Skip to content

armgit / hypit

Public Imported from GitHub
0

Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.

refactor: collapse execution onto a single local runtime

kashorin52942f9c1aee
diff --git a/.gitignore b/.gitignore
index 7d2e5cae..66d4ec60 100644
--- a/.gitignore
+++ b/.gitignore
@@ -53,7 +53,8 @@ examples/**/.svml/
examples/**/evidence/generated/
services/whisperx/.venv/
services/whisperx/build/
-services/whisperx/**/__pycache__/
+**/__pycache__/
+*.py[cod]
services/whisperx/src/*.egg-info/
services/image-opencv/.venv/
services/image-opencv/**/__pycache__/
diff --git a/packages/credential-store-env/package.json b/packages/credential-store-env/package.json
index b427b310..e2e71f0d 100644
--- a/packages/credential-store-env/package.json
+++ b/packages/credential-store-env/package.json
@@ -1,17 +1,22 @@
{
"name": "@hypit/credential-store-env",
- "version": "0.0.0-dev",
+ "version": "0.1.0",
"license": "SEE LICENSE IN LICENSE",
"private": true,
"type": "module",
"exports": {
".": "./src/index.ts"
},
+ "files": ["dist", "README.md"],
"hypit": {
"activation": "./src/activation.ts"
},
- "dependencies": {
+ "peerDependencies": {
+ "@hypit/runtime-local": "workspace:^"
+ },
+ "devDependencies": {
+ "@hypit/hypit": "workspace:*",
"@hypit/runtime": "workspace:*",
- "@hypit/runtime-kit": "workspace:*"
+ "@hypit/runtime-local": "workspace:*"
}
}
diff --git a/packages/credential-store-env/src/activation.ts b/packages/credential-store-env/src/activation.ts
index 89b81624..5346d1a8 100644
--- a/packages/credential-store-env/src/activation.ts
+++ b/packages/credential-store-env/src/activation.ts
@@ -2,7 +2,7 @@ import {
createRuntimeCredentialStoreAdapterFacet,
runtimeConfigExact,
runtimeConfigObject,
-} from "@hypit/runtime-kit";
+} from "@hypit/runtime-local/extension";
import { EnvironmentCredentialStore } from "./index.js";
@@ -18,8 +18,8 @@ const environmentCredentialStoreAdapter = createRuntimeCredentialStoreAdapterFac
});
export const hypitPackage = {
- format: "hypit.node-package@1" as const,
- hostFacets: [environmentCredentialStoreAdapter],
+ format: "hypit.package@1" as const,
+ facets: [environmentCredentialStoreAdapter],
};
export default hypitPackage;
diff --git a/packages/credential-store-env/src/index.ts b/packages/credential-store-env/src/index.ts
index d94e5d7b..b4af746f 100644
--- a/packages/credential-store-env/src/index.ts
+++ b/packages/credential-store-env/src/index.ts
@@ -2,8 +2,8 @@ import type {
CredentialRef,
CredentialStore,
CredentialValue,
-} from "@hypit/runtime";
-import { verifyCredentialRef } from "@hypit/runtime";
+} from "@hypit/runtime-local/extension";
+import { verifyCredentialRef } from "@hypit/runtime-local/extension";
/** Resolves only explicitly requested environment variables and never snapshots or enumerates env. */
export class EnvironmentCredentialStore implements CredentialStore {
diff --git a/packages/credential-store-file/README.md b/packages/credential-store-file/README.md
deleted file mode 100644
index c8ed5914..00000000
--- a/packages/credential-store-file/README.md
+++ /dev/null
@@ -1,71 +0,0 @@
-# `@hypit/credential-store-file`
-
-A writable CredentialStore for a deployment that explicitly chooses local file storage, including
-Linux without an OS credential locker. It stores unencrypted credential values in an owner-private
-directory outside the video project. On Windows the selected directory must have a private user ACL;
-POSIX file modes do not set Windows ACLs. Choose `@hypit/credential-store-os` when using macOS Keychain
-or Windows Credential Locker, `@hypit/credential-store-platform` for OS storage on macOS/Windows
-and this file Store on Linux or `@hypit/credential-store-env` for externally
-supplied, read-only values.
-
-## Select it before login
-
-After `hypit runtime init`, edit the created Profile before running `auth` or starting its Runtime.
-Replace its credential-store selection and the chosen Endpoint's credential reference together:
-
-```json
-{
- "credentials": {
- "file": { "use": "@hypit/credential-store-file" }
- },
- "endpoints": {
- "hypihub.default": {
- "use": "@hypit/provider-hypihub",
- "config": {
- "baseUrl": "https://hypit.ai",
- "apiKey": { "store": "file", "key": "hypihub.oauth" }
- }
- }
- }
-}
-```
-
-This is a Profile fragment: preserve its format, dataRoot, other Endpoints and bindings. For an
-existing Profile, edit only the selected references and use `hypit runtime use <profile>` to select it.
-The Endpoint still owns its acquisition flow; the Store only persists its result:
-
-```bash
-hypit auth login hypihub.default
-hypit auth status hypihub.default
-hypit auth logout hypihub.default
-```
-
-No existing OS credential is migrated and no failed lookup tries another Store. A damaged document
-can be replaced by login or deleted by logout without decoding the old value. Status and execution
-report the read error rather than treating corruption as a missing credential.
-
-## Storage
-
-The default directory is `credentials` under the Host state root printed by `hypit paths`.
-`config.path` explicitly selects a directory, including an absolute directory outside that root;
-relative paths resolve against the Host root.
-Opening the adapter and reading an absent key do not create files. Keep this directory outside Git.
-On WSL, the default under the Linux home uses normal Linux permissions. If the Host state root is
-on a Windows-mounted drive, set this Store's `config.path` to a private directory in the WSL Linux
-filesystem before login. A Windows mount's reported mode does not establish that its Windows ACL
-protects the secret, so the Store does not waive its owner-private check for that path.
-
-Each key has its own JSON file containing only `secret` and optional `expiresAt`, as defined by
-CredentialValue. Filenames use reversible lower-case hex encoding of the key's UTF-16 bytes, with a
-`key-` prefix; they are not hashes or secret encryption. This preserves case-sensitive key identity on
-case-insensitive filesystems and keeps slashes and reserved names out of filesystem path syntax.
-Filesystem path-length limits still apply; an overlong key fails rather than selecting another name.
-
-Writes create an owner-only temporary file and replace the single destination through `@hypit/file-io-node`.
-On Windows this uses native POSIX replacement semantics, so an open reader keeps the old file
-while a new open sees the replacement; it does not use Node’s `MoveFileExW` path. Different
-keys do not overwrite each other's updates. Reads see a complete document, and the last completed
-replacement of the same key supplies its value. There is no process-local queue or cross-process
-coordination; filesystem errors propagate to the caller rather than being retried or hidden.
-The Store does not enumerate credentials, maintain an index, or record write history.
-Permission and I/O errors propagate. Existing directory permissions are not silently changed.
diff --git a/packages/credential-store-file/package.json b/packages/credential-store-file/package.json
deleted file mode 100644
index 79849549..00000000
--- a/packages/credential-store-file/package.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "name": "@hypit/credential-store-file",
- "version": "0.0.0-dev",
- "license": "SEE LICENSE IN LICENSE",
- "private": true,
- "type": "module",
- "exports": {
- ".": "./src/index.ts"
- },
- "files": [
- "src",
- "README.md"
- ],
- "hypit": {
- "activation": "./src/activation.ts"
- },
- "dependencies": {
- "@hypit/runtime": "workspace:*",
- "@hypit/runtime-kit": "workspace:*",
- "@hypit/file-io-node": "workspace:*"
- }
-}
diff --git a/packages/credential-store-file/src/activation.ts b/packages/credential-store-file/src/activation.ts
deleted file mode 100644
index 803a88a4..00000000
--- a/packages/credential-store-file/src/activation.ts
+++ /dev/null
@@ -1,30 +0,0 @@
-import { join, resolve } from "node:path";
-import {
- createRuntimeCredentialStoreAdapterFacet,
- runtimeConfigExact,
- runtimeConfigObject,
- runtimeConfigString,
-} from "@hypit/runtime-kit";
-import { FileCredentialStore } from "./store.js";
-
-const fileCredentialStoreAdapter = createRuntimeCredentialStoreAdapterFacet({
- use: "@hypit/credential-store-file",
- validate(context) {
- const config = runtimeConfigObject(context.config, "file CredentialStore");
- runtimeConfigExact(config, ["path"], "file CredentialStore");
- runtimeConfigString(config.path, "file credential path");
- },
- open(context) {
- const config = runtimeConfigObject(context.config, "file CredentialStore");
- const path = runtimeConfigString(config.path, "file credential path");
- return { value: new FileCredentialStore(
- path === undefined ? join(context.hostStateRoot, "credentials") : resolve(context.hostStateRoot, path),
- ) };
- },
-});
-
-export const hypitPackage = {
- format: "hypit.node-package@1" as const,
- hostFacets: [fileCredentialStoreAdapter],
-};
-export default hypitPackage;
diff --git a/packages/credential-store-file/src/index.ts b/packages/credential-store-file/src/index.ts
deleted file mode 100644
index 481b1203..00000000
--- a/packages/credential-store-file/src/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { FileCredentialStore } from "./store.js";
diff --git a/packages/credential-store-local/README.md b/packages/credential-store-local/README.md
new file mode 100644
index 00000000..a099053d
--- /dev/null
+++ b/packages/credential-store-local/README.md
@@ -0,0 +1,37 @@
+# `@hypit/credential-store-local`
+
+The writable CredentialStore for the machine running Hypit. It owns references filed under
+`{ store: "local", key }`.
+
+By default it uses macOS Keychain or Windows Credential Locker on those systems, and owner-private
+files on Linux. These are implementation strategies of one local Store, not separate Runtime
+components.
+
+```json
+{
+ "credentials": {
+ "local": { "use": "@hypit/credential-store-local" }
+ }
+}
+```
+
+Select the file backend explicitly when a system locker is unsuitable, including Windows secrets
+that exceed Credential Locker's 512-character password limit:
+
+```json
+{
+ "credentials": {
+ "local": {
+ "use": "@hypit/credential-store-local",
+ "config": { "backend": "file", "path": "credentials" }
+ }
+ }
+}
+```
+
+`path` is resolved below the Hypit host state root. The directory and documents must be private to
+their owner. `service` optionally changes the macOS/Windows locker service name. Setting
+`backend: "system"` requires macOS or Windows and fails instead of silently switching storage.
+
+Use `@hypit/credential-store-env` when the deployment environment, rather than Hypit, owns a
+read-only secret.
diff --git a/packages/credential-store-local/package.json b/packages/credential-store-local/package.json
new file mode 100644
index 00000000..4b3f7d2b
--- /dev/null
+++ b/packages/credential-store-local/package.json
@@ -0,0 +1,28 @@
+{
+ "name": "@hypit/credential-store-local",
+ "version": "0.1.0",
+ "license": "SEE LICENSE IN LICENSE",
+ "private": true,
+ "type": "module",
+ "exports": {
+ ".": "./src/index.ts"
+ },
+ "files": [
+ "dist",
+ "runtime",
+ "README.md"
+ ],
+ "hypit": {
+ "activation": "./src/activation.ts"
+ },
+ "peerDependencies": {
+ "@hypit/hypit": "workspace:^",
+ "@hypit/runtime-local": "workspace:^"
+ },
+ "devDependencies": {
+ "@hypit/atomic-file": "workspace:*",
+ "@hypit/hypit": "workspace:*",
+ "@hypit/runtime": "workspace:*",
+ "@hypit/runtime-local": "workspace:*"
+ }
+}
diff --git a/packages/credential-store-os/runtime/windows-credential.ps1 b/packages/credential-store-local/runtime/windows-credential.ps1
similarity index 96%
rename from packages/credential-store-os/runtime/windows-credential.ps1
rename to packages/credential-store-local/runtime/windows-credential.ps1
index ef0501d3..45622034 100644
--- a/packages/credential-store-os/runtime/windows-credential.ps1
+++ b/packages/credential-store-local/runtime/windows-credential.ps1
@@ -39,7 +39,7 @@ switch ($Operation) {
$bytes = [Convert]::FromBase64String([string]$request.secret)
$secret = [System.Text.Encoding]::UTF8.GetString($bytes)
if ($secret.Length -gt 512) {
- throw "PasswordVault cannot store a $($secret.Length)-character secret (limit 512). Select @hypit/credential-store-file for OAuth tokens."
+ throw "PasswordVault cannot store a $($secret.Length)-character secret (limit 512). Select @hypit/credential-store-local for OAuth tokens."
}
$credential = New-Object Windows.Security.Credentials.PasswordCredential(
[string]$request.service,
diff --git a/packages/credential-store-local/src/activation.ts b/packages/credential-store-local/src/activation.ts
new file mode 100644
index 00000000..75edc7e5
--- /dev/null
+++ b/packages/credential-store-local/src/activation.ts
@@ -0,0 +1,41 @@
+import { join, resolve } from "node:path";
+import {
+ createRuntimeCredentialStoreAdapterFacet,
+ runtimeConfigExact,
+ runtimeConfigObject,
+ runtimeConfigString,
+} from "@hypit/runtime-local/extension";
+import { LocalCredentialStore } from "./store.js";
+
+const localCredentialStoreAdapter = createRuntimeCredentialStoreAdapterFacet({
+ use: "@hypit/credential-store-local",
+ validate(context) {
+ const config = runtimeConfigObject(context.config, "local CredentialStore");
+ runtimeConfigExact(config, ["backend", "path", "service"], "local CredentialStore");
+ const backend = runtimeConfigString(config.backend, "local credential backend");
+ if (backend !== undefined && backend !== "system" && backend !== "file") {
+ throw new Error("local credential backend must be system or file");
+ }
+ runtimeConfigString(config.path, "local credential path");
+ runtimeConfigString(config.service, "local credential service");
+ },
+ open(context) {
+ const config = runtimeConfigObject(context.config, "local CredentialStore");
+ const backend = runtimeConfigString(config.backend, "local credential backend") as "system" | "file" | undefined;
+ const path = runtimeConfigString(config.path, "local credential path");
+ const service = runtimeConfigString(config.service, "local credential service");
+ return {
+ value: new LocalCredentialStore({
+ directory: path === undefined ? join(context.hostStateRoot, "credentials") : resolve(context.hostStateRoot, path),
+ ...(backend === undefined ? {} : { backend }),
+ ...(service === undefined ? {} : { service }),
+ }),
+ };
+ },
+});
+
+export const hypitPackage = {
+ format: "hypit.package@1" as const,
+ facets: [localCredentialStoreAdapter],
+};
+export default hypitPackage;
diff --git a/packages/credential-store-file/src/store.ts b/packages/credential-store-local/src/file.ts
similarity index 95%
rename from packages/credential-store-file/src/store.ts
rename to packages/credential-store-local/src/file.ts
index 854189c7..86878e66 100644
--- a/packages/credential-store-file/src/store.ts
+++ b/packages/credential-store-local/src/file.ts
@@ -1,9 +1,9 @@
-import { replaceFile } from "@hypit/file-io-node";
+import { replaceFile } from "@hypit/hypit/atomic-file";
import { randomUUID } from "node:crypto";
import { mkdir, open, rm, stat, unlink } from "node:fs/promises";
import { join } from "node:path";
-import { verifyCredentialRef } from "@hypit/runtime";
-import type { CredentialRef, CredentialValue, WritableCredentialStore } from "@hypit/runtime";
+import { verifyCredentialRef } from "@hypit/runtime-local/extension";
+import type { CredentialRef, CredentialValue, WritableCredentialStore } from "@hypit/runtime-local/extension";
function missing(error: unknown): boolean {
return error instanceof Error && "code" in error && error.code === "ENOENT";
diff --git a/packages/credential-store-local/src/index.ts b/packages/credential-store-local/src/index.ts
new file mode 100644
index 00000000..d4faee52
--- /dev/null
+++ b/packages/credential-store-local/src/index.ts
@@ -0,0 +1,4 @@
+export { LocalCredentialStore } from "./store.js";
+export { FileCredentialStore } from "./file.js";
+export { OsCredentialStore } from "./os.js";
+export type { OsCredentialDeleter, OsCredentialReader, OsCredentialWriter } from "./os.js";
diff --git a/packages/credential-store-os/src/store.ts b/packages/credential-store-local/src/os.ts
similarity index 92%
rename from packages/credential-store-os/src/store.ts
rename to packages/credential-store-local/src/os.ts
index 5aac6ba8..4acf9e14 100644
--- a/packages/credential-store-os/src/store.ts
+++ b/packages/credential-store-local/src/os.ts
@@ -1,15 +1,15 @@
import { execFile } from "node:child_process";
import { windowsCredential } from "./windows.js";
-import { verifyCredentialRef } from "@hypit/runtime";
+import { verifyCredentialRef } from "@hypit/runtime-local/extension";
import type {
CredentialRef,
CredentialValue,
WritableCredentialStore,
-} from "@hypit/runtime";
+} from "@hypit/runtime-local/extension";
export const osCredentialStoreModuleRef = {
- name: "@hypit/credential-store-os",
+ name: "@hypit/credential-store-local",
version: "1",
} as const;
@@ -85,10 +85,9 @@ function platformBackend(service: string) {
if (process.platform === "win32") return windowsBackend();
// A Profile that selects this Store cannot be repaired by anything the user does here, and the
// other Stores are the answer, so name them where the failure is read.
- throw new Error("OS CredentialStore supports macOS and Windows only; select "
- + "@hypit/credential-store-platform (platform locker, owner-private file on Linux), "
- + "@hypit/credential-store-file (owner-private local file) or @hypit/credential-store-env "
- + "(externally supplied value) in this Profile's credentials instead");
+ throw new Error("System credential storage supports macOS and Windows only; select "
+ + "@hypit/credential-store-local with backend file, or @hypit/credential-store-env "
+ + "for an externally supplied value");
}
/** One logical writable store backed by the current user's OS credential locker. */
diff --git a/packages/credential-store-platform/src/store.ts b/packages/credential-store-local/src/store.ts
similarity index 68%
rename from packages/credential-store-platform/src/store.ts
rename to packages/credential-store-local/src/store.ts
index 7d5b9b7d..b7503ad8 100644
--- a/packages/credential-store-platform/src/store.ts
+++ b/packages/credential-store-local/src/store.ts
@@ -1,21 +1,21 @@
import {
credentialRef,
verifyCredentialRef,
-} from "@hypit/runtime";
+} from "@hypit/runtime-local/extension";
import type {
CredentialRef,
CredentialValue,
WritableCredentialStore,
-} from "@hypit/runtime";
-import { FileCredentialStore } from "@hypit/credential-store-file";
-import { OsCredentialStore } from "@hypit/credential-store-os";
+} from "@hypit/runtime-local/extension";
+import { FileCredentialStore } from "./file.js";
+import { OsCredentialStore } from "./os.js";
import type {
OsCredentialDeleter,
OsCredentialReader,
OsCredentialWriter,
-} from "@hypit/credential-store-os";
+} from "./os.js";
-export type PlatformCredentialStoreOptions = {
+export type LocalCredentialStoreOptions = {
/** Directory holding the documents this Store selects on Linux. */
readonly directory: string;
/** Service the locker's entries are filed under; the OS Store's own default applies where absent. */
@@ -25,6 +25,8 @@ export type PlatformCredentialStoreOptions = {
* separate so the selection can be exercised on one machine for every platform.
*/
readonly platform?: NodeJS.Platform;
+ /** Force one local backend; omitted selects the native locker, or a private file on Linux. */
+ readonly backend?: "system" | "file";
/** Locker backend to read and write with, where the platform's own locker is not the one to use. */
readonly locker?: {
readonly read: OsCredentialReader;
@@ -37,28 +39,31 @@ export type PlatformCredentialStoreOptions = {
* An explicitly selected storage policy: OS credentials on macOS/Windows, files on Linux.
* The selected backend's errors propagate; other platforms are unsupported by this package.
*/
-export class PlatformCredentialStore implements WritableCredentialStore {
+export class LocalCredentialStore implements WritableCredentialStore {
readonly #delegate: WritableCredentialStore;
readonly #backing: "os" | "file";
- constructor(options: PlatformCredentialStoreOptions) {
+ constructor(options: LocalCredentialStoreOptions) {
const platform = options.platform ?? process.platform;
- if (platform === "darwin" || platform === "win32") {
+ if (options.backend === "file") {
+ this.#backing = "file";
+ this.#delegate = new FileCredentialStore(options.directory);
+ } else if (platform === "darwin" || platform === "win32") {
this.#backing = "os";
this.#delegate = new OsCredentialStore({
...(options.service === undefined ? {} : { service: options.service }),
...options.locker,
});
- } else if (platform === "linux") {
+ } else if (platform === "linux" && options.backend !== "system") {
this.#backing = "file";
this.#delegate = new FileCredentialStore(options.directory);
} else {
- throw new Error(`Platform CredentialStore does not support ${platform}; select an explicit CredentialStore supported by this host`);
+ throw new Error(`Local CredentialStore cannot use the system credential locker on ${platform}; select backend file`);
}
}
owns(ref: CredentialRef): boolean {
- return ref.store === "platform";
+ return ref.store === "local";
}
/**
@@ -77,13 +82,13 @@ export class PlatformCredentialStore implements WritableCredentialStore {
async put(ref: CredentialRef, value: CredentialValue): Promise<void> {
verifyCredentialRef(ref);
- if (!this.owns(ref)) throw new Error(`Platform CredentialStore does not own ${ref.store}`);
+ if (!this.owns(ref)) throw new Error(`Local CredentialStore does not own ${ref.store}`);
await this.#delegate.put(this.#translated(ref), value);
}
async delete(ref: CredentialRef): Promise<boolean> {
verifyCredentialRef(ref);
- if (!this.owns(ref)) throw new Error(`Platform CredentialStore does not own ${ref.store}`);
+ if (!this.owns(ref)) throw new Error(`Local CredentialStore does not own ${ref.store}`);
return await this.#delegate.delete(this.#translated(ref));
}
}
diff --git a/packages/credential-store-os/src/windows.ts b/packages/credential-store-local/src/windows.ts
similarity index 96%
rename from packages/credential-store-os/src/windows.ts
rename to packages/credential-store-local/src/windows.ts
index 1f8d0fcb..b6d531fa 100644
--- a/packages/credential-store-os/src/windows.ts
+++ b/packages/credential-store-local/src/windows.ts
@@ -17,7 +17,7 @@ export function assertWindowsLockerSecret(secret: string, account: string): void
throw new Error(
`Windows Credential Locker cannot store the ${secret.length}-character secret for ${account}`
+ ` (PasswordVault limit is ${windowsLockerPasswordLimit} characters).`
- + " Select @hypit/credential-store-file for OAuth tokens.",
+ + " Select @hypit/credential-store-local with backend file for OAuth tokens.",
);
}
}
diff --git a/packages/credential-store-file/test/concurrency.test.ts b/packages/credential-store-local/test/file-concurrency.test.ts
similarity index 97%
rename from packages/credential-store-file/test/concurrency.test.ts
rename to packages/credential-store-local/test/file-concurrency.test.ts
index 721e6b56..52d5d6b3 100644
--- a/packages/credential-store-file/test/concurrency.test.ts
+++ b/packages/credential-store-local/test/file-concurrency.test.ts
@@ -6,10 +6,10 @@ import { join } from "node:path";
import { fileURLToPath } from "node:url";
import test from "node:test";
import { credentialRef } from "@hypit/runtime";
-import { FileCredentialStore } from "../src/store.js";
+import { FileCredentialStore } from "../src/file.js";
const distribution = fileURLToPath(new URL("../../../", import.meta.url));
-const fixture = fileURLToPath(new URL("./store-writer-fixture.ts", import.meta.url));
+const fixture = fileURLToPath(new URL("./file-store-writer-fixture.ts", import.meta.url));
const writers = 8;
type Exit = { code: number; stderr: string };
diff --git a/packages/credential-store-file/test/failed-replacement.test.ts b/packages/credential-store-local/test/file-failed-replacement.test.ts
similarity index 97%
rename from packages/credential-store-file/test/failed-replacement.test.ts
rename to packages/credential-store-local/test/file-failed-replacement.test.ts
index a9c249e0..40a07246 100644
--- a/packages/credential-store-file/test/failed-replacement.test.ts
+++ b/packages/credential-store-local/test/file-failed-replacement.test.ts
@@ -5,7 +5,7 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
import { credentialRef } from "@hypit/runtime";
-import { FileCredentialStore } from "../src/store.js";
+import { FileCredentialStore } from "../src/file.js";
test("a refused replacement preserves the old credential, cleans its temporary and reports the I/O error", { skip: process.platform === "win32" }, async t => {
const root = await fs.mkdtemp(join(tmpdir(), "hypit-refused-credential-"));
diff --git a/packages/credential-store-file/test/store-writer-fixture.ts b/packages/credential-store-local/test/file-store-writer-fixture.ts
similarity index 90%
rename from packages/credential-store-file/test/store-writer-fixture.ts
rename to packages/credential-store-local/test/file-store-writer-fixture.ts
index 7f06d442..eceffc54 100644
--- a/packages/credential-store-file/test/store-writer-fixture.ts
+++ b/packages/credential-store-local/test/file-store-writer-fixture.ts
@@ -1,6 +1,6 @@
import { once } from "node:events";
import { credentialRef } from "@hypit/runtime";
-import { FileCredentialStore } from "../src/store.js";
+import { FileCredentialStore } from "../src/file.js";
const [directory, key, secret] = process.argv.slice(2);
diff --git a/packages/credential-store-file/test/store.test.ts b/packages/credential-store-local/test/file-store.test.ts
similarity index 98%
rename from packages/credential-store-file/test/store.test.ts
rename to packages/credential-store-local/test/file-store.test.ts
index af3a8bc9..6952a957 100644
--- a/packages/credential-store-file/test/store.test.ts
+++ b/packages/credential-store-local/test/file-store.test.ts
@@ -4,7 +4,7 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
import { credentialRef } from "@hypit/runtime";
-import { FileCredentialStore } from "../src/store.js";
+import { FileCredentialStore } from "../src/file.js";
test("independent credential keys retain concurrent writes and round-trip opaque names", async () => {
const root = await mkdtemp(join(tmpdir(), "hypit-file-credentials-"));
diff --git a/packages/credential-store-os/test/store.test.ts b/packages/credential-store-local/test/os-store.test.ts
similarity index 95%
rename from packages/credential-store-os/test/store.test.ts
rename to packages/credential-store-local/test/os-store.test.ts
index 51064057..96aa5d3e 100644
--- a/packages/credential-store-os/test/store.test.ts
+++ b/packages/credential-store-local/test/os-store.test.ts
@@ -2,7 +2,7 @@ import assert from "node:assert/strict";
import test from "node:test";
import { credentialRef } from "@hypit/runtime";
-import { OsCredentialStore } from "@hypit/credential-store-os";
+import { OsCredentialStore } from "@hypit/credential-store-local";
function memoryStore(entries: Readonly<Record<string, string>> = {}) {
const values = new Map(Object.entries(entries));
diff --git a/packages/credential-store-platform/test/store.test.ts b/packages/credential-store-local/test/store.test.ts
similarity index 79%
rename from packages/credential-store-platform/test/store.test.ts
rename to packages/credential-store-local/test/store.test.ts
index a856021d..581b59b7 100644
--- a/packages/credential-store-platform/test/store.test.ts
+++ b/packages/credential-store-local/test/store.test.ts
@@ -4,9 +4,9 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
import { credentialRef } from "@hypit/runtime";
-import { FileCredentialStore } from "@hypit/credential-store-file";
-import { OsCredentialStore } from "@hypit/credential-store-os";
-import { PlatformCredentialStore } from "@hypit/credential-store-platform";
+import { FileCredentialStore } from "@hypit/credential-store-local";
+import { OsCredentialStore } from "@hypit/credential-store-local";
+import { LocalCredentialStore } from "@hypit/credential-store-local";
/** A locker that keeps entries in memory, so a platform's locker is exercised without touching one. */
function memoryLocker(entries: Readonly<Record<string, string>> = {}) {
@@ -28,8 +28,8 @@ test("macOS stores credentials in its locker and never creates a file", async ()
try {
const directory = join(root, "credentials");
const locker = memoryLocker();
- const store = new PlatformCredentialStore({ directory, platform: "darwin", locker });
- const ref = credentialRef("platform", "hypihub.oauth");
+ const store = new LocalCredentialStore({ directory, platform: "darwin", locker });
+ const ref = credentialRef("local", "hypihub.oauth");
assert.equal(await store.resolve(ref), undefined);
await store.put(ref, { secret: "locker-secret" });
assert.deepEqual(await store.resolve(ref), { secret: "locker-secret" });
@@ -44,10 +44,10 @@ test("Windows selects the locker as well", async () => {
const root = await scratch("hypit-platform-credentials-");
try {
const locker = memoryLocker();
- const store = new PlatformCredentialStore({
+ const store = new LocalCredentialStore({
directory: join(root, "credentials"), platform: "win32", locker,
});
- await store.put(credentialRef("platform", "hypihub.oauth"), { secret: "locker-secret" });
+ await store.put(credentialRef("local", "hypihub.oauth"), { secret: "locker-secret" });
assert.equal(locker.entries.get("hypihub.oauth"), "locker-secret");
assert.deepEqual(await readdir(root), [], "file storage stays untouched by the OS policy");
} finally { await rm(root, { recursive: true, force: true }); }
@@ -57,8 +57,8 @@ test("Linux stores owner-private documents in the file Store's directory", async
const root = await scratch("hypit-platform-credentials-");
try {
const directory = join(root, "credentials");
- const store = new PlatformCredentialStore({ directory, platform: "linux" });
- const ref = credentialRef("platform", "hypihub.oauth");
+ const store = new LocalCredentialStore({ directory, platform: "linux" });
+ const ref = credentialRef("local", "hypihub.oauth");
await store.put(ref, { secret: "file-secret", expiresAt: 42 });
assert.deepEqual(await store.resolve(ref), { secret: "file-secret", expiresAt: 42 });
const files = await readdir(directory);
@@ -76,20 +76,20 @@ test("switching between this Store and the file Store finds the same credential"
try {
const directory = join(root, "credentials");
await new FileCredentialStore(directory).put(credentialRef("file", "hypihub.oauth"), { secret: "written-by-file" });
- const platform = new PlatformCredentialStore({ directory, platform: "linux" });
- assert.deepEqual(await platform.resolve(credentialRef("platform", "hypihub.oauth")), { secret: "written-by-file" });
- await platform.put(credentialRef("platform", "second"), { secret: "written-by-platform" });
+ const platform = new LocalCredentialStore({ directory, platform: "linux" });
+ assert.deepEqual(await platform.resolve(credentialRef("local", "hypihub.oauth")), { secret: "written-by-file" });
+ await platform.put(credentialRef("local", "second"), { secret: "written-by-platform" });
assert.deepEqual(await new FileCredentialStore(directory).resolve(credentialRef("file", "second")),
{ secret: "written-by-platform" });
} finally { await rm(root, { recursive: true, force: true }); }
});
-test("only this Store owns the name platform, and it owns no other name", async () => {
+test("only this Store owns the name local, and it owns no other name", async () => {
const root = await scratch("hypit-platform-credentials-");
try {
const directory = join(root, "credentials");
- const platform = new PlatformCredentialStore({ directory, platform: "linux" });
- const ref = credentialRef("platform", "hypihub.oauth");
+ const platform = new LocalCredentialStore({ directory, platform: "linux" });
+ const ref = credentialRef("local", "hypihub.oauth");
assert.equal(await platform.resolve(credentialRef("file", "hypihub.oauth")), undefined,
"a ref filed under another name is not this Store's to answer");
await assert.rejects(platform.put(credentialRef("env", "HYPIHUB_OAUTH"), { secret: "x" }), /does not own env/u);
@@ -103,9 +103,9 @@ test("only this Store owns the name platform, and it owns no other name", async
test("unsupported platforms fail before creating credential files", async () => {
const root = await scratch("hypit-platform-credentials-");
try {
- assert.throws(() => new PlatformCredentialStore({
+ assert.throws(() => new LocalCredentialStore({
directory: join(root, "credentials"), platform: "freebsd",
- }), /Platform CredentialStore does not support freebsd/u);
+ }), /Local CredentialStore cannot use the system credential locker on freebsd/u);
assert.deepEqual(await readdir(root), []);
} finally { await rm(root, { recursive: true, force: true }); }
});
@@ -115,11 +115,11 @@ test("locker failures propagate without switching to file storage", async () =>
try {
const failure = new Error("locker unavailable");
const fail = async () => { throw failure; };
- const store = new PlatformCredentialStore({
+ const store = new LocalCredentialStore({
directory: join(root, "credentials"), platform: "darwin",
locker: { read: fail, write: fail, remove: fail },
});
- const ref = credentialRef("platform", "hypihub.oauth");
+ const ref = credentialRef("local", "hypihub.oauth");
await assert.rejects(store.resolve(ref), (error) => error === failure);
await assert.rejects(store.put(ref, { secret: "not-written" }), (error) => error === failure);
await assert.rejects(store.delete(ref), (error) => error === failure);
diff --git a/packages/credential-store-os/test/windows-limit.test.ts b/packages/credential-store-local/test/windows-limit.test.ts
similarity index 91%
rename from packages/credential-store-os/test/windows-limit.test.ts
rename to packages/credential-store-local/test/windows-limit.test.ts
index ef03a9db..a34f8f92 100644
--- a/packages/credential-store-os/test/windows-limit.test.ts
+++ b/packages/credential-store-local/test/windows-limit.test.ts
@@ -7,6 +7,6 @@ test("Windows locker rejects OAuth-sized secrets before PasswordVault", () => {
assertWindowsLockerSecret("x".repeat(windowsLockerPasswordLimit), "hypihub.oauth");
assert.throws(
() => assertWindowsLockerSecret("x".repeat(windowsLockerPasswordLimit + 1), "hypihub.oauth"),
- /513-character secret for hypihub\.oauth.*PasswordVault limit is 512.*credential-store-file/u,
+ /513-character secret for hypihub\.oauth.*PasswordVault limit is 512.*credential-store-local.*backend file/u,
);
});
diff --git a/packages/credential-store-os/test/windows.test.ts b/packages/credential-store-local/test/windows.test.ts
similarity index 97%
rename from packages/credential-store-os/test/windows.test.ts
rename to packages/credential-store-local/test/windows.test.ts
index 1eeb1b48..04d9941a 100644
--- a/packages/credential-store-os/test/windows.test.ts
+++ b/packages/credential-store-local/test/windows.test.ts
@@ -6,7 +6,7 @@ import { syncBuiltinESMExports } from "node:module";
import { randomUUID } from "node:crypto";
import test from "node:test";
import { credentialRef } from "@hypit/runtime";
-import { OsCredentialStore } from "../src/store.js";
+import { OsCredentialStore } from "../src/os.js";
import { windowsCredential } from "../src/windows.js";
test("an oversized bridge response terminates the child and keeps secret output out of the error", async t => {
diff --git a/packages/credential-store-os/README.md b/packages/credential-store-os/README.md
deleted file mode 100644
index 4f0ff7e4..00000000
--- a/packages/credential-store-os/README.md
+++ /dev/null
@@ -1,17 +0,0 @@
-# `@hypit/credential-store-os`
-
-Writable Runtime `CredentialStore` backed by the current user's operating-system credential locker:
-macOS Keychain or Windows Credential Locker. Runtime Profiles use one stable `{ store: "os", key }`
-reference on both systems; Source and project files never contain the secret.
-
-The adapter accepts one optional `service` name. It reads, writes or deletes only the exact
-service/account pair requested by the selected Endpoint and cannot enumerate credentials. Windows
-passes the request over a private child-process pipe to the packaged PowerShell bridge, so secret
-bytes do not appear in command arguments or temporary files.
-
-Use `hypit auth login <endpoint> --runtime <profile>` to write the selected credential and
-`hypit auth logout` to remove it.
-
-A Profile that must also run on Linux can select `@hypit/credential-store-platform`:
-that package uses this Store on macOS and Windows, and an unencrypted, owner-private file on Linux.
-Selecting `@hypit/credential-store-os` directly continues to require macOS or Windows.
diff --git a/packages/credential-store-os/package.json b/packages/credential-store-os/package.json
deleted file mode 100644
index 39f08026..00000000
--- a/packages/credential-store-os/package.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "name": "@hypit/credential-store-os",
- "version": "0.0.0-dev",
- "license": "SEE LICENSE IN LICENSE",
- "private": true,
- "type": "module",
- "exports": {
- ".": "./src/index.ts"
- },
- "files": [
- "src",
- "runtime",
- "README.md"
- ],
- "hypit": {
- "activation": "./src/activation.ts"
- },
- "dependencies": {
- "@hypit/runtime": "workspace:*",
- "@hypit/runtime-kit": "workspace:*"
- }
-}
diff --git a/packages/credential-store-os/src/activation.ts b/packages/credential-store-os/src/activation.ts
deleted file mode 100644
index 1d563f31..00000000
--- a/packages/credential-store-os/src/activation.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-import {
- createRuntimeCredentialStoreAdapterFacet,
- runtimeConfigExact,
- runtimeConfigObject,
- runtimeConfigString,
-} from "@hypit/runtime-kit";
-
-import { OsCredentialStore } from "./store.js";
-
-const osCredentialStoreRuntimeAdapter = createRuntimeCredentialStoreAdapterFacet({
- use: "@hypit/credential-store-os",
- validate(context) {
- const config = runtimeConfigObject(context.config, "OS CredentialStore");
- runtimeConfigExact(config, ["service"], "OS CredentialStore");
- runtimeConfigString(config.service, "OS credential service");
- },
- open(context) {
- const config = runtimeConfigObject(context.config, "OS CredentialStore");
- runtimeConfigExact(config, ["service"], "OS CredentialStore");
- return { value: new OsCredentialStore({
- ...(runtimeConfigString(config.service, "OS credential service") === undefined
- ? {} : { service: config.service as string }),
- }) };
- },
-});
-
-export const hypitPackage = {
- format: "hypit.node-package@1" as const,
- hostFacets: [osCredentialStoreRuntimeAdapter],
-};
-
-export default hypitPackage;
diff --git a/packages/credential-store-os/src/index.ts b/packages/credential-store-os/src/index.ts
deleted file mode 100644
index 88cc2fe5..00000000
--- a/packages/credential-store-os/src/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export { OsCredentialStore, osCredentialStoreModuleRef } from "./store.js";
-export type { OsCredentialDeleter, OsCredentialReader, OsCredentialWriter } from "./store.js";
diff --git a/packages/credential-store-platform/README.md b/packages/credential-store-platform/README.md
deleted file mode 100644
index c4566598..00000000
--- a/packages/credential-store-platform/README.md
+++ /dev/null
@@ -1,65 +0,0 @@
-# `@hypit/credential-store-platform`
-
-An explicitly selected CredentialStore policy: macOS Keychain on macOS, Windows Credential Locker
-on Windows, and an unencrypted, owner-private file on Linux. Other platforms are unsupported by this
-package and report an error. Linux may offer other credential services; this package chooses file
-storage there and does not detect or integrate those services.
-
-A Profile can select this package to use that policy on Linux, macOS and Windows.
-`@hypit/credential-store-os`, `@hypit/credential-store-file` and `@hypit/credential-store-env`
-remain selectable directly for a deployment with a different storage choice.
-
-## Select it
-
-```json
-{
- "credentials": {
- "platform": { "use": "@hypit/credential-store-platform" }
- },
- "endpoints": {
- "hypihub.default": {
- "use": "@hypit/provider-hypihub",
- "config": {
- "baseUrl": "https://hypit.ai",
- "apiKey": { "store": "platform", "key": "hypihub.oauth" }
- }
- }
- }
-}
-```
-
-The Endpoint still owns its acquisition flow and the Store only persists the result:
-
-```bash
-hypit auth login hypihub.default --runtime <profile>
-hypit auth status hypihub.default --runtime <profile>
-hypit auth logout hypihub.default --runtime <profile>
-```
-
-## What it does not do
-
-The choice is made once per host, from the platform the Runtime is running on. This is not a lookup
-chain: a miss or failure in one store never tries another, and no credential is migrated between them. A
-credential stored in a locker stays in that locker; a credential stored in a file stays in that file.
-
-## Configuration
-
-- `path` selects the directory for Linux file storage, resolved against the Host state root printed by
- `hypit paths`. The default is the same `credentials` directory `@hypit/credential-store-file` uses,
- so on Linux, switching between the two Stores finds the credential already stored.
-- WSL uses the Linux file Store. If the Host state root is on a Windows-mounted drive, select a
- private directory in the WSL Linux filesystem with `path`; the Store keeps its permission check.
-- `service` selects the locker service name. The OS Store's own default applies when it is absent.
-
-## Storage on each platform
-
-On macOS and Windows the credential is held by the platform locker, with exactly the rules of
-`@hypit/credential-store-os`: it is encrypted and access-controlled by the operating system, and it
-follows that locker’s access and synchronization policy. Windows Credential Locker may roam
-credentials through the user’s Microsoft account.
-
-On Linux the credential is held by an owner-private document with exactly the rules of
-`@hypit/credential-store-file`: unencrypted JSON, one document per key, directory mode `0700`, file
-mode `0600`, outside the video project, and never enumerated or indexed. Filesystem path-length
-limits apply to an overlong key, which fails rather than selecting another name. A damaged document
-can be replaced by `auth login` or deleted by `auth logout` without decoding the old value.
diff --git a/packages/credential-store-platform/package.json b/packages/credential-store-platform/package.json
deleted file mode 100644
index 5591b1b5..00000000
--- a/packages/credential-store-platform/package.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{
- "name": "@hypit/credential-store-platform",
- "version": "0.0.0-dev",
- "license": "SEE LICENSE IN LICENSE",
- "private": true,
- "type": "module",
- "exports": {
- ".": "./src/index.ts"
- },
- "files": [
- "src",
- "README.md"
- ],
- "hypit": {
- "activation": "./src/activation.ts"
- },
- "dependencies": {
- "@hypit/credential-store-file": "workspace:*",
- "@hypit/credential-store-os": "workspace:*",
- "@hypit/runtime": "workspace:*",
- "@hypit/runtime-kit": "workspace:*"
- }
-}
diff --git a/packages/credential-store-platform/src/activation.ts b/packages/credential-store-platform/src/activation.ts
deleted file mode 100644
index 3cd58d7e..00000000
--- a/packages/credential-store-platform/src/activation.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-import { join, resolve } from "node:path";
-import {
- createRuntimeCredentialStoreAdapterFacet,
- runtimeConfigExact,
- runtimeConfigObject,
- runtimeConfigString,
-} from "@hypit/runtime-kit";
-import { PlatformCredentialStore } from "./store.js";
-
-const platformCredentialStoreAdapter = createRuntimeCredentialStoreAdapterFacet({
- use: "@hypit/credential-store-platform",
- validate(context) {
- const config = runtimeConfigObject(context.config, "platform CredentialStore");
- runtimeConfigExact(config, ["path", "service"], "platform CredentialStore");
- runtimeConfigString(config.path, "platform credential path");
- runtimeConfigString(config.service, "platform credential service");
- },
- open(context) {
- const config = runtimeConfigObject(context.config, "platform CredentialStore");
- const path = runtimeConfigString(config.path, "platform credential path");
- const service = runtimeConfigString(config.service, "platform credential service");
- return {
- value: new PlatformCredentialStore({
- // Linux uses the same directory the file Store uses by default, so a Profile
- // that switches between them on Linux finds the credential it stored.
- directory: path === undefined ? join(context.hostStateRoot, "credentials") : resolve(context.hostStateRoot, path),
- ...(service === undefined ? {} : { service }),
- }),
- };
- },
-});
-
-export const hypitPackage = {
- format: "hypit.node-package@1" as const,
- hostFacets: [platformCredentialStoreAdapter],
-};
-export default hypitPackage;
diff --git a/packages/credential-store-platform/src/index.ts b/packages/credential-store-platform/src/index.ts
deleted file mode 100644
index eb9028e5..00000000
--- a/packages/credential-store-platform/src/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { PlatformCredentialStore } from "./store.js";
diff --git a/packages/endpoint-kit/README.md b/packages/endpoint/README.md
similarity index 89%
rename from packages/endpoint-kit/README.md
rename to packages/endpoint/README.md
index 7faeab45..b9a0d33d 100644
--- a/packages/endpoint-kit/README.md
+++ b/packages/endpoint/README.md
@@ -1,4 +1,4 @@
-# `@hypit/hypit/endpoint-kit`
+# `@hypit/hypit/endpoint`
SDK for packages that fulfill exact external capabilities.
@@ -8,8 +8,8 @@ runtime dependencies. The active Distribution supplies this API when loading the
No Hypit checkout is needed to develop or install the extension.
```ts
-import { defineEndpointPackage } from "@hypit/hypit/endpoint-kit";
-import type { AsyncEndpoint, CredentialRef, EndpointRequest } from "@hypit/hypit/endpoint-kit";
+import { defineEndpoint } from "@hypit/hypit/endpoint";
+import type { AsyncEndpoint, CredentialRef, EndpointRequest } from "@hypit/hypit/endpoint";
import { generationTypes, compileWireRequest, sealGeneratedImageSet } from "@hypit/hypit/generation";
```
@@ -25,9 +25,11 @@ ports into the service's wire format; the Provider need not import the model's i
One Provider can implement multiple capabilities, and another Provider can implement those same
capabilities. The Profile selects the implementation used by a project.
-An endpoint can call a vendor API, local process, Lambda function, device or human service. An
-endpoint package declares the capabilities it fulfills, its result types, credentials and scheduling
-limits, then installs handlers into a Host registrar.
+An endpoint can call a vendor API, local process, device or human service. A Provider package creates
+one configured Endpoint instance with `defineEndpoint`, declaring the capabilities it fulfills, its
+result types, credentials and scheduling limits, then installs handlers into a Host registrar. The
+configured instance is not itself a package: ordinary package management owns the Provider package,
+while the Runtime Profile owns instance identity and configuration.
Immediate endpoints return a result directly. Asynchronous endpoints implement `start`, `poll` and
optional best effort `cancel`. Provider-total and exact-capability resource limits control concurrency
@@ -73,7 +75,7 @@ actionLimits: {
}
```
-These are example deployment choices, not model limits. `defineEndpointPackage` scopes their resource
+These are example deployment choices, not model limits. `defineEndpoint` scopes their resource
identities to the declared pool; custom `actions` can instead supply explicit shared resource claims.
`concurrency` holds units until that action returns. A rate budget starts with `limit` permits,
replenishes `limit` permits per `periodMs`, and spends one permit per admitted action. One action may
@@ -87,9 +89,15 @@ independent of pricing metadata and does not promise byte-identical output. The
and asynchronous capabilities cannot be transient. Its capacity limits apply within one disposable
session; capabilities that require durable quota shared with Builds stay Build-only.
-Endpoint packages are selected by a Runtime Profile, never activated by author imports. This package
+Endpoint instances are selected by a Runtime Profile, never activated by author imports. This package
depends on no Node filesystem, scheduler implementation or video domain.
+HTTP is one optional Provider mechanism, not part of the generic Endpoint protocol. HTTP Providers
+import deadlines, Retry-After parsing and structured transport observations from
+`@hypit/hypit/endpoint/http`. Those helpers report what one request attempt observed; they do not
+choose whether catalogue lookup, submission, polling or collection should retry. The Provider owns
+that phase-specific decision and the meaning of every service response.
+
`pricing: { kind: "local" }` explicitly declares work on this machine without a Provider call charge.
`pricing: { kind: "page", url }` identifies published pricing information; it does not determine an
account's eventual bill. An absent declaration leaves pricing unknown. Callers can summarize explicit
diff --git a/packages/endpoint-kit/package.json b/packages/endpoint/package.json
similarity index 72%
rename from packages/endpoint-kit/package.json
rename to packages/endpoint/package.json
index 6e9c0f8c..996cb1f3 100644
--- a/packages/endpoint-kit/package.json
+++ b/packages/endpoint/package.json
@@ -1,11 +1,12 @@
{
- "name": "@hypit/endpoint-kit",
+ "name": "@hypit/endpoint",
"version": "0.0.0-dev",
"license": "SEE LICENSE IN LICENSE",
"private": true,
"type": "module",
"exports": {
- ".": "./src/index.ts"
+ ".": "./src/index.ts",
+ "./http": "./src/http.ts"
},
"dependencies": {
"@hypit/protocol": "workspace:*",
diff --git a/packages/endpoint/src/http.ts b/packages/endpoint/src/http.ts
new file mode 100644
index 00000000..4672ba89
--- /dev/null
+++ b/packages/endpoint/src/http.ts
@@ -0,0 +1,117 @@
+/** A non-success HTTP response. It is evidence, not by itself a service verdict. */
+export class EndpointHttpError extends Error {
+ constructor(
+ readonly code: string,
+ message: string,
+ readonly status: number,
+ readonly retryAfterMs?: number,
+ ) {
+ super(message);
+ }
+}
+
+/** The HTTP attempt produced no response: connection failure, interrupted read, or timeout. */
+export class EndpointTransportError extends Error {
+ readonly code: string | undefined;
+ readonly timeout: true | undefined;
+
+ constructor(message: string, options: ErrorOptions & { readonly code?: string; readonly timeout?: true } = {}) {
+ super(message, options);
+ this.code = options.code;
+ this.timeout = options.timeout;
+ }
+}
+
+/** A successful HTTP response whose body cannot be interpreted by the Provider. */
+export class EndpointResponseError extends Error {}
+
+type FailureDetail = {
+ readonly message: string;
+ readonly code?: string;
+};
+
+/** Preserve the useful chain hidden behind Node's generic `fetch failed` message. */
+function transportDetail(error: unknown): FailureDetail {
+ const messages: string[] = [];
+ let code: string | undefined;
+ let current: unknown = error;
+ const visited = new Set<object>();
+ while (current instanceof Error && !visited.has(current)) {
+ visited.add(current);
+ const currentCode = (current as { readonly code?: unknown }).code;
+ if (code === undefined && typeof currentCode === "string" && currentCode.length > 0) code = currentCode;
+ const message = current.message.trim();
+ if (message.length > 0 && messages.at(-1) !== message) messages.push(message);
+ current = current.cause;
+ }
+ if (messages.length === 0) messages.push(String(error));
+ const detail = code === undefined || messages.some((message) => message.includes(code))
+ ? messages.join(": ")
+ : `${messages.join(": ")}: ${code}`;
+ return { message: detail, ...(code === undefined ? {} : { code }) };
+}
+
+/** Convert a rejected HTTP send/read into structured transport evidence. */
+export function endpointTransportError(error: unknown): EndpointTransportError {
+ if (error instanceof EndpointTransportError) return error;
+ const detail = transportDetail(error);
+ return new EndpointTransportError(detail.message, {
+ cause: error,
+ ...(detail.code === undefined ? {} : { code: detail.code }),
+ });
+}
+
+/** Observe a rejected HTTP send/read without deciding the Endpoint action's outcome. */
+export async function transport<T>(request: Promise<T>): Promise<T> {
+ try {
+ return await request;
+ } catch (error) {
+ throw endpointTransportError(error);
+ }
+}
+
+export type RequestDeadline = {
+ readonly signal: AbortSignal;
+ readonly wait: <T>(work: Promise<T>) => Promise<T>;
+};
+
+/**
+ * Bound one Provider-owned HTTP exchange, including response-body consumption, and always release
+ * the timer. This helper performs no request and makes no retry or service-verdict decision.
+ */
+export async function withRequestDeadline<T>(
+ timeoutMs: number,
+ work: (deadline: RequestDeadline) => Promise<T>,
+ timeoutError: () => EndpointTransportError = () => new EndpointTransportError(
+ "Request timed out",
+ { timeout: true },
+ ),
+): Promise<T> {
+ if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1) {
+ throw new Error("Request timeout must be a positive integer");
+ }
+ const controller = new AbortController();
+ let reject!: (reason: EndpointTransportError) => void;
+ const expired = new Promise<never>((_resolve, fail) => { reject = fail; });
+ const timer = setTimeout(() => {
+ const reason = timeoutError();
+ reject(reason);
+ controller.abort(reason);
+ }, timeoutMs);
+ const wait = async <Value>(request: Promise<Value>): Promise<Value> => await transport(
+ Promise.race([request, expired]),
+ );
+ try {
+ return await work({ signal: controller.signal, wait });
+ } finally {
+ clearTimeout(timer);
+ }
+}
+
+/** The wait a `Retry-After` header asks for, in milliseconds: delay-seconds or an HTTP-date. */
+export function retryAfterMs(headers: Headers, now = Date.now()): number | undefined {
+ const value = headers.get("retry-after")?.trim();
+ if (value === undefined || value.length === 0) return undefined;
+ const delay = /^\d+$/u.test(value) ? Number(value) * 1000 : Date.parse(value) - now;
+ return Number.isFinite(delay) ? Math.max(0, Math.round(delay)) : undefined;
+}
diff --git a/packages/endpoint-kit/src/index.ts b/packages/endpoint/src/index.ts
similarity index 84%
rename from packages/endpoint-kit/src/index.ts
rename to packages/endpoint/src/index.ts
index e9dd806d..3bc62c92 100644
--- a/packages/endpoint-kit/src/index.ts
+++ b/packages/endpoint/src/index.ts
@@ -13,6 +13,7 @@ import type {
CredentialAcquisition,
CredentialRef,
CredentialValue,
+ ExecutionDiagnostic,
OperationFailure,
OperationProgress,
CapacityResourceClaim,
@@ -22,12 +23,18 @@ import { capacityUnits, verifyCredentialRef } from "@hypit/runtime";
export { canonicalize } from "@hypit/protocol";
export type { BlobRef, CanonicalValue, CapabilityRef, ModuleRef, ResourceId, StoredValue, TypeRef } from "@hypit/protocol";
-export { credentialRef, isStreamingResourceStore } from "@hypit/runtime";
+export {
+ credentialRef,
+ decodeOAuth2Credential,
+ encodeOAuth2Credential,
+ isStreamingResourceStore,
+} from "@hypit/runtime";
export type {
CapacityResourceClaim,
CredentialAcquisition,
CredentialRef,
CredentialValue,
+ ExecutionDiagnostic,
OperationFailure,
OperationProgress,
OperationReceipt,
@@ -244,7 +251,8 @@ export type EndpointPricing =
| { readonly kind: "page"; readonly url: string }
| { readonly kind: "local" };
-export type EndpointPackage = {
+/** One concrete Provider configuration selected by a Runtime Profile. */
+export type EndpointInstance = {
readonly instance: {
readonly id: string;
readonly pool: string;
@@ -305,9 +313,7 @@ export type AsyncEndpointCapability = EndpointCapabilityBase & {
export type EndpointCapability = ImmediateEndpointCapability | AsyncEndpointCapability;
-export type DefineEndpointPackageOptions = {
- readonly module: ModuleRef;
- readonly facet: string;
+export type DefineEndpointOptions = {
readonly instance: string;
/** Explicit non-secret account, deployment or compute-pool identity. */
readonly pool: string;
@@ -342,19 +348,16 @@ function positiveInteger(value: number, subject: string): number {
}
/** Build every static and executable fact for one configured Endpoint from one definition. */
-export function defineEndpointPackage(options: DefineEndpointPackageOptions): EndpointPackage {
- assert(options.module.name.trim().length > 0 && options.module.version.trim().length > 0,
- "Endpoint module identity is invalid");
- assert(options.facet.trim().length > 0, "Endpoint facet is empty");
+export function defineEndpoint(options: DefineEndpointOptions): EndpointInstance {
assert(options.instance.trim().length > 0, "Endpoint instance is empty");
assert(options.pool.trim().length > 0, "Endpoint Provider Pool is empty");
- assert(options.capabilities.length > 0, "Endpoint package declares no capability");
+ assert(options.capabilities.length > 0, "Endpoint instance declares no capability");
assert(options.actions === undefined || options.actionLimits === undefined,
- "Endpoint package must choose actions or actionLimits, not both");
+ "Endpoint instance must choose actions or actionLimits, not both");
const keys = options.capabilities.map((item) => refKey(item.capability));
- assert(new Set(keys).size === keys.length, "Endpoint package repeats a capability");
+ assert(new Set(keys).size === keys.length, "Endpoint instance repeats a capability");
const capacities = options.capabilities.map((item) => item.capacity ?? item.capability.name);
- assert(capacities.every((capacity) => capacity.trim().length > 0), "Endpoint package capacity class is empty");
+ assert(capacities.every((capacity) => capacity.trim().length > 0), "Endpoint instance capacity class is empty");
if (options.pricing?.kind === "page") {
let url: URL | undefined;
try { url = new URL(options.pricing.url); } catch { url = undefined; }
@@ -371,7 +374,7 @@ export function defineEndpointPackage(options: DefineEndpointPackageOptions): En
);
const previous = capacityConcurrency.get(capacity);
assert(previous === undefined || previous === concurrency,
- `Endpoint package capacity ${capacity} has conflicting concurrency limits`);
+ `Endpoint instance capacity ${capacity} has conflicting concurrency limits`);
capacityConcurrency.set(capacity, concurrency);
}
const credentials = Object.fromEntries(Object.entries(options.credentials ?? {})
@@ -497,58 +500,3 @@ export function wakeAfter(
export class EndpointServiceError extends Error {
constructor(readonly code: string, message: string) { super(message); }
}
-/** A non-success HTTP response, with the wait the service asked for when it gave one. */
-export class EndpointHttpError extends EndpointServiceError {
- constructor(code: string, message: string, readonly status: number, readonly retryAfterMs?: number) { super(code, message); }
-}
-/** The request produced no response: connection failure, interrupted read, or request timeout. */
-export class EndpointTransportError extends Error {}
-/** A success response whose body cannot be used. */
-export class EndpointResponseError extends Error {}
-
-/** Report a rejected send or read as a transport error. */
-export async function transport<T>(request: Promise<T>): Promise<T> {
- try { return await request; } catch (error) {
- if (error instanceof EndpointTransportError) throw error;
- throw new EndpointTransportError(transportMessage(error), { cause: error });
- }
-}
-
-// Node's fetch reports every network failure as "fetch failed"; which one it was (ECONNRESET,
-// UND_ERR_CONNECT_TIMEOUT, ENOTFOUND, a certificate error) is only on `cause`.
-function transportMessage(error: unknown): string {
- if (!(error instanceof Error)) return String(error);
- const cause = error.cause;
- if (!(cause instanceof Error)) return error.message;
- const code = (cause as { code?: unknown }).code;
- const detail = typeof code === "string" && !cause.message.includes(code)
- ? `${code} ${cause.message}`.trim()
- : cause.message;
- return detail.length > 0 ? `${error.message}: ${detail}` : error.message;
-}
-
-/** The wait a `Retry-After` header asks for, in milliseconds; either delay-seconds or an HTTP-date. */
-export function retryAfterMs(headers: Headers, now = Date.now()): number | undefined {
- const value = headers.get("retry-after")?.trim();
- if (value === undefined || value.length === 0) return undefined;
- const delay = /^\d+$/u.test(value) ? Number(value) * 1000 : Date.parse(value) - now;
- return Number.isFinite(delay) ? Math.max(0, Math.round(delay)) : undefined;
-}
-
-/**
- * Decide a poll action's outcome from the error it threw. Transport errors and HTTP 429/5xx keep the
- * job pending for the next poll; every other error, including credential and response errors, fails it.
- */
-export function pollAgainOrFail(error: unknown, options: {
- readonly handle: CanonicalValue;
- readonly pollIntervalMs: number;
- readonly failure: (error: unknown) => EndpointOutcome;
-}): EndpointOutcome {
- if (error instanceof EndpointTransportError) {
- return wakeAfter(options.handle, options.pollIntervalMs, Date.now(), { phase: "retrying" });
- }
- if (error instanceof EndpointHttpError && (error.status === 429 || error.status >= 500)) {
- return wakeAfter(options.handle, error.retryAfterMs ?? options.pollIntervalMs, Date.now(), { phase: "retrying" });
- }
- return options.failure(error);
-}
diff --git a/packages/endpoint-kit/test/endpoint.test.ts b/packages/endpoint/test/endpoint.test.ts
similarity index 70%
rename from packages/endpoint-kit/test/endpoint.test.ts
rename to packages/endpoint/test/endpoint.test.ts
index 56246c7c..07c06045 100644
--- a/packages/endpoint-kit/test/endpoint.test.ts
+++ b/packages/endpoint/test/endpoint.test.ts
@@ -2,19 +2,25 @@ import assert from "node:assert/strict";
import test from "node:test";
import {
- defineEndpointPackage,
+ defineEndpoint,
wakeAfter,
-} from "@hypit/endpoint-kit";
+} from "@hypit/endpoint";
+import {
+ EndpointTransportError,
+ endpointTransportError,
+ retryAfterMs,
+ withRequestDeadline,
+} from "@hypit/endpoint/http";
import type {
EndpointRegistrar,
EndpointRegistrationOptions,
ImmediateEndpointHandler,
AsyncEndpoint,
-} from "@hypit/endpoint-kit";
+} from "@hypit/endpoint";
import type { CapabilityRef, TypeRef } from "@hypit/protocol";
import { credentialRef } from "@hypit/runtime";
-import { capabilities, types } from "../../core/test/greeting-fixture.js";
+import { capabilities, types } from "../../kernel/test/greeting-fixture.js";
type CapturedRegistration = {
readonly id: string;
@@ -36,9 +42,7 @@ function capturingRegistrar(registrations: CapturedRegistration[]): EndpointRegi
}
test("one Endpoint definition generates one configured instance and host-neutral registration", async () => {
- const endpoint = defineEndpointPackage({
- module: { name: "example.provider", version: "1" },
- facet: "http-json",
+ const endpoint = defineEndpoint({
instance: "example.personal",
pool: "example.personal",
credentials: { apiKey: credentialRef("env", "EXAMPLE_API_KEY") },
@@ -81,9 +85,7 @@ test("one Endpoint definition generates one configured instance and host-neutral
});
test("an asynchronous Endpoint cannot opt into disposable execution", () => {
- assert.throws(() => defineEndpointPackage({
- module: { name: "example.provider", version: "1" },
- facet: "remote",
+ assert.throws(() => defineEndpoint({
instance: "example.remote",
pool: "example.remote",
capabilities: [{
@@ -106,3 +108,21 @@ test("wakeAfter turns polling policy into an explicit Runtime wake hint", () =>
wakeAt: 15_000,
});
});
+
+test("HTTP mechanics retain transport evidence without choosing an Endpoint outcome", async () => {
+ const now = Date.parse("2026-10-07T00:00:00Z");
+ assert.equal(retryAfterMs(new Headers({ "retry-after": "30" }), now), 30_000);
+ assert.equal(retryAfterMs(new Headers({ "retry-after": "Wed, 07 Oct 2026 00:00:45 GMT" }), now), 45_000);
+ assert.equal(retryAfterMs(new Headers({ "retry-after": "later" }), now), undefined);
+
+ const cause = Object.assign(new Error("getaddrinfo ENOTFOUND api.example.test"), { code: "ENOTFOUND" });
+ const observed = endpointTransportError(new TypeError("fetch failed", { cause }));
+ assert.equal(observed.code, "ENOTFOUND");
+ assert.match(observed.message, /fetch failed: getaddrinfo ENOTFOUND api\.example\.test/u);
+ assert.equal(observed.cause instanceof TypeError, true);
+
+ await assert.rejects(
+ withRequestDeadline(1, async ({ wait }) => await wait(new Promise(() => undefined))),
+ (error) => error instanceof EndpointTransportError && error.timeout === true,
+ );
+});
diff --git a/packages/provider-beatapi/README.md b/packages/provider-beatapi/README.md
index 1e3fa045..6e457dfc 100644
--- a/packages/provider-beatapi/README.md
+++ b/packages/provider-beatapi/README.md
@@ -54,8 +54,8 @@ Runtime Profile example:
"format": "hypit.runtime-local@1",
"dataRoot": ".hypit/runtimes/local",
"credentials": {
- "platform": {
- "use": "@hypit/credential-store-platform"
+ "local": {
+ "use": "@hypit/credential-store-local"
}
},
"endpoints": {
@@ -63,7 +63,7 @@ Runtime Profile example:
"use": "@hypit/provider-beatapi",
"pool": "beatapi.default",
"config": {
- "apiKey": { "store": "platform", "key": "beatapi.api-key" },
+ "apiKey": { "store": "local", "key": "beatapi.api-key" },
"defaultConcurrency": 3,
"pollIntervalMs": 10000
}
@@ -82,3 +82,6 @@ submission of the same body resolves to the same task.
HTTP failures keep BeatAPI's `error.code`, message, `request_id` and any `retry_after_seconds`; a
`failed` task keeps its `error_code` and `error_message`. Any URL inside a surfaced reason is
redacted, since a hosted result URL is an access capability rather than diagnostic content.
+Polling transport failures and HTTP 429/5xx preserve the same task. BeatAPI's
+`retry_after_seconds` takes precedence over the standard `Retry-After` header; either wait is capped
+at the original operation deadline, where the next poll concludes timeout without querying early.
diff --git a/packages/provider-beatapi/package.json b/packages/provider-beatapi/package.json
index 0fe75a91..a425356d 100644
--- a/packages/provider-beatapi/package.json
+++ b/packages/provider-beatapi/package.json
@@ -5,15 +5,19 @@
"private": true,
"type": "module",
"exports": { ".": "./src/index.ts" },
+ "files": ["dist", "README.md"],
"hypit": { "activation": "./src/activation.ts" },
- "dependencies": {
- "@hypit/endpoint-kit": "workspace:*",
+ "peerDependencies": {
+ "@hypit/hypit": "workspace:^",
+ "@hypit/runtime-local": "workspace:^"
+ },
+ "devDependencies": {
+ "@hypit/endpoint": "workspace:*",
"@hypit/generation": "workspace:*",
+ "@hypit/hypit": "workspace:*",
"@hypit/protocol": "workspace:*",
"@hypit/runtime": "workspace:*",
- "@hypit/runtime-kit": "workspace:*"
- },
- "devDependencies": {
+ "@hypit/runtime-local": "workspace:*",
"@hypit/gpt-image": "workspace:*",
"@hypit/grok-imagine": "workspace:*",
"@hypit/minimax-h3": "workspace:*",
diff --git a/packages/provider-beatapi/src/activation.ts b/packages/provider-beatapi/src/activation.ts
index 9645b5c0..1815c93f 100644
--- a/packages/provider-beatapi/src/activation.ts
+++ b/packages/provider-beatapi/src/activation.ts
@@ -6,7 +6,7 @@ import {
runtimeConfigObject,
runtimeConfigPositiveInteger,
runtimeConfigString,
-} from "@hypit/runtime-kit";
+} from "@hypit/runtime-local/extension";
import { createBeatApiProvider } from "./provider.js";
@@ -55,8 +55,8 @@ const adapter = createRuntimeEndpointAdapterFacet({
});
export const hypitPackage = {
- format: "hypit.node-package@1" as const,
- hostFacets: [adapter],
+ format: "hypit.package@1" as const,
+ facets: [adapter],
};
export default hypitPackage;
diff --git a/packages/provider-beatapi/src/errors.ts b/packages/provider-beatapi/src/errors.ts
index 0fa2ec16..16286b8a 100644
--- a/packages/provider-beatapi/src/errors.ts
+++ b/packages/provider-beatapi/src/errors.ts
@@ -1,4 +1,5 @@
-import { EndpointHttpError, EndpointServiceError } from "@hypit/endpoint-kit";
+import { EndpointServiceError } from "@hypit/hypit/endpoint";
+import { EndpointHttpError, retryAfterMs } from "@hypit/hypit/endpoint/http";
/** BeatAPI's `{ error: { code, message, request_id, retry_after_seconds } }` envelope and terminal task errors. */
function record(value: unknown): Record<string, unknown> | undefined {
@@ -25,15 +26,16 @@ export class BeatApiHttpError extends EndpointHttpError {
const code = text(error?.code) ?? "BEATAPI_HTTP_ERROR";
const reason = text(error?.message) ?? (error === undefined ? text(bodyText.slice(0, 2000)) : undefined);
const requestId = text(error?.request_id) ?? text(response.headers.get("x-request-id"));
- const retryAfter = typeof error?.retry_after_seconds === "number" ? error.retry_after_seconds : undefined;
+ const serviceRetryAfter = typeof error?.retry_after_seconds === "number" ? Math.round(error.retry_after_seconds * 1000) : undefined;
+ const retryAfter = serviceRetryAfter ?? retryAfterMs(response.headers);
const facts = [
`BeatAPI HTTP ${status}`, code, `${request.method} ${request.path}`,
...(request.model === undefined ? [] : [`model=${request.model}`]),
...(requestId === undefined ? [] : [`request=${requestId}`]),
- ...(retryAfter === undefined ? [] : [`retry-after=${retryAfter}s`]),
+ ...(retryAfter === undefined ? [] : [`retry-after=${retryAfter}ms`]),
];
super(code, `${facts.join("; ")}${reason === undefined ? "" : `: ${safeBeatApiReason(reason)}`}`,
- status, retryAfter === undefined ? undefined : Math.round(retryAfter * 1000));
+ status, retryAfter);
}
}
diff --git a/packages/provider-beatapi/src/mapping.ts b/packages/provider-beatapi/src/mapping.ts
index a56d2202..6b88c5e9 100644
--- a/packages/provider-beatapi/src/mapping.ts
+++ b/packages/provider-beatapi/src/mapping.ts
@@ -1,5 +1,5 @@
-import type { ModuleRef } from "@hypit/protocol";
-import type { GenerationWireMapping } from "@hypit/generation";
+import type { ModuleRef } from "@hypit/hypit/protocol";
+import type { GenerationWireMapping } from "@hypit/hypit/generation";
const SEEDANCE: ModuleRef = { name: "@hypit/seedance", version: "1" };
const MINIMAX: ModuleRef = { name: "@hypit/minimax-h3", version: "1" };
diff --git a/packages/provider-beatapi/src/provider.ts b/packages/provider-beatapi/src/provider.ts
index 8cad98eb..4122e6b9 100644
--- a/packages/provider-beatapi/src/provider.ts
+++ b/packages/provider-beatapi/src/provider.ts
@@ -1,11 +1,11 @@
-import { requestDeadline } from "@hypit/runtime-kit";
-import type { AsyncEndpoint, EndpointCredential, EndpointInvocationContext, EndpointOutcome } from "@hypit/endpoint-kit";
-import { EndpointResponseError, EndpointServiceError, EndpointTransportError, defineEndpointPackage, pollAgainOrFail, transport, wakeAfter } from "@hypit/endpoint-kit";
-import type { GenerationArtifactUrlResolver } from "@hypit/generation";
-import { canonicalize } from "@hypit/protocol";
-import type { BlobRef, CapabilityRef } from "@hypit/protocol";
-import { credentialRef } from "@hypit/runtime";
-import type { CredentialRef, ResourceStore } from "@hypit/runtime";
+import type { AsyncEndpoint, EndpointCredential, EndpointInvocationContext, EndpointOutcome } from "@hypit/hypit/endpoint";
+import { EndpointServiceError, defineEndpoint, wakeAfter } from "@hypit/hypit/endpoint";
+import { EndpointHttpError, EndpointResponseError, EndpointTransportError, withRequestDeadline } from "@hypit/hypit/endpoint/http";
+import type { GenerationArtifactUrlResolver } from "@hypit/hypit/generation";
+import { canonicalize } from "@hypit/hypit/protocol";
+import type { BlobRef, CanonicalValue, CapabilityRef } from "@hypit/hypit/protocol";
+import { credentialRef } from "@hypit/hypit/endpoint";
+import type { CredentialRef, ResourceStore } from "@hypit/hypit/endpoint";
import { beatApiRouteForCapability, beatApiRoutes } from "./routes.js";
import { BeatApiHttpError, BeatApiServiceError, beatApiTaskFailure } from "./errors.js";
@@ -17,7 +17,7 @@ export type CreateBeatApiProviderOptions = {
readonly baseUrl?: string;
readonly apiKey?: CredentialRef;
readonly defaultConcurrency?: number;
- readonly actionLimits?: import("@hypit/endpoint-kit").EndpointActionLimits;
+ readonly actionLimits?: import("@hypit/hypit/endpoint").EndpointActionLimits;
readonly pollIntervalMs?: number;
readonly requestTimeoutMs?: number;
readonly operationTimeoutMs?: number;
@@ -64,7 +64,10 @@ function apiBaseUrl(value: string): string {
}
function apiKey(credentials: Readonly<Record<string, EndpointCredential>>): string {
const value = credentials.apiKey?.secret;
- assert(typeof value === "string" && value.length > 0, "BeatAPI apiKey credential is unavailable; store a BeatAPI API key for this Endpoint");
+ if (typeof value !== "string" || value.length === 0) {
+ throw new BeatApiServiceError("BEATAPI_CREDENTIAL_UNAVAILABLE",
+ "BeatAPI apiKey credential is unavailable; store a BeatAPI API key for this Endpoint");
+ }
return value;
}
function httpsUrl(value: unknown, subject: string): string {
@@ -75,18 +78,34 @@ function failureMessage(error: unknown): string {
return error instanceof Error ? error.message : String(error);
}
function failure(error: unknown): EndpointOutcome {
- return { status: "failed", failure: { code: error instanceof EndpointServiceError ? error.code : "BEATAPI_ERROR", message: failureMessage(error) } };
+ if (!(error instanceof EndpointServiceError || error instanceof EndpointHttpError
+ || error instanceof EndpointTransportError || error instanceof EndpointResponseError)) throw error;
+ const code = error instanceof EndpointServiceError || error instanceof EndpointHttpError ? error.code : "BEATAPI_ERROR";
+ return { status: "failed", failure: { code, message: failureMessage(error) } };
+}
+function retrying(error: unknown, handle: CanonicalValue, pollIntervalMs: number, deadlineAt?: number): EndpointOutcome | undefined {
+ const delay = error instanceof EndpointTransportError ? pollIntervalMs
+ : error instanceof EndpointHttpError && (error.status === 429 || error.status >= 500)
+ ? error.retryAfterMs ?? pollIntervalMs : undefined;
+ if (delay === undefined) return undefined;
+ const now = Date.now();
+ return { status: "pending", handle, wakeAt: Math.min(now + delay, deadlineAt ?? Number.MAX_SAFE_INTEGER), progress: { phase: "retrying" } };
+}
+function unknownSubmission(error: unknown): EndpointOutcome | undefined {
+ return error instanceof EndpointTransportError ? { status: "failed", failure: {
+ code: "BEATAPI_SUBMISSION_UNKNOWN",
+ message: `BeatAPI submission transport failed; remote outcome is unknown: ${error.message}`,
+ } } : undefined;
}
class BeatApiClient {
constructor(readonly baseUrl: string, readonly timeout: number, readonly fetcher: typeof globalThis.fetch) {}
async json(path: string, key: string, init: RequestInit = {}): Promise<Record<string, unknown>> {
- const deadline = requestDeadline(this.timeout, () => new EndpointTransportError("BeatAPI request timed out"));
- try {
- const response = await transport(deadline.wait(this.fetcher(`${this.baseUrl}${path}`, {
- ...init, signal: deadline.signal, headers: { authorization: `Bearer ${key}`, ...(init.headers ?? {}) },
- })));
- const text = await transport(deadline.wait(response.text()));
+ return await withRequestDeadline(this.timeout, async ({ signal, wait }) => {
+ const response = await wait(this.fetcher(`${this.baseUrl}${path}`, {
+ ...init, signal, headers: { authorization: `Bearer ${key}`, ...(init.headers ?? {}) },
+ }));
+ const text = await wait(response.text());
if (!response.ok) {
const input = typeof init.body === "string" ? JSON.parse(init.body) as Record<string, unknown> : undefined;
throw new BeatApiHttpError(response.status, response, text, {
@@ -96,7 +115,7 @@ class BeatApiClient {
let body: unknown;
try { body = text.length === 0 ? {} : JSON.parse(text); } catch { throw new EndpointResponseError(`BeatAPI returned invalid JSON (${response.status})`); }
return object(object(body, "BeatAPI response").data, "BeatAPI response data");
- } finally { deadline.finish(); }
+ }, () => new EndpointTransportError("BeatAPI request timed out", { timeout: true }));
}
/** Upload one referenced Resource and return the HTTPS URL the task request carries. */
async upload(artifact: BlobRef, resources: ResourceStore, key: string): Promise<string> {
@@ -117,12 +136,11 @@ class BeatApiClient {
return httpsUrl(file.url, "BeatAPI file upload");
}
async download(url: string): Promise<{ readonly bytes: Uint8Array; readonly mediaType: string }> {
- const deadline = requestDeadline(this.timeout);
- try {
- const response = await deadline.wait(this.fetcher(url, { signal: deadline.signal }));
- if (!response.ok) throw new Error(`BeatAPI asset returned HTTP ${response.status}`);
- return { bytes: new Uint8Array(await deadline.wait(response.arrayBuffer())), mediaType: response.headers.get("content-type")?.split(";", 1)[0] ?? "application/octet-stream" };
- } finally { deadline.finish(); }
+ return await withRequestDeadline(this.timeout, async ({ signal, wait }) => {
+ const response = await wait(this.fetcher(url, { signal }));
+ if (!response.ok) throw new BeatApiHttpError(response.status, response, "", { method: "GET", path: url });
+ return { bytes: new Uint8Array(await wait(response.arrayBuffer())), mediaType: response.headers.get("content-type")?.split(";", 1)[0] ?? "application/octet-stream" };
+ });
}
}
@@ -150,20 +168,21 @@ function endpoint(client: BeatApiClient, pollIntervalMs: number, maxOperationMs:
assert(route !== undefined, "BeatAPI does not implement this exact capability");
const request = route.prepare(context.need.constraints);
await context.reportProgress?.({ phase: `Preparing BeatAPI request: ${request.model}` });
- let body: Record<string, unknown>;
+ const body = await request.compile(resolverFor(client, context, publicAssetUrl));
+ await context.reportProgress?.({ phase: `Submitting BeatAPI request: ${request.model}` });
+ let response: Record<string, unknown>;
try {
- body = await request.compile(resolverFor(client, context, publicAssetUrl));
+ response = await client.json(`/v1/${request.media}s/tasks`, apiKey(context.credentials), {
+ method: "POST",
+ headers: { "content-type": "application/json", "idempotency-key": context.operation },
+ body: JSON.stringify(body),
+ });
} catch (error) {
- throw new BeatApiServiceError(error instanceof EndpointServiceError ? error.code : "BEATAPI_ERROR",
- `BeatAPI request preparation failed; model=${request.model}; generation not submitted: ${failureMessage(error)}`);
+ const unknown = unknownSubmission(error);
+ if (unknown !== undefined) return unknown;
+ throw error;
}
- await context.reportProgress?.({ phase: `Submitting BeatAPI request: ${request.model}` });
- const response = await client.json(`/v1/${request.media}s/tasks`, apiKey(context.credentials), {
- method: "POST",
- headers: { "content-type": "application/json", "idempotency-key": context.operation },
- body: JSON.stringify(body),
- });
- assert(typeof response.id === "string" && response.id.length > 0, "BeatAPI response has no task id");
+ if (typeof response.id !== "string" || response.id.length === 0) throw new EndpointResponseError("BeatAPI response has no task id");
const handle: Handle = { contract: "hypit.beatapi-operation@1", taskId: response.id, route: route.key, startedAt: Date.now() };
const receipt = { id: handle.taskId };
await context.checkpoint?.({ handle: canonicalize(handle), receipt });
@@ -173,12 +192,14 @@ function endpoint(client: BeatApiClient, pollIntervalMs: number, maxOperationMs:
}
},
async poll(context) {
+ let operationDeadlineAt: number | undefined;
try {
const handle = object(context.handle, "BeatAPI handle") as unknown as Handle;
const route = beatApiRouteForCapability(context.need.capability);
assert(route !== undefined && handle.contract === "hypit.beatapi-operation@1" && handle.route === route.key, "BeatAPI handle is invalid");
const receipt = { id: handle.taskId };
- if (Date.now() - handle.startedAt > maxOperationMs) {
+ operationDeadlineAt = handle.startedAt + maxOperationMs;
+ if (Date.now() >= operationDeadlineAt) {
return { status: "failed", receipt, failure: { code: "BEATAPI_OPERATION_TIMEOUT", message: `BeatAPI task ${handle.taskId} exceeded this Provider's operationTimeoutMs (${maxOperationMs}); remote outcome is unknown` } };
}
const task = await client.json(`/v1/tasks/${encodeURIComponent(handle.taskId)}`, apiKey(context.credentials));
@@ -188,13 +209,13 @@ function endpoint(client: BeatApiClient, pollIntervalMs: number, maxOperationMs:
}
const rejected = beatApiTaskFailure(task, handle.taskId);
if (rejected !== undefined) return { ...failure(rejected), receipt };
- assert(status === "succeeded", `BeatAPI returned unknown task status ${status}`);
+ if (status !== "succeeded") throw new EndpointResponseError(`BeatAPI returned unknown task status ${status}`);
const media = object(task.output, "BeatAPI task output").media;
- assert(Array.isArray(media) && media.length > 0, "BeatAPI task succeeded without output media");
+ if (!Array.isArray(media) || media.length === 0) throw new EndpointResponseError("BeatAPI task succeeded without output media");
const urls = media.map((item, index) => httpsUrl(object(item, `BeatAPI output ${index + 1}`).url, `BeatAPI output ${index + 1}`));
return { status: "ready", handle: canonicalize({ ...handle, urls }), receipt };
} catch (error) {
- return pollAgainOrFail(error, { handle: context.handle, pollIntervalMs, failure });
+ return retrying(error, context.handle, pollIntervalMs, operationDeadlineAt) ?? failure(error);
}
},
async collect(context) {
@@ -210,7 +231,7 @@ function endpoint(client: BeatApiClient, pollIntervalMs: number, maxOperationMs:
}
return { status: "completed", result: { value: route.packageResult(blobs) }, receipt: { id: handle.taskId } };
} catch (error) {
- return failure(error);
+ return retrying(error, context.handle, pollIntervalMs) ?? failure(error);
}
},
};
@@ -224,10 +245,10 @@ export function createBeatApiProvider(options: CreateBeatApiProviderOptions = {}
}
const client = new BeatApiClient(apiBaseUrl(options.baseUrl ?? "https://api.beatapi.io"), requestTimeoutMs, options.fetch ?? globalThis.fetch);
const asyncEndpoint = endpoint(client, options.pollIntervalMs ?? 10_000, operationTimeoutMs, options.publicAssetUrl);
- return defineEndpointPackage({
- module: beatApiProviderModuleRef, facet: "gateway", instance: options.instance ?? "beatapi.default", pool: options.pool ?? options.instance ?? "beatapi.default",
+ return defineEndpoint({
+ instance: options.instance ?? "beatapi.default", pool: options.pool ?? options.instance ?? "beatapi.default",
pricing: { kind: "page", url: "https://docs.beatapi.io/pricing" },
- credentials: { apiKey: options.apiKey ?? credentialRef("os", "beatapi.api-key") },
+ credentials: { apiKey: options.apiKey ?? credentialRef("local", "beatapi.api-key") },
credentialInputs: { apiKey: { label: "BeatAPI API key" } },
defaultConcurrency: options.defaultConcurrency ?? 4,
...(options.actionLimits === undefined ? {} : { actionLimits: options.actionLimits }),
diff --git a/packages/provider-beatapi/src/routes.ts b/packages/provider-beatapi/src/routes.ts
index d60dd784..fb37f8bc 100644
--- a/packages/provider-beatapi/src/routes.ts
+++ b/packages/provider-beatapi/src/routes.ts
@@ -4,11 +4,11 @@ import {
generationTypes,
sealGeneratedImageSet,
sealGeneratedVideoSet,
-} from "@hypit/generation";
-import type { GenerationArtifactUrlResolver, GenerationRequest, GenerationWireMapping } from "@hypit/generation";
-import { canonicalize } from "@hypit/protocol";
-import type { BlobRef, CapabilityRef, CanonicalValue, StoredValue, TypeRef } from "@hypit/protocol";
-import type { EndpointRequest, EndpointSupport } from "@hypit/endpoint-kit";
+} from "@hypit/hypit/generation";
+import type { GenerationArtifactUrlResolver, GenerationRequest, GenerationWireMapping } from "@hypit/hypit/generation";
+import { canonicalize } from "@hypit/hypit/protocol";
+import type { BlobRef, CapabilityRef, CanonicalValue, StoredValue, TypeRef } from "@hypit/hypit/protocol";
+import type { EndpointRequest, EndpointSupport } from "@hypit/hypit/endpoint";
import { beatApiMappings } from "./mapping.js";
export type BeatApiPreparedRequest = {
diff --git a/packages/provider-hiapi/README.md b/packages/provider-hiapi/README.md
index 9ce3452c..38dee28d 100644
--- a/packages/provider-hiapi/README.md
+++ b/packages/provider-hiapi/README.md
@@ -55,8 +55,8 @@ Runtime Profile example:
"format": "hypit.runtime-local@1",
"dataRoot": ".hypit/runtimes/local",
"credentials": {
- "platform": {
- "use": "@hypit/credential-store-platform"
+ "local": {
+ "use": "@hypit/credential-store-local"
}
},
"endpoints": {
@@ -64,7 +64,7 @@ Runtime Profile example:
"use": "@hypit/provider-hiapi",
"pool": "hiapi.default",
"config": {
- "apiKey": { "store": "platform", "key": "hiapi.api-key" },
+ "apiKey": { "store": "local", "key": "hiapi.api-key" },
"defaultConcurrency": 3,
"pollIntervalMs": 10000
}
@@ -79,3 +79,5 @@ Runtime Profile example:
`operationTimeoutMs` and `actionLimits` bound single HTTP calls, the whole remote task and action
concurrency. HTTP failures keep HiAPI's `error_code` and message; failed tasks keep
`data.error.code` and message, with any signed URL in the message redacted.
+Polling transport failures and HTTP 429/5xx preserve the same task and honor standard `Retry-After`;
+the scheduled wake never passes the original operation deadline. Other errors end the local attempt.
diff --git a/packages/provider-hiapi/package.json b/packages/provider-hiapi/package.json
index 80dbd109..3bb1553d 100644
--- a/packages/provider-hiapi/package.json
+++ b/packages/provider-hiapi/package.json
@@ -5,15 +5,19 @@
"private": true,
"type": "module",
"exports": { ".": "./src/index.ts" },
+ "files": ["dist", "README.md"],
"hypit": { "activation": "./src/activation.ts" },
- "dependencies": {
- "@hypit/endpoint-kit": "workspace:*",
+ "peerDependencies": {
+ "@hypit/hypit": "workspace:^",
+ "@hypit/runtime-local": "workspace:^"
+ },
+ "devDependencies": {
+ "@hypit/endpoint": "workspace:*",
"@hypit/generation": "workspace:*",
+ "@hypit/hypit": "workspace:*",
"@hypit/protocol": "workspace:*",
"@hypit/runtime": "workspace:*",
- "@hypit/runtime-kit": "workspace:*"
- },
- "devDependencies": {
+ "@hypit/runtime-local": "workspace:*",
"@hypit/gpt-image": "workspace:*",
"@hypit/grok-imagine": "workspace:*",
"@hypit/minimax-h3": "workspace:*",
diff --git a/packages/provider-hiapi/src/activation.ts b/packages/provider-hiapi/src/activation.ts
index 61814ddc..5934c70d 100644
--- a/packages/provider-hiapi/src/activation.ts
+++ b/packages/provider-hiapi/src/activation.ts
@@ -6,7 +6,7 @@ import {
runtimeConfigObject,
runtimeConfigPositiveInteger,
runtimeConfigString,
-} from "@hypit/runtime-kit";
+} from "@hypit/runtime-local/extension";
import { createHiApiProvider } from "./provider.js";
@@ -55,8 +55,8 @@ const adapter = createRuntimeEndpointAdapterFacet({
});
export const hypitPackage = {
- format: "hypit.node-package@1" as const,
- hostFacets: [adapter],
+ format: "hypit.package@1" as const,
+ facets: [adapter],
};
export default hypitPackage;
diff --git a/packages/provider-hiapi/src/errors.ts b/packages/provider-hiapi/src/errors.ts
index b0f6ce1c..2dc62ee3 100644
--- a/packages/provider-hiapi/src/errors.ts
+++ b/packages/provider-hiapi/src/errors.ts
@@ -1,4 +1,5 @@
-import { EndpointHttpError, EndpointServiceError } from "@hypit/endpoint-kit";
+import { EndpointServiceError } from "@hypit/hypit/endpoint";
+import { EndpointHttpError, retryAfterMs } from "@hypit/hypit/endpoint/http";
/** HiAPI's `{ code, message, error_code }` envelope and task `error` object, kept at the service boundary. */
function record(value: unknown): Record<string, unknown> | undefined {
@@ -29,7 +30,8 @@ export class HiApiHttpError extends EndpointHttpError {
...(request.model === undefined ? [] : [`model=${request.model}`]),
...(requestId === undefined ? [] : [`request=${requestId}`]),
];
- super(code, `${facts.join("; ")}${reason === undefined ? "" : `: ${safeHiApiReason(reason)}`}`, status);
+ super(code, `${facts.join("; ")}${reason === undefined ? "" : `: ${safeHiApiReason(reason)}`}`,
+ status, retryAfterMs(response.headers));
}
}
diff --git a/packages/provider-hiapi/src/mapping.ts b/packages/provider-hiapi/src/mapping.ts
index d4393b0d..8b7789a8 100644
--- a/packages/provider-hiapi/src/mapping.ts
+++ b/packages/provider-hiapi/src/mapping.ts
@@ -1,5 +1,5 @@
-import type { ModuleRef } from "@hypit/protocol";
-import type { GenerationWireMapping } from "@hypit/generation";
+import type { ModuleRef } from "@hypit/hypit/protocol";
+import type { GenerationWireMapping } from "@hypit/hypit/generation";
const SEEDANCE: ModuleRef = { name: "@hypit/seedance", version: "1" };
const SEEDREAM: ModuleRef = { name: "@hypit/seedream", version: "1" };
diff --git a/packages/provider-hiapi/src/provider.ts b/packages/provider-hiapi/src/provider.ts
index af443c9b..ef69396e 100644
--- a/packages/provider-hiapi/src/provider.ts
+++ b/packages/provider-hiapi/src/provider.ts
@@ -1,11 +1,11 @@
-import { requestDeadline } from "@hypit/runtime-kit";
-import type { AsyncEndpoint, EndpointCredential, EndpointInvocationContext, EndpointOutcome } from "@hypit/endpoint-kit";
-import { EndpointResponseError, EndpointServiceError, EndpointTransportError, defineEndpointPackage, pollAgainOrFail, transport, wakeAfter } from "@hypit/endpoint-kit";
-import type { GenerationArtifactUrlResolver } from "@hypit/generation";
-import { canonicalize } from "@hypit/protocol";
-import type { BlobRef, CapabilityRef } from "@hypit/protocol";
-import { credentialRef } from "@hypit/runtime";
-import type { CredentialRef, ResourceStore } from "@hypit/runtime";
+import type { AsyncEndpoint, EndpointCredential, EndpointInvocationContext, EndpointOutcome } from "@hypit/hypit/endpoint";
+import { EndpointServiceError, defineEndpoint, wakeAfter } from "@hypit/hypit/endpoint";
+import { EndpointHttpError, EndpointResponseError, EndpointTransportError, withRequestDeadline } from "@hypit/hypit/endpoint/http";
+import type { GenerationArtifactUrlResolver } from "@hypit/hypit/generation";
+import { canonicalize } from "@hypit/hypit/protocol";
+import type { BlobRef, CanonicalValue, CapabilityRef } from "@hypit/hypit/protocol";
+import { credentialRef } from "@hypit/hypit/endpoint";
+import type { CredentialRef, ResourceStore } from "@hypit/hypit/endpoint";
import { hiApiRouteForCapability, hiApiRoutes } from "./routes.js";
import type { HiApiMediaLimits } from "./routes.js";
import { HiApiHttpError, HiApiServiceError, hiApiTaskFailure } from "./errors.js";
@@ -18,7 +18,7 @@ export type CreateHiApiProviderOptions = {
readonly baseUrl?: string;
readonly apiKey?: CredentialRef;
readonly defaultConcurrency?: number;
- readonly actionLimits?: import("@hypit/endpoint-kit").EndpointActionLimits;
+ readonly actionLimits?: import("@hypit/hypit/endpoint").EndpointActionLimits;
readonly pollIntervalMs?: number;
readonly requestTimeoutMs?: number;
readonly operationTimeoutMs?: number;
@@ -49,25 +49,49 @@ function apiBaseUrl(value: string): string {
}
function apiKey(credentials: Readonly<Record<string, EndpointCredential>>): string {
const value = credentials.apiKey?.secret;
- assert(typeof value === "string" && value.length > 0, "HiAPI apiKey credential is unavailable; store a HiAPI API key for this Endpoint");
+ if (typeof value !== "string" || value.length === 0) {
+ throw new HiApiServiceError("HIAPI_CREDENTIAL_UNAVAILABLE",
+ "HiAPI apiKey credential is unavailable; store a HiAPI API key for this Endpoint");
+ }
return value;
}
function failureMessage(error: unknown): string {
return error instanceof Error ? error.message : String(error);
}
function failure(error: unknown): EndpointOutcome {
- return { status: "failed", failure: { code: error instanceof EndpointServiceError ? error.code : "HIAPI_ERROR", message: failureMessage(error) } };
+ if (!(error instanceof EndpointServiceError
+ || error instanceof EndpointHttpError
+ || error instanceof EndpointTransportError
+ || error instanceof EndpointResponseError)) throw error;
+ const code = error instanceof EndpointServiceError || error instanceof EndpointHttpError
+ ? error.code : "HIAPI_ERROR";
+ return { status: "failed", failure: { code, message: failureMessage(error) } };
+}
+function retrying(error: unknown, handle: CanonicalValue, pollIntervalMs: number, deadlineAt?: number): EndpointOutcome | undefined {
+ const delay = error instanceof EndpointTransportError
+ ? pollIntervalMs
+ : error instanceof EndpointHttpError && (error.status === 429 || error.status >= 500)
+ ? error.retryAfterMs ?? pollIntervalMs
+ : undefined;
+ if (delay === undefined) return undefined;
+ const now = Date.now();
+ return { status: "pending", handle, wakeAt: Math.min(now + delay, deadlineAt ?? Number.MAX_SAFE_INTEGER), progress: { phase: "retrying" } };
+}
+function unknownSubmission(error: unknown): EndpointOutcome | undefined {
+ return error instanceof EndpointTransportError ? { status: "failed", failure: {
+ code: "HIAPI_SUBMISSION_UNKNOWN",
+ message: `HiAPI submission transport failed; remote outcome is unknown: ${error.message}`,
+ } } : undefined;
}
class HiApiClient {
constructor(readonly baseUrl: string, readonly timeout: number, readonly fetcher: typeof globalThis.fetch) {}
async json(path: string, key: string, init: RequestInit = {}): Promise<Record<string, unknown>> {
- const deadline = requestDeadline(this.timeout, () => new EndpointTransportError("HiAPI request timed out"));
- try {
- const response = await transport(deadline.wait(this.fetcher(`${this.baseUrl}${path}`, {
- ...init, signal: deadline.signal, headers: { authorization: `Bearer ${key}`, ...(init.headers ?? {}) },
- })));
- const text = await transport(deadline.wait(response.text()));
+ return await withRequestDeadline(this.timeout, async ({ signal, wait }) => {
+ const response = await wait(this.fetcher(`${this.baseUrl}${path}`, {
+ ...init, signal, headers: { authorization: `Bearer ${key}`, ...(init.headers ?? {}) },
+ }));
+ const text = await wait(response.text());
if (!response.ok) {
const input = typeof init.body === "string" ? JSON.parse(init.body) as Record<string, unknown> : undefined;
throw new HiApiHttpError(response.status, response, text, {
@@ -77,15 +101,14 @@ class HiApiClient {
let body: unknown;
try { body = text.length === 0 ? {} : JSON.parse(text); } catch { throw new EndpointResponseError(`HiAPI returned invalid JSON (${response.status})`); }
return object(object(body, "HiAPI response").data, "HiAPI response data");
- } finally { deadline.finish(); }
+ }, () => new EndpointTransportError("HiAPI request timed out", { timeout: true }));
}
async download(url: string): Promise<{ readonly bytes: Uint8Array; readonly mediaType: string }> {
- const deadline = requestDeadline(this.timeout);
- try {
- const response = await deadline.wait(this.fetcher(url, { signal: deadline.signal }));
- if (!response.ok) throw new Error(`HiAPI asset returned HTTP ${response.status}`);
- return { bytes: new Uint8Array(await deadline.wait(response.arrayBuffer())), mediaType: response.headers.get("content-type")?.split(";", 1)[0] ?? "application/octet-stream" };
- } finally { deadline.finish(); }
+ return await withRequestDeadline(this.timeout, async ({ signal, wait }) => {
+ const response = await wait(this.fetcher(url, { signal }));
+ if (!response.ok) throw new HiApiHttpError(response.status, response, "", { method: "GET", path: url });
+ return { bytes: new Uint8Array(await wait(response.arrayBuffer())), mediaType: response.headers.get("content-type")?.split(";", 1)[0] ?? "application/octet-stream" };
+ });
}
}
@@ -127,17 +150,19 @@ function endpoint(client: HiApiClient, pollIntervalMs: number, maxOperationMs: n
const request = route.prepare(context.need.constraints);
await context.reportProgress?.({ phase: `Preparing HiAPI request: ${request.model}` });
let body: Record<string, unknown>;
+ body = await request.compile(resolverFor(request.mediaLimits, context, publicAssetUrl));
+ await context.reportProgress?.({ phase: `Submitting HiAPI request: ${request.model}` });
+ let response: Record<string, unknown>;
try {
- body = await request.compile(resolverFor(request.mediaLimits, context, publicAssetUrl));
+ response = await client.json("/v1/tasks", apiKey(context.credentials), {
+ method: "POST", headers: { "content-type": "application/json", "idempotency-key": context.operation }, body: JSON.stringify(body),
+ });
} catch (error) {
- throw new HiApiServiceError(error instanceof EndpointServiceError ? error.code : "HIAPI_ERROR",
- `HiAPI request preparation failed; model=${request.model}; generation not submitted: ${failureMessage(error)}`);
+ const unknown = unknownSubmission(error);
+ if (unknown !== undefined) return unknown;
+ throw error;
}
- await context.reportProgress?.({ phase: `Submitting HiAPI request: ${request.model}` });
- const response = await client.json("/v1/tasks", apiKey(context.credentials), {
- method: "POST", headers: { "content-type": "application/json", "idempotency-key": context.operation }, body: JSON.stringify(body),
- });
- assert(typeof response.taskId === "string" && response.taskId.length > 0, "HiAPI response has no taskId");
+ if (typeof response.taskId !== "string" || response.taskId.length === 0) throw new EndpointResponseError("HiAPI response has no taskId");
const handle: Handle = { contract: "hypit.hiapi-operation@1", taskId: response.taskId, route: route.key, startedAt: Date.now() };
const receipt = { id: handle.taskId };
await context.checkpoint?.({ handle: canonicalize(handle), receipt });
@@ -147,12 +172,14 @@ function endpoint(client: HiApiClient, pollIntervalMs: number, maxOperationMs: n
}
},
async poll(context) {
+ let operationDeadlineAt: number | undefined;
try {
const handle = object(context.handle, "HiAPI handle") as unknown as Handle;
const route = hiApiRouteForCapability(context.need.capability);
assert(route !== undefined && handle.contract === "hypit.hiapi-operation@1" && handle.route === route.key, "HiAPI handle is invalid");
const receipt = { id: handle.taskId };
- if (Date.now() - handle.startedAt > maxOperationMs) {
+ operationDeadlineAt = handle.startedAt + maxOperationMs;
+ if (Date.now() >= operationDeadlineAt) {
return { status: "failed", receipt, failure: { code: "HIAPI_OPERATION_TIMEOUT", message: `HiAPI task ${handle.taskId} exceeded this Provider's operationTimeoutMs (${maxOperationMs}); remote outcome is unknown` } };
}
const task = await client.json(`/v1/tasks/${encodeURIComponent(handle.taskId)}`, apiKey(context.credentials));
@@ -162,16 +189,16 @@ function endpoint(client: HiApiClient, pollIntervalMs: number, maxOperationMs: n
}
const rejected = hiApiTaskFailure(task, handle.taskId);
if (rejected !== undefined) return { ...failure(rejected), receipt };
- assert(status === "success", `HiAPI returned unknown task status ${status}`);
- assert(Array.isArray(task.output) && task.output.length > 0, "HiAPI task succeeded without output");
+ if (status !== "success") throw new EndpointResponseError(`HiAPI returned unknown task status ${status}`);
+ if (!Array.isArray(task.output) || task.output.length === 0) throw new EndpointResponseError("HiAPI task succeeded without output");
const urls = task.output.map((item, index) => {
const url = object(item, `HiAPI output ${index + 1}`).url;
- assert(typeof url === "string" && /^https?:\/\//u.test(url), `HiAPI output ${index + 1} has no URL`);
+ if (typeof url !== "string" || !/^https?:\/\//u.test(url)) throw new EndpointResponseError(`HiAPI output ${index + 1} has no URL`);
return url;
});
return { status: "ready", handle: canonicalize({ ...handle, urls }), receipt };
} catch (error) {
- return pollAgainOrFail(error, { handle: context.handle, pollIntervalMs, failure });
+ return retrying(error, context.handle, pollIntervalMs, operationDeadlineAt) ?? failure(error);
}
},
async collect(context) {
@@ -187,7 +214,7 @@ function endpoint(client: HiApiClient, pollIntervalMs: number, maxOperationMs: n
}
return { status: "completed", result: { value: route.packageResult(blobs) }, receipt: { id: handle.taskId } };
} catch (error) {
- return failure(error);
+ return retrying(error, context.handle, pollIntervalMs) ?? failure(error);
}
},
};
@@ -201,10 +228,10 @@ export function createHiApiProvider(options: CreateHiApiProviderOptions = {}) {
}
const client = new HiApiClient(apiBaseUrl(options.baseUrl ?? "https://api.hiapi.ai"), requestTimeoutMs, options.fetch ?? globalThis.fetch);
const asyncEndpoint = endpoint(client, options.pollIntervalMs ?? 10_000, operationTimeoutMs, options.publicAssetUrl);
- return defineEndpointPackage({
- module: hiApiProviderModuleRef, facet: "gateway", instance: options.instance ?? "hiapi.default", pool: options.pool ?? options.instance ?? "hiapi.default",
+ return defineEndpoint({
+ instance: options.instance ?? "hiapi.default", pool: options.pool ?? options.instance ?? "hiapi.default",
pricing: { kind: "page", url: "https://www.hiapi.ai/en/pricing" },
- credentials: { apiKey: options.apiKey ?? credentialRef("os", "hiapi.api-key") },
+ credentials: { apiKey: options.apiKey ?? credentialRef("local", "hiapi.api-key") },
credentialInputs: { apiKey: { label: "HiAPI API key" } },
defaultConcurrency: options.defaultConcurrency ?? 4,
...(options.actionLimits === undefined ? {} : { actionLimits: options.actionLimits }),
diff --git a/packages/provider-hiapi/src/routes.ts b/packages/provider-hiapi/src/routes.ts
index ae65b4e7..38bdf809 100644
--- a/packages/provider-hiapi/src/routes.ts
+++ b/packages/provider-hiapi/src/routes.ts
@@ -4,11 +4,11 @@ import {
generationTypes,
sealGeneratedImageSet,
sealGeneratedVideoSet,
-} from "@hypit/generation";
-import type { GenerationArtifactUrlResolver, GenerationRequest, GenerationWireMapping } from "@hypit/generation";
-import { canonicalize } from "@hypit/protocol";
-import type { BlobRef, CapabilityRef, CanonicalValue, StoredValue, TypeRef } from "@hypit/protocol";
-import type { EndpointRequest, EndpointSupport } from "@hypit/endpoint-kit";
+} from "@hypit/hypit/generation";
+import type { GenerationArtifactUrlResolver, GenerationRequest, GenerationWireMapping } from "@hypit/hypit/generation";
+import { canonicalize } from "@hypit/hypit/protocol";
+import type { BlobRef, CapabilityRef, CanonicalValue, StoredValue, TypeRef } from "@hypit/hypit/protocol";
+import type { EndpointRequest, EndpointSupport } from "@hypit/hypit/endpoint";
import { hiApiMappings } from "./mapping.js";
/** Documented byte limits for inline media on one HiAPI model; an absent kind carries no documented cap. */
diff --git a/packages/provider-hypihub/README.md b/packages/provider-hypihub/README.md
index cb0678fe..606f52d0 100644
--- a/packages/provider-hypihub/README.md
+++ b/packages/provider-hypihub/README.md
@@ -4,6 +4,17 @@ Thin Hypit Runtime Provider for a HypiHub deployment. It is an optional default
paid generation and WhisperX alignment requests. Select it for a chosen HypiHub account, with OAuth
or an API key in the configured Credential Store; other Providers remain ordinary Profile choices.
+The implementation uses only the public `@hypit/hypit/*` Provider APIs. Its one cross-package
+contract is an explicit peer on `@hypit/whisperx`, whose capability identity, request validation and
+wire-response interpretation it implements remotely. Compatible published releases use an ordinary
+SemVer range; the consuming project's npm/pnpm lockfile fixes the installed pair. Hypit performs no
+Provider download, version resolution or Build-time upgrade. The Provider reads its own package
+version for its User-Agent and does not inherit the Hypit Distribution version.
+
+The official Distribution currently obtains this Provider as a default npm dependency because its
+starter Runtime Profile selects HypiHub. The Profile selection and the npm dependency are separate:
+another Distribution may omit it, and a project may install a compatible version explicitly.
+
`doctor` is read-only. If a stored OAuth access token needs refresh, it reports that account access
and refresh validity remain unchecked; it does not rotate credentials or conclude that their Store
is read-only. Authorized execution and pricing reads retain the normal refresh-and-persist path.
@@ -85,9 +96,6 @@ references; the returned job uses the same polling and asset collection lifecycl
account's `/v1/models` establishes availability. The processed video enters ordinary Normalize,
then either semantic alignment for a Script performance or a Visual Clip for independently timed footage.
-[Background Removal](../background-removal/README.md) declares a separate single-image capability.
-This Provider does not currently implement it; select a project Provider for that operation.
-
Runtime Profile example:
```json
@@ -96,7 +104,7 @@ Runtime Profile example:
"dataRoot": ".hypit/runtimes/local",
"credentials": {
"platform": {
- "use": "@hypit/credential-store-platform"
+ "use": "@hypit/credential-store-local"
}
},
"endpoints": {
@@ -219,8 +227,11 @@ admission budgets. Each accepts `concurrency` and `rate: { limit, periodMs }`, s
These limits count lifecycle actions; Provider-specific upload parts and HTTP requests remain inside
those actions. Synchronous speech and transcription retain their ordinary request capacity.
-A submission, polling or collection error ends the local attempt. Known job IDs and credential
-references remain available in Result receipts; a timeout with no ID is recorded as such. A job can
+A submission or collection error ends the local attempt. During polling, transport failures and HTTP
+429/5xx preserve the same job handle and schedule another read; a standard `Retry-After` is honored,
+but the wake time never passes the original `operationTimeoutMs` deadline. Credential, response and
+other non-retryable errors still end the attempt. Known job IDs and credential references remain
+available in Result receipts; a timeout with no ID is recorded as such. A job can
be inspected at `/jobs/<id>` and its generated assets at `/jobs/<id>/assets` on the selected API base.
The next production attempt uses a new Run and Build. Runtime bindings never switch from a user's
own Provider to HypiHub after a key, quota or transport failure.
diff --git a/packages/provider-hypihub/package.json b/packages/provider-hypihub/package.json
index dbbdb191..c21bb8fb 100644
--- a/packages/provider-hypihub/package.json
+++ b/packages/provider-hypihub/package.json
@@ -1,28 +1,34 @@
{
"name": "@hypit/provider-hypihub",
- "version": "0.0.0-dev",
+ "version": "0.1.0",
"license": "SEE LICENSE IN LICENSE",
"private": true,
"type": "module",
"exports": { ".": "./src/index.ts" },
+ "files": ["dist", "README.md"],
"hypit": { "activation": "./src/activation.ts" },
- "dependencies": {
- "@hypit/endpoint-kit": "workspace:*",
+ "peerDependencies": {
+ "@hypit/hypit": "workspace:^",
+ "@hypit/runtime-local": "workspace:^",
+ "@hypit/whisperx": "workspace:^"
+ },
+ "devDependencies": {
+ "@hypit/endpoint": "workspace:*",
"@hypit/generation": "workspace:*",
+ "@hypit/hypit": "workspace:*",
"@hypit/protocol": "workspace:*",
"@hypit/runtime": "workspace:*",
- "@hypit/runtime-kit": "workspace:*",
+ "@hypit/runtime-local": "workspace:*",
"@hypit/speech-evidence": "workspace:*",
"@hypit/text": "workspace:*",
- "@hypit/whisperx": "workspace:*"
- },
- "devDependencies": {
- "@hypit/driver-node": "workspace:*",
+ "@hypit/whisperx": "workspace:*",
+ "@hypit/executor": "workspace:*",
"@hypit/elevenlabs-speech": "workspace:*",
"@hypit/fishaudio-speech": "workspace:*",
"@hypit/mimo-speech": "workspace:*",
"@hypit/seedance": "workspace:*",
- "@hypit/speech": "workspace:*",
- "@hypit/volcengine-matting": "workspace:*"
+ "@hypit/volcengine-matting": "workspace:*",
+ "@hypit/gpt-image": "workspace:*",
+ "typescript": "5.9.3"
}
}
diff --git a/packages/provider-hypihub/src/activation.ts b/packages/provider-hypihub/src/activation.ts
index 6715543f..d9a81737 100644
--- a/packages/provider-hypihub/src/activation.ts
+++ b/packages/provider-hypihub/src/activation.ts
@@ -6,7 +6,7 @@ import {
runtimeConfigObject,
runtimeConfigPositiveInteger,
runtimeConfigString,
-} from "@hypit/runtime-kit";
+} from "@hypit/runtime-local/extension";
import { createHypiHubProvider, diagnoseHypiHubProvider } from "./provider.js";
@@ -84,8 +84,8 @@ const adapter = createRuntimeEndpointAdapterFacet({
});
export const hypitPackage = {
- format: "hypit.node-package@1" as const,
- hostFacets: [adapter],
+ format: "hypit.package@1" as const,
+ facets: [adapter],
};
export default hypitPackage;
diff --git a/packages/provider-hypihub/src/errors.ts b/packages/provider-hypihub/src/errors.ts
index c380447c..e4c10145 100644
--- a/packages/provider-hypihub/src/errors.ts
+++ b/packages/provider-hypihub/src/errors.ts
@@ -1,4 +1,5 @@
-import { EndpointHttpError, EndpointServiceError, retryAfterMs } from "@hypit/endpoint-kit";
+import { EndpointServiceError } from "@hypit/hypit/endpoint";
+import { EndpointHttpError, retryAfterMs } from "@hypit/hypit/endpoint/http";
/** HypiHub's public error envelope, kept at the service boundary. */
function record(value: unknown): Record<string, unknown> | undefined {
diff --git a/packages/provider-hypihub/src/mapping.ts b/packages/provider-hypihub/src/mapping.ts
index 831e0cd8..4b701c9e 100644
--- a/packages/provider-hypihub/src/mapping.ts
+++ b/packages/provider-hypihub/src/mapping.ts
@@ -1,5 +1,5 @@
-import type { CapabilityRef, ModuleRef } from "@hypit/protocol";
-import type { GenerationWireMapping } from "@hypit/generation";
+import type { CapabilityRef, ModuleRef } from "@hypit/hypit/protocol";
+import type { GenerationWireMapping } from "@hypit/hypit/generation";
/** HypiHub model IDs and the normalized request fields they accept. */
const SEEDANCE: ModuleRef = { name: "@hypit/seedance", version: "1" };
diff --git a/packages/provider-hypihub/src/oauth.ts b/packages/provider-hypihub/src/oauth.ts
index 96dddf24..85db4d16 100644
--- a/packages/provider-hypihub/src/oauth.ts
+++ b/packages/provider-hypihub/src/oauth.ts
@@ -1,7 +1,9 @@
-import type { EndpointCredential } from "@hypit/endpoint-kit";
-import { EndpointTransportError, transport } from "@hypit/endpoint-kit";
-import { decodeOAuth2Credential, encodeOAuth2Credential } from "@hypit/runtime";
-import { requestDeadline } from "@hypit/runtime-kit";
+import type { EndpointCredential } from "@hypit/hypit/endpoint";
+import {
+ decodeOAuth2Credential,
+ encodeOAuth2Credential,
+} from "@hypit/hypit/endpoint";
+import { EndpointResponseError, EndpointTransportError, withRequestDeadline } from "@hypit/hypit/endpoint/http";
import { HypiHubHttpError } from "./errors.js";
const OAUTH_CLIENT_ID = "hyc_d5d5e8e7131b0c877756e66c";
@@ -67,9 +69,8 @@ export function createHypiHubAuth(options: {
throw new Error("HypiHub OAuth credential is read-only; run hypit auth login with a writable Credential Store");
}
refreshing = (async () => {
- const deadline = requestDeadline(options.requestTimeoutMs, () => new EndpointTransportError("HypiHub OAuth refresh timed out"));
- try {
- const response = await transport(deadline.wait(options.fetch(tokenEndpoint, {
+ return await withRequestDeadline(options.requestTimeoutMs, async ({ signal, wait }) => {
+ const response = await wait(options.fetch(tokenEndpoint, {
method: "POST",
headers: { "content-type": "application/x-www-form-urlencoded" },
body: new URLSearchParams({
@@ -77,15 +78,15 @@ export function createHypiHubAuth(options: {
refresh_token: refreshToken!,
client_id: OAUTH_CLIENT_ID,
}),
- signal: deadline.signal,
- })));
- const text = await transport(deadline.wait(response.text()));
+ signal,
+ }));
+ const text = await wait(response.text());
if (!response.ok) throw new HypiHubHttpError(response.status, response, text, {
method: "POST", url: tokenEndpoint,
});
let body: OAuthTokenResponse;
try { body = JSON.parse(text) as OAuthTokenResponse; }
- catch { throw new Error(`HypiHub OAuth refresh returned invalid JSON (${response.status})`); }
+ catch { throw new EndpointResponseError(`HypiHub OAuth refresh returned invalid JSON (${response.status})`); }
assert(typeof body.access_token === "string" && body.access_token.length > 0,
"HypiHub OAuth refresh returned no access token");
accessToken = body.access_token;
@@ -102,9 +103,7 @@ export function createHypiHubAuth(options: {
...(expiresAt === undefined ? {} : { expiresAt }),
});
return accessToken;
- } finally {
- deadline.finish();
- }
+ }, () => new EndpointTransportError("HypiHub OAuth refresh timed out", { timeout: true }));
})();
try { return await refreshing; }
finally { refreshing = undefined; }
diff --git a/packages/provider-hypihub/src/provider.ts b/packages/provider-hypihub/src/provider.ts
index fd6183a5..e42946dc 100644
--- a/packages/provider-hypihub/src/provider.ts
+++ b/packages/provider-hypihub/src/provider.ts
@@ -1,14 +1,13 @@
import { readFileSync } from "node:fs";
-import { requestDeadline } from "@hypit/runtime-kit";
-import type { AsyncEndpoint, EndpointCredential, EndpointFulfillment, EndpointInvocationContext, EndpointPollContext, EndpointPricingReader, EndpointStartContext, EndpointOutcome, ImmediateEndpointHandler } from "@hypit/endpoint-kit";
-import { EndpointResponseError, EndpointServiceError, EndpointTransportError, defineEndpointPackage, pollAgainOrFail, transport, wakeAfter } from "@hypit/endpoint-kit";
-import { selectWireModelForRequest } from "@hypit/generation";
-import type { GenerationRequest } from "@hypit/generation";
-import { canonicalize } from "@hypit/protocol";
-import type { BlobRef, CapabilityRef } from "@hypit/protocol";
-import { credentialRef } from "@hypit/runtime";
-import type { CredentialRef, ResourceStore } from "@hypit/runtime";
-import { sealAlignedTranscriptEvidence, speechEvidenceTypes } from "@hypit/speech-evidence";
+import type { RuntimeDoctorDiagnostic } from "@hypit/runtime-local/extension";
+import type { AsyncEndpoint, CredentialRef, EndpointCredential, EndpointFulfillment, EndpointInvocationContext, EndpointPollContext, EndpointPricingReader, EndpointStartContext, EndpointOutcome, ImmediateEndpointHandler, ResourceStore } from "@hypit/hypit/endpoint";
+import { credentialRef, EndpointServiceError, defineEndpoint, wakeAfter } from "@hypit/hypit/endpoint";
+import { EndpointHttpError, EndpointResponseError, EndpointTransportError, withRequestDeadline } from "@hypit/hypit/endpoint/http";
+import { selectWireModelForRequest } from "@hypit/hypit/generation";
+import type { GenerationRequest } from "@hypit/hypit/generation";
+import { canonicalize } from "@hypit/hypit/protocol";
+import type { BlobRef, CanonicalValue, CapabilityRef } from "@hypit/hypit/protocol";
+import { sealAlignedTranscriptEvidence, speechEvidenceTypes } from "@hypit/hypit/speech-evidence";
import {
assertWhisperXEvidenceWav,
interpretWhisperXTranscript,
@@ -19,17 +18,16 @@ import type { WhisperXTranscriptResponse } from "@hypit/whisperx";
import { hypiHubRouteForCapability, hypiHubRoutes } from "./routes.js";
import type { HypiHubModelOperation } from "./routes.js";
import { HypiHubUploader } from "./upload.js";
-import type { RuntimeDoctorDiagnostic } from "@hypit/runtime-kit";
import { createHypiHubAuth, hypiHubCredentialNeedsRefresh } from "./oauth.js";
import type { HypiHubAuth } from "./oauth.js";
import { HypiHubHttpError, HypiHubServiceError, hypiHubJobFailure } from "./errors.js";
-function distributionVersion(): string {
+function providerVersion(): string {
try {
- const manifest = JSON.parse(readFileSync(new URL("../../../package.json", import.meta.url), "utf8")) as {
+ const manifest = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")) as {
readonly name?: unknown; readonly version?: unknown;
};
- if (manifest.name !== "@hypit/hypit" || typeof manifest.version !== "string" || manifest.version.length === 0) {
+ if (manifest.name !== "@hypit/provider-hypihub" || typeof manifest.version !== "string" || manifest.version.length === 0) {
return "unknown";
}
return manifest.version;
@@ -38,7 +36,7 @@ function distributionVersion(): string {
}
}
-const userAgent = `hypit/${distributionVersion()}`;
+const userAgent = `hypit-provider-hypihub/${providerVersion()}`;
const identifiedFetch = (fetcher: typeof globalThis.fetch): typeof globalThis.fetch =>
async (input, init) => {
@@ -55,7 +53,7 @@ export type CreateHypiHubProviderOptions = {
readonly baseUrl?: string;
readonly apiKey?: CredentialRef;
readonly defaultConcurrency?: number;
- readonly actionLimits?: import("@hypit/endpoint-kit").EndpointActionLimits;
+ readonly actionLimits?: import("@hypit/hypit/endpoint").EndpointActionLimits;
readonly capabilityConcurrency?: Readonly<Record<string, number>>;
readonly pollIntervalMs?: number;
readonly requestTimeoutMs?: number;
@@ -90,15 +88,35 @@ function apiBaseUrl(value: string): string {
}
function credential(credentials: Readonly<Record<string, EndpointCredential>>) {
const value = credentials.apiKey?.secret;
- assert(typeof value === "string" && value.length > 0, "HypiHub apiKey credential is unavailable; configure this Endpoint's credential with a HypiHub API key or OAuth login");
+ if (typeof value !== "string" || value.length === 0) {
+ throw new HypiHubServiceError("HYPIHUB_CREDENTIAL_UNAVAILABLE",
+ "HypiHub apiKey credential is unavailable; configure this Endpoint's credential with a HypiHub API key or OAuth login");
+ }
return credentials.apiKey!;
}
function failureMessage(error: unknown): string {
return error instanceof Error ? error.message : String(error);
}
function failure(error: unknown): EndpointOutcome {
- const message = failureMessage(error);
- return { status: "failed", failure: { code: error instanceof EndpointServiceError ? error.code : "HYPIHUB_ERROR", message } };
+ if (!(error instanceof EndpointServiceError || error instanceof EndpointHttpError
+ || error instanceof EndpointTransportError || error instanceof EndpointResponseError)) throw error;
+ const code = error instanceof EndpointServiceError || error instanceof EndpointHttpError ? error.code : "HYPIHUB_ERROR";
+ return { status: "failed", failure: { code, message: failureMessage(error) } };
+}
+
+function retrying(error: unknown, handle: CanonicalValue, pollIntervalMs: number, deadlineAt?: number): EndpointOutcome | undefined {
+ const delay = error instanceof EndpointTransportError ? pollIntervalMs
+ : error instanceof EndpointHttpError && (error.status === 429 || error.status >= 500)
+ ? error.retryAfterMs ?? pollIntervalMs : undefined;
+ if (delay === undefined) return undefined;
+ const now = Date.now();
+ return { status: "pending", handle, wakeAt: Math.min(now + delay, deadlineAt ?? Number.MAX_SAFE_INTEGER), progress: { phase: "retrying" } };
+}
+function unknownSubmission(error: unknown): EndpointOutcome | undefined {
+ return error instanceof EndpointTransportError ? { status: "failed", failure: {
+ code: "HYPIHUB_SUBMISSION_UNKNOWN",
+ message: `HypiHub submission transport failed; remote outcome is unknown: ${error.message}`,
+ } } : undefined;
}
function jobId(value: Record<string, unknown>): string {
@@ -107,13 +125,24 @@ function jobId(value: Record<string, unknown>): string {
return id;
}
-async function verifyModelRoute(client: HypiHubClient, auth: HypiHubAuth, model: string, operation: HypiHubModelOperation): Promise<void> {
- const card = await client.json(`/models/${encodeURIComponent(model)}`, auth);
+async function verifyModelRoute(client: HypiHubClient, auth: HypiHubAuth, model: string, operation: HypiHubModelOperation): Promise<boolean> {
+ let card: Record<string, unknown>;
+ try {
+ card = await client.json(`/models/${encodeURIComponent(model)}`, auth);
+ } catch (error) {
+ if (error instanceof EndpointTransportError
+ || error instanceof EndpointHttpError && (error.status === 429 || error.status >= 500)) return false;
+ throw error;
+ }
const endpoints = card.endpoints;
- assert(Array.isArray(endpoints) && endpoints.every((value) => typeof value === "string"),
- `HypiHub model ${model} returned no valid operation list; support for ${operation} is unknown`);
- assert(endpoints.includes(operation),
- `HypiHub model ${model} does not list operation ${operation}; listed operations: ${endpoints.join(", ") || "none"}`);
+ if (!Array.isArray(endpoints) || !endpoints.every((value) => typeof value === "string")) {
+ throw new EndpointResponseError(`HypiHub model ${model} returned no valid operation list; support for ${operation} is unknown`);
+ }
+ if (!endpoints.includes(operation)) {
+ throw new HypiHubServiceError("HYPIHUB_MODEL_OPERATION_UNAVAILABLE",
+ `HypiHub model ${model} does not list operation ${operation}; listed operations: ${endpoints.join(", ") || "none"}`);
+ }
+ return true;
}
class HypiHubClient {
@@ -150,15 +179,12 @@ class HypiHubClient {
async json(path: string, auth: HypiHubAuth, init: RequestInit = {}, refreshOnUnauthorized = true,
onResponse?: (response: Response) => Promise<void>): Promise<Record<string, unknown>> {
const token = await auth.token();
- const deadline = requestDeadline(this.timeout, () => new EndpointTransportError("HypiHub request timed out"));
- try {
- const response = await transport(deadline.wait(this.fetcher(`${this.baseUrl}${path}`, { ...init, signal: deadline.signal, headers: { authorization: `Bearer ${token}`, ...(init.headers ?? {}) } })));
- if (response.status !== 401 && onResponse !== undefined) await deadline.wait(onResponse(response));
- const text = await transport(deadline.wait(response.text())); let body: unknown = {};
+ const result = await withRequestDeadline(this.timeout, async ({ signal, wait }) => {
+ const response = await wait(this.fetcher(`${this.baseUrl}${path}`, { ...init, signal, headers: { authorization: `Bearer ${token}`, ...(init.headers ?? {}) } }));
+ if (response.status !== 401 && onResponse !== undefined) await wait(onResponse(response));
+ const text = await wait(response.text()); let body: unknown = {};
if (response.status === 401 && refreshOnUnauthorized && auth.canRefresh()) {
- deadline.finish();
- await auth.refresh();
- return await this.json(path, auth, init, false, onResponse);
+ return undefined;
}
if (!response.ok) {
const input = typeof init.body === "string" ? JSON.parse(init.body) as Record<string, unknown> : undefined;
@@ -169,20 +195,22 @@ class HypiHubClient {
}
try { body = text.length === 0 ? {} : JSON.parse(text); } catch { throw new EndpointResponseError(`HypiHub returned invalid JSON (${response.status})`); }
return object(body, "HypiHub response");
- } finally { deadline.finish(); }
+ }, () => new EndpointTransportError("HypiHub request timed out", { timeout: true }));
+ if (result !== undefined) return result;
+ await auth.refresh();
+ return await this.json(path, auth, init, false, onResponse);
}
async download(url: string): Promise<{ readonly bytes: Uint8Array; readonly mediaType: string }> {
let lastError: unknown;
for (let attempt = 0; attempt < this.downloadAttempts; attempt += 1) {
- const deadline = requestDeadline(this.timeout);
try {
- const response = await deadline.wait(this.fetcher(url, { signal: deadline.signal }));
- if (!response.ok) throw new Error(`HypiHub asset returned HTTP ${response.status}`);
- return { bytes: new Uint8Array(await deadline.wait(response.arrayBuffer())), mediaType: response.headers.get("content-type")?.split(";", 1)[0] ?? "application/octet-stream" };
+ return await withRequestDeadline(this.timeout, async ({ signal, wait }) => {
+ const response = await wait(this.fetcher(url, { signal }));
+ if (!response.ok) throw new HypiHubHttpError(response.status, response, "", { method: "GET", url });
+ return { bytes: new Uint8Array(await wait(response.arrayBuffer())), mediaType: response.headers.get("content-type")?.split(";", 1)[0] ?? "application/octet-stream" };
+ });
} catch (error) {
lastError = error;
- } finally {
- deadline.finish();
}
}
throw lastError instanceof Error ? lastError : new Error(String(lastError));
@@ -220,19 +248,16 @@ class HypiHubClient {
}
async speech(auth: HypiHubAuth, body: Record<string, unknown>, refreshOnUnauthorized = true): Promise<readonly { readonly bytes: Uint8Array; readonly mediaType: string }[]> {
const token = await auth.token();
- const deadline = requestDeadline(this.timeout);
- try {
- const response = await deadline.wait(this.fetcher(`${this.baseUrl}/audio/speech`, {
+ const result = await withRequestDeadline(this.timeout, async ({ signal, wait }) => {
+ const response = await wait(this.fetcher(`${this.baseUrl}/audio/speech`, {
method: "POST",
headers: { authorization: `Bearer ${token}`, "content-type": "application/json" },
body: JSON.stringify({ ...body, output: "b64_json" }),
- signal: deadline.signal,
+ signal,
}));
- const bytes = new Uint8Array(await deadline.wait(response.arrayBuffer()));
+ const bytes = new Uint8Array(await wait(response.arrayBuffer()));
if (response.status === 401 && refreshOnUnauthorized && auth.canRefresh()) {
- deadline.finish();
- await auth.refresh();
- return await this.speech(auth, body, false);
+ return undefined;
}
if (!response.ok) {
throw new HypiHubHttpError(response.status, response, Buffer.from(bytes).toString("utf8"), {
@@ -267,9 +292,10 @@ class HypiHubClient {
`HypiHub audio response ${index + 1} contains neither audio bytes nor a URL`);
return await this.download(item.url);
}));
- } finally {
- deadline.finish();
- }
+ });
+ if (result !== undefined) return result;
+ await auth.refresh();
+ return await this.speech(auth, body, false);
}
}
@@ -291,7 +317,7 @@ function pricingAuth(credentials: Readonly<Record<string, EndpointCredential>>,
});
}
-function pricingModel(request: import("@hypit/endpoint-kit").EndpointRequest, transcriptionModel: string): string | undefined {
+function pricingModel(request: import("@hypit/hypit/endpoint").EndpointRequest, transcriptionModel: string): string | undefined {
if (capabilityKey(request.capability) === capabilityKey(whisperXCapabilities.alignment)) {
return transcriptionModel;
}
@@ -424,11 +450,9 @@ async function prepareGeneration(client: HypiHubClient, context: EndpointInvocat
const request = route.prepare(context.need.constraints);
const auth = authFor(context, client);
await context.reportProgress?.({ phase: `Reading HypiHub model catalogue: ${request.model} (${request.operation})` });
- try {
- await verifyModelRoute(client, auth, request.model, request.operation);
- } catch (error) {
- throw new HypiHubServiceError(error instanceof EndpointServiceError ? error.code : "HYPIHUB_ERROR",
- `HypiHub model catalogue check failed; model=${request.model}; operation=${request.operation}; references uploaded=0; generation not submitted: ${failureMessage(error)}`);
+ if (!await verifyModelRoute(client, auth, request.model, request.operation)) {
+ await context.reportDiagnostic?.({ level: "warning",
+ message: `HypiHub model catalogue is temporarily unavailable for ${request.model}; proceeding without a support verdict` });
}
await context.reportProgress?.({ phase: `Preparing HypiHub request: ${request.model} (${request.operation})` });
const uploaded = new Map<string, Promise<string>>();
@@ -442,13 +466,7 @@ async function prepareGeneration(client: HypiHubClient, context: EndpointInvocat
uploaded.set(key, promise);
return promise;
};
- let compiled;
- try {
- compiled = await request.compile(resolve);
- } catch (error) {
- throw new HypiHubServiceError(error instanceof EndpointServiceError ? error.code : "HYPIHUB_ERROR",
- `HypiHub request preparation failed; model=${request.model}; operation=${request.operation}; generation not submitted: ${failureMessage(error)}`);
- }
+ const compiled = await request.compile(resolve);
return { route, auth, compiled, operation: request.operation };
}
@@ -471,7 +489,14 @@ function endpoint(client: HypiHubClient, pollIntervalMs: number, maxOperationMs:
const path = operation === "image_edits" ? "/images/edits"
: operation === "images" ? "/images/generations" : "/videos";
await context.reportProgress?.({ phase: `Submitting HypiHub request: ${compiled.model} (${operation})` });
- const response = await client.json(path, auth, { method: "POST", headers: { "content-type": "application/json", "idempotency-key": context.operation }, body: JSON.stringify({ model: compiled.model, ...input }) });
+ let response: Record<string, unknown>;
+ try {
+ response = await client.json(path, auth, { method: "POST", headers: { "content-type": "application/json", "idempotency-key": context.operation }, body: JSON.stringify({ model: compiled.model, ...input }) });
+ } catch (error) {
+ const unknown = unknownSubmission(error);
+ if (unknown !== undefined) return unknown;
+ throw error;
+ }
const status = response.status;
const remoteEnded = status === "succeeded" || status === "completed";
const handle: Handle = { contract: "hypit.hypihub-operation@1", jobId: jobId(response), route: capabilityKey(route.capability), startedAt: Date.now() };
@@ -486,10 +511,12 @@ function endpoint(client: HypiHubClient, pollIntervalMs: number, maxOperationMs:
}
},
async poll(context: EndpointPollContext) {
+ let operationDeadlineAt: number | undefined;
try {
const handle = object(context.handle, "HypiHub handle") as unknown as Handle; const route = hypiHubRouteForCapability(context.need.capability);
assert(route !== undefined && handle.contract === "hypit.hypihub-operation@1" && handle.route === capabilityKey(route.capability), "HypiHub handle is invalid");
- if (Date.now() - handle.startedAt > maxOperationMs) {
+ operationDeadlineAt = handle.startedAt + maxOperationMs;
+ if (Date.now() >= operationDeadlineAt) {
return { status: "failed",
receipt: { id: handle.jobId },
failure: { code: "HYPIHUB_OPERATION_TIMEOUT", message: `HypiHub job ${handle.jobId} exceeded this Provider's operationTimeoutMs (${maxOperationMs}); remote outcome is unknown` } };
@@ -501,7 +528,7 @@ function endpoint(client: HypiHubClient, pollIntervalMs: number, maxOperationMs:
if (status !== "succeeded" && status !== "completed") throw new Error(`HypiHub returned unknown job status ${String(status)}`);
return { status: "ready", handle: context.handle, receipt: { id: handle.jobId } };
} catch (error) {
- return pollAgainOrFail(error, { handle: context.handle, pollIntervalMs, failure });
+ return retrying(error, context.handle, pollIntervalMs, operationDeadlineAt) ?? failure(error);
}
},
async collect(context) {
@@ -510,7 +537,7 @@ function endpoint(client: HypiHubClient, pollIntervalMs: number, maxOperationMs:
const route = hypiHubRouteForCapability(context.need.capability);
assert(route !== undefined && handle.route === capabilityKey(route.capability), "HypiHub collection route differs");
return await complete(client, authFor(context, client), route, handle.jobId, context.resources);
- } catch (error) { return failure(error); }
+ } catch (error) { return retrying(error, context.handle, pollIntervalMs) ?? failure(error); }
},
};
@@ -574,7 +601,10 @@ export function createHypiHubProvider(options: CreateHypiHubProviderOptions = {}
`WhisperX evidence Resource ${request.audio.resource} is unavailable or has changed`);
assertWhisperXEvidenceWav(bytes, request.sampleFrames);
const auth = authFor(context, client);
- await verifyModelRoute(client, auth, transcriptionModel, "transcriptions");
+ if (!await verifyModelRoute(client, auth, transcriptionModel, "transcriptions")) {
+ await context.reportDiagnostic?.({ level: "warning",
+ message: `HypiHub model catalogue is temporarily unavailable for ${transcriptionModel}; proceeding without a support verdict` });
+ }
await context.reportProgress?.({ phase: "Preparing audio for hosted transcription" });
const url = options.publicAssetUrl === undefined
? await client.upload(request.audio, context.resources, auth)
@@ -599,11 +629,11 @@ export function createHypiHubProvider(options: CreateHypiHubProviderOptions = {}
}
};
const oauthOrigin = new URL(options.baseUrl ?? "https://hypit.ai").origin;
- return defineEndpointPackage({
- module: hypiHubProviderModuleRef, facet: "gateway", instance: options.instance ?? "hypihub.default", pool: options.pool ?? options.instance ?? "hypihub.default",
+ return defineEndpoint({
+ instance: options.instance ?? "hypihub.default", pool: options.pool ?? options.instance ?? "hypihub.default",
pricing: { kind: "page", url: "https://hypit.ai/commercial/pricing/" },
readPricing: hypiHubPricingReader(pricingClient, transcriptionModel),
- credentials: { apiKey: options.apiKey ?? credentialRef("os", "hypihub.oauth") },
+ credentials: { apiKey: options.apiKey ?? credentialRef("local", "hypihub.oauth") },
credentialInputs: { apiKey: {
label: "HypiHub credential",
acquisition: {
diff --git a/packages/provider-hypihub/src/routes.ts b/packages/provider-hypihub/src/routes.ts
index de2d7ce2..ac457f52 100644
--- a/packages/provider-hypihub/src/routes.ts
+++ b/packages/provider-hypihub/src/routes.ts
@@ -5,11 +5,11 @@ import {
sealGeneratedAudioSet,
sealGeneratedImageSet,
sealGeneratedVideoSet,
-} from "@hypit/generation";
-import type { GenerationArtifactUrlResolver, GenerationRequest, GenerationWireMapping } from "@hypit/generation";
-import { canonicalize } from "@hypit/protocol";
-import type { BlobRef, CapabilityRef, CanonicalValue, StoredValue, TypeRef } from "@hypit/protocol";
-import type { EndpointRequest, EndpointSupport } from "@hypit/endpoint-kit";
+} from "@hypit/hypit/generation";
+import type { GenerationArtifactUrlResolver, GenerationRequest, GenerationWireMapping } from "@hypit/hypit/generation";
+import { canonicalize } from "@hypit/hypit/protocol";
+import type { BlobRef, CapabilityRef, CanonicalValue, StoredValue, TypeRef } from "@hypit/hypit/protocol";
+import type { EndpointRequest, EndpointSupport } from "@hypit/hypit/endpoint";
import { hypiHubMappings } from "./mapping.js";
export type HypiHubModelOperation = "images" | "image_edits" | "videos" | "audio_speech" | "transcriptions";
diff --git a/packages/provider-hypihub/src/upload.ts b/packages/provider-hypihub/src/upload.ts
index da117656..8d221388 100644
--- a/packages/provider-hypihub/src/upload.ts
+++ b/packages/provider-hypihub/src/upload.ts
@@ -1,9 +1,9 @@
-import { EndpointServiceError } from "@hypit/endpoint-kit";
-import { requestDeadline } from "@hypit/runtime-kit";
+import { EndpointServiceError } from "@hypit/hypit/endpoint";
+import { EndpointResponseError, withRequestDeadline } from "@hypit/hypit/endpoint/http";
import { createHash } from "node:crypto";
import type { HypiHubAuth } from "./oauth.js";
-import { HypiHubHttpError, safeHypiHubReason } from "./errors.js";
+import { HypiHubHttpError, HypiHubServiceError, safeHypiHubReason } from "./errors.js";
type UploadAuth = HypiHubAuth | string;
@@ -176,24 +176,21 @@ export class HypiHubUploader {
private async jsonOnce(path: string, auth: UploadAuth, init: RequestInit, timeoutMs: number, retryAuth = true): Promise<Record<string, unknown>> {
const token = await uploadToken(auth);
- const request = requestDeadline(timeoutMs);
const deadline = Date.now() + timeoutMs;
- try {
- const response = await request.wait(this.fetcher(`${this.baseUrl}${path}`, {
+ const result = await withRequestDeadline(timeoutMs, async ({ signal, wait }) => {
+ const response = await wait(this.fetcher(`${this.baseUrl}${path}`, {
...init,
- signal: request.signal,
+ signal,
headers: { authorization: `Bearer ${token}`, ...(init.headers ?? {}) },
}));
- const text = await request.wait(response.text());
+ const text = await wait(response.text());
if (response.status === 401 && retryAuth && uploadCanRefresh(auth)) {
- request.finish();
- await (auth as HypiHubAuth).refresh();
- return await this.jsonOnce(path, auth, init, Math.max(1, deadline - Date.now()), false);
+ return undefined;
}
let body: unknown = {};
try { body = text.length === 0 ? {} : JSON.parse(text); }
catch {
- if (response.ok) throw new Error(`HypiHub returned invalid JSON (${response.status})`);
+ if (response.ok) throw new EndpointResponseError(`HypiHub returned invalid JSON (${response.status})`);
}
if (!response.ok) {
throw new HypiHubHttpError(response.status, response, text, {
@@ -201,9 +198,10 @@ export class HypiHubUploader {
});
}
return object(body, "HypiHub response");
- } finally {
- request.finish();
- }
+ });
+ if (result !== undefined) return result;
+ await (auth as HypiHubAuth).refresh();
+ return await this.jsonOnce(path, auth, init, Math.max(1, deadline - Date.now()), false);
}
private async signParts(uploadId: string, declarations: readonly PartDeclaration[], auth: UploadAuth): Promise<Map<number, Record<string, unknown>>> {
@@ -259,40 +257,39 @@ export class HypiHubUploader {
const refreshed = await this.signParts(uploadId, [declaration], auth);
capability = refreshed.get(declaration.part_number) ?? {};
}
- const request = requestDeadline(this.uploadPartTimeout);
const startedAt = Date.now();
this.log(`part upload started upload=${uploadId} part=${declaration.part_number} bytes=${declaration.bytes} attempt=${attempt + 1}`);
try {
- const url = requiredString(capability.url, "HypiHub signed upload URL");
- assertHTTPS(url, "HypiHub signed upload URL");
- const payload = new ArrayBuffer(body.byteLength);
- new Uint8Array(payload).set(body);
- const response = await request.wait(this.fetcher(url, {
- method: "PUT",
- headers: this.signedHeaders(capability.headers, declaration),
- body: payload,
- signal: request.signal,
- }));
- if (!response.ok) throw new Error(`S3 rejected upload part ${declaration.part_number} with HTTP ${response.status}`);
- const etag = response.headers.get("etag");
- assert(etag !== null && etag.length > 0, `S3 upload part ${declaration.part_number} returned no ETag`);
- const verified = response.headers.get("x-amz-checksum-sha256");
- assert(verified === null || verified === declaration.checksum_sha256,
- `S3 upload part ${declaration.part_number} returned a different checksum`);
- this.log(`part upload completed upload=${uploadId} part=${declaration.part_number} bytes=${declaration.bytes} attempt=${attempt + 1} elapsed=${this.elapsed(startedAt)}`);
- return {
- part_number: declaration.part_number,
- etag,
- checksum_sha256: declaration.checksum_sha256,
- };
+ return await withRequestDeadline(this.uploadPartTimeout, async ({ signal, wait }) => {
+ const url = requiredString(capability.url, "HypiHub signed upload URL");
+ assertHTTPS(url, "HypiHub signed upload URL");
+ const payload = new ArrayBuffer(body.byteLength);
+ new Uint8Array(payload).set(body);
+ const response = await wait(this.fetcher(url, {
+ method: "PUT",
+ headers: this.signedHeaders(capability.headers, declaration),
+ body: payload,
+ signal,
+ }));
+ if (!response.ok) throw new Error(`S3 rejected upload part ${declaration.part_number} with HTTP ${response.status}`);
+ const etag = response.headers.get("etag");
+ assert(etag !== null && etag.length > 0, `S3 upload part ${declaration.part_number} returned no ETag`);
+ const verified = response.headers.get("x-amz-checksum-sha256");
+ assert(verified === null || verified === declaration.checksum_sha256,
+ `S3 upload part ${declaration.part_number} returned a different checksum`);
+ this.log(`part upload completed upload=${uploadId} part=${declaration.part_number} bytes=${declaration.bytes} attempt=${attempt + 1} elapsed=${this.elapsed(startedAt)}`);
+ return {
+ part_number: declaration.part_number,
+ etag,
+ checksum_sha256: declaration.checksum_sha256,
+ };
+ });
} catch (error) {
this.log(`part upload failed upload=${uploadId} part=${declaration.part_number} attempt=${attempt + 1} elapsed=${this.elapsed(startedAt)} reason=${this.safeReason(error)}`);
if (attempt + 1 < this.uploadPartAttempts) {
this.log(`part upload retry scheduled upload=${uploadId} part=${declaration.part_number} next_attempt=${attempt + 2}`);
await new Promise((resolve) => setTimeout(resolve, 500 * (attempt + 1)));
}
- } finally {
- request.finish();
}
}
// A presigned URL is a temporary credential, so never include the fetcher's URL-bearing error.
@@ -361,7 +358,10 @@ export class HypiHubUploader {
this.log(`upload cancellation still pending upload=${uploadId} reason=${this.safeReason(cancelError)}`);
}
}
- throw error instanceof EndpointServiceError ? error : new Error(this.safeReason(error));
+ throw error instanceof EndpointServiceError || error instanceof HypiHubHttpError
+ ? error
+ : new HypiHubServiceError("HYPIHUB_UPLOAD_FAILED",
+ `HypiHub reference upload failed before generation submission: ${this.safeReason(error)}`);
}
}
diff --git a/packages/provider-hypihub/test/oauth.test.ts b/packages/provider-hypihub/test/oauth.test.ts
index ae88a528..b833a9a8 100644
--- a/packages/provider-hypihub/test/oauth.test.ts
+++ b/packages/provider-hypihub/test/oauth.test.ts
@@ -1,7 +1,7 @@
import assert from "node:assert/strict";
import test from "node:test";
-import type { EndpointCredential } from "@hypit/endpoint-kit";
+import type { EndpointCredential } from "@hypit/endpoint";
import { decodeOAuth2Credential, encodeOAuth2Credential } from "@hypit/runtime";
import { createHypiHubAuth } from "../src/oauth.js";
diff --git a/packages/provider-hypihub/test/provider.test.ts b/packages/provider-hypihub/test/provider.test.ts
index 4e49a91d..8ce61580 100644
--- a/packages/provider-hypihub/test/provider.test.ts
+++ b/packages/provider-hypihub/test/provider.test.ts
@@ -2,9 +2,9 @@ import assert from "node:assert/strict";
import test from "node:test";
import { encodeOAuth2Credential } from "@hypit/runtime";
-import { EndpointRegistry, MemoryResourceStore } from "@hypit/driver-node";
-import { defineEndpointPackage } from "@hypit/endpoint-kit";
-import type { AsyncEndpoint } from "@hypit/endpoint-kit";
+import { EndpointRegistry, MemoryResourceStore } from "@hypit/executor";
+import { defineEndpoint } from "@hypit/endpoint";
+import type { AsyncEndpoint } from "@hypit/endpoint";
import type { CanonicalValue, Need } from "@hypit/protocol";
import { mimoSpeechEndpoints, sealMimoSpeechRequest } from "@hypit/mimo-speech";
import { fishAudioSpeechEndpoints, sealFishAudioSpeechRequest } from "@hypit/fishaudio-speech";
@@ -238,6 +238,8 @@ test("HypiHub returns its current model-pricing document", async () => {
fetch: async (input, init) => {
assert.equal(String(input), "https://hypit.ai/v1/pricing?model=seedance-2");
assert.equal((init?.headers as Record<string, string>).authorization, "Bearer test-key");
+ assert.equal((init?.headers as Record<string, string>)["user-agent"],
+ "hypit-provider-hypihub/0.1.0");
return Response.json({
object: "model_pricing",
model: "seedance-2",
@@ -363,9 +365,7 @@ test("HypiHub declares both MiMo speech capabilities; who serves them is the Pro
assert.ok(needs.every((item) => registry.resolve(item).status === "resolved"));
// A second Endpoint offering the same capability makes the choice the deployment's, not the Provider's.
- const other = defineEndpointPackage({
- module: { name: "example.tts", version: "1" },
- facet: "tts",
+ const other = defineEndpoint({
instance: "mimo.official",
pool: "mimo.official",
capabilities: [{
@@ -673,7 +673,7 @@ test("HypiHub stops before paid submission when a reference upload fails", async
assert.equal(uploadAttempts, 2);
assert.equal(cancelled, true);
assert.equal(paidSubmissions, 0);
- assert.match(outcome.status === "failed" ? outcome.failure.message : "", /request preparation failed.*generation not submitted/u);
+ assert.match(outcome.status === "failed" ? outcome.failure.message : "", /reference upload failed before generation submission/u);
assert.doesNotMatch(outcome.status === "failed" ? outcome.failure.message : "", /must-not-leak/u);
});
@@ -947,26 +947,22 @@ test("generation and voice cloning check their exact catalogue operation before
try { await selected.registration.handler(context); }
catch (error) { failed = error as Error & { code?: string }; }
}
- if (availability === "available") {
+ if (availability === "available" || availability === "unknown") {
assert.equal(failed, undefined);
assert.deepEqual(events, item.references ? ["catalogue", "reference", "submit"] : ["catalogue", "submit"]);
assert.match(progress.at(-1)!, /Submitting HypiHub request/u);
} else {
assert.ok(failed);
assert.deepEqual(events, ["catalogue"], "neither a reference nor another model is tried");
- assert.match(failed.message, /model catalogue check failed.*references uploaded=0; generation not submitted/u);
- assert.ok(failed.message.includes(`model=${item.model}; operation=${item.operation}`));
if (availability === "missing") {
assert.equal(failed.code, "model_not_found");
assert.match(failed.message, /HTTP 404.*request=catalogue-request.*No route for this account/u);
} else if (availability === "different-operation") {
+ assert.equal(failed.code, "HYPIHUB_MODEL_OPERATION_UNAVAILABLE");
assert.match(failed.message, /does not list operation.*listed operations: transcriptions/u);
} else if (availability === "undeclared") {
assert.match(failed.message, /returned no valid operation list.*is unknown/u);
assert.doesNotMatch(failed.message, /does not list operation|model_not_found/u);
- } else {
- assert.match(failed.message, /Connection closed before catalogue response/u);
- assert.doesNotMatch(failed.message, /model_not_found/u);
}
assert.equal(progress.length, 1);
assert.match(progress[0]!, /Reading HypiHub model catalogue/u);
diff --git a/packages/provider-hypihub/test/routes.test.ts b/packages/provider-hypihub/test/routes.test.ts
index 991a92f0..34be9fba 100644
--- a/packages/provider-hypihub/test/routes.test.ts
+++ b/packages/provider-hypihub/test/routes.test.ts
@@ -1,7 +1,7 @@
import assert from "node:assert/strict";
import test from "node:test";
import type { GenerationArtifactUrlResolver } from "@hypit/generation";
-import type { EndpointSupport } from "@hypit/endpoint-kit";
+import type { EndpointSupport } from "@hypit/endpoint";
import type { BlobRef, CanonicalValue } from "@hypit/protocol";
import { hypiHubRoutes } from "../src/routes.js";
diff --git a/packages/provider-monid/README.md b/packages/provider-monid/README.md
index 7b5abcb3..d9785420 100644
--- a/packages/provider-monid/README.md
+++ b/packages/provider-monid/README.md
@@ -65,8 +65,8 @@ Runtime Profile example:
"format": "hypit.runtime-local@1",
"dataRoot": ".hypit/runtimes/local",
"credentials": {
- "platform": {
- "use": "@hypit/credential-store-platform"
+ "local": {
+ "use": "@hypit/credential-store-local"
}
},
"endpoints": {
@@ -74,7 +74,7 @@ Runtime Profile example:
"use": "@hypit/provider-monid",
"pool": "monid.default",
"config": {
- "apiKey": { "store": "platform", "key": "monid.api-key" },
+ "apiKey": { "store": "local", "key": "monid.api-key" },
"defaultConcurrency": 3,
"pollIntervalMs": 10000
}
@@ -88,3 +88,5 @@ Runtime Profile example:
`hypit auth login monid.default --runtime hypit.runtime.json`. Optional `requestTimeoutMs`,
`operationTimeoutMs` and `actionLimits` bound single HTTP calls, the whole remote run and action
concurrency; file-system runs poll at most every five seconds within `requestTimeoutMs`.
+Polling transport failures and HTTP 429/5xx preserve the same run and honor standard `Retry-After`;
+the scheduled wake never passes the original operation deadline. Other errors end the local attempt.
diff --git a/packages/provider-monid/package.json b/packages/provider-monid/package.json
index 482cec17..7178db33 100644
--- a/packages/provider-monid/package.json
+++ b/packages/provider-monid/package.json
@@ -5,17 +5,21 @@
"private": true,
"type": "module",
"exports": { ".": "./src/index.ts" },
+ "files": ["dist", "README.md"],
"hypit": { "activation": "./src/activation.ts" },
- "dependencies": {
- "@hypit/endpoint-kit": "workspace:*",
+ "peerDependencies": {
+ "@hypit/hypit": "workspace:^",
+ "@hypit/runtime-local": "workspace:^"
+ },
+ "devDependencies": {
+ "@hypit/endpoint": "workspace:*",
"@hypit/generation": "workspace:*",
+ "@hypit/hypit": "workspace:*",
"@hypit/minimax-h3": "workspace:*",
"@hypit/protocol": "workspace:*",
"@hypit/runtime": "workspace:*",
- "@hypit/runtime-kit": "workspace:*",
- "@hypit/wan": "workspace:*"
- },
- "devDependencies": {
+ "@hypit/runtime-local": "workspace:*",
+ "@hypit/wan": "workspace:*",
"@hypit/seedance": "workspace:*"
}
}
diff --git a/packages/provider-monid/src/activation.ts b/packages/provider-monid/src/activation.ts
index 185133a6..6a3112bf 100644
--- a/packages/provider-monid/src/activation.ts
+++ b/packages/provider-monid/src/activation.ts
@@ -6,7 +6,7 @@ import {
runtimeConfigObject,
runtimeConfigPositiveInteger,
runtimeConfigString,
-} from "@hypit/runtime-kit";
+} from "@hypit/runtime-local/extension";
import { createMonidProvider } from "./provider.js";
@@ -55,8 +55,8 @@ const adapter = createRuntimeEndpointAdapterFacet({
});
export const hypitPackage = {
- format: "hypit.node-package@1" as const,
- hostFacets: [adapter],
+ format: "hypit.package@1" as const,
+ facets: [adapter],
};
export default hypitPackage;
diff --git a/packages/provider-monid/src/errors.ts b/packages/provider-monid/src/errors.ts
index f819f28c..e9ff81a1 100644
--- a/packages/provider-monid/src/errors.ts
+++ b/packages/provider-monid/src/errors.ts
@@ -1,4 +1,5 @@
-import { EndpointHttpError, EndpointServiceError } from "@hypit/endpoint-kit";
+import { EndpointServiceError } from "@hypit/hypit/endpoint";
+import { EndpointHttpError, retryAfterMs } from "@hypit/hypit/endpoint/http";
/** Monid's `{ code, message }` error envelope and run outcome fields, kept at the service boundary. */
function record(value: unknown): Record<string, unknown> | undefined {
@@ -27,7 +28,8 @@ export class MonidHttpError extends EndpointHttpError {
`Monid HTTP ${status}`, `${request.method} ${request.path}`,
...(requestId === undefined ? [] : [`request=${requestId}`]),
];
- super("MONID_HTTP_ERROR", `${facts.join("; ")}${reason === undefined ? "" : `: ${safeMonidReason(reason)}`}`, status);
+ super("MONID_HTTP_ERROR", `${facts.join("; ")}${reason === undefined ? "" : `: ${safeMonidReason(reason)}`}`,
+ status, retryAfterMs(response.headers));
}
}
diff --git a/packages/provider-monid/src/mapping.ts b/packages/provider-monid/src/mapping.ts
index a1649587..fc2cb194 100644
--- a/packages/provider-monid/src/mapping.ts
+++ b/packages/provider-monid/src/mapping.ts
@@ -1,5 +1,5 @@
-import type { ModuleRef } from "@hypit/protocol";
-import type { GenerationWireMapping } from "@hypit/generation";
+import type { ModuleRef } from "@hypit/hypit/protocol";
+import type { GenerationWireMapping } from "@hypit/hypit/generation";
const SEEDANCE: ModuleRef = { name: "@hypit/seedance", version: "1" };
const MINIMAX_H3: ModuleRef = { name: "@hypit/minimax-h3", version: "1" };
diff --git a/packages/provider-monid/src/provider.ts b/packages/provider-monid/src/provider.ts
index ed789933..43725c98 100644
--- a/packages/provider-monid/src/provider.ts
+++ b/packages/provider-monid/src/provider.ts
@@ -1,11 +1,11 @@
-import { requestDeadline } from "@hypit/runtime-kit";
-import type { AsyncEndpoint, EndpointCredential, EndpointInvocationContext, EndpointOutcome } from "@hypit/endpoint-kit";
-import { EndpointResponseError, EndpointServiceError, EndpointTransportError, defineEndpointPackage, pollAgainOrFail, transport, wakeAfter } from "@hypit/endpoint-kit";
-import type { GenerationArtifactUrlResolver } from "@hypit/generation";
-import { canonicalize } from "@hypit/protocol";
-import type { BlobRef, CapabilityRef } from "@hypit/protocol";
-import { credentialRef } from "@hypit/runtime";
-import type { CredentialRef, ResourceStore } from "@hypit/runtime";
+import type { AsyncEndpoint, EndpointCredential, EndpointInvocationContext, EndpointOutcome } from "@hypit/hypit/endpoint";
+import { EndpointServiceError, defineEndpoint, wakeAfter } from "@hypit/hypit/endpoint";
+import { EndpointHttpError, EndpointResponseError, EndpointTransportError, withRequestDeadline } from "@hypit/hypit/endpoint/http";
+import type { GenerationArtifactUrlResolver } from "@hypit/hypit/generation";
+import { canonicalize } from "@hypit/hypit/protocol";
+import type { BlobRef, CanonicalValue, CapabilityRef } from "@hypit/hypit/protocol";
+import { credentialRef } from "@hypit/hypit/endpoint";
+import type { CredentialRef, ResourceStore } from "@hypit/hypit/endpoint";
import { monidRouteForCapability, monidRoutes } from "./routes.js";
import { MonidHttpError, MonidServiceError, monidRunFailure, monidTerminalStatuses } from "./errors.js";
@@ -17,7 +17,7 @@ export type CreateMonidProviderOptions = {
readonly baseUrl?: string;
readonly apiKey?: CredentialRef;
readonly defaultConcurrency?: number;
- readonly actionLimits?: import("@hypit/endpoint-kit").EndpointActionLimits;
+ readonly actionLimits?: import("@hypit/hypit/endpoint").EndpointActionLimits;
readonly pollIntervalMs?: number;
readonly requestTimeoutMs?: number;
readonly operationTimeoutMs?: number;
@@ -48,17 +48,37 @@ function apiBaseUrl(value: string): string {
}
function apiKey(credentials: Readonly<Record<string, EndpointCredential>>): string {
const value = credentials.apiKey?.secret;
- assert(typeof value === "string" && value.length > 0, "Monid apiKey credential is unavailable; store a Monid API key for this Endpoint");
+ if (typeof value !== "string" || value.length === 0) {
+ throw new MonidServiceError("MONID_CREDENTIAL_UNAVAILABLE",
+ "Monid apiKey credential is unavailable; store a Monid API key for this Endpoint");
+ }
return value;
}
function failureMessage(error: unknown): string {
return error instanceof Error ? error.message : String(error);
}
function failure(error: unknown): EndpointOutcome {
- return { status: "failed", failure: { code: error instanceof EndpointServiceError ? error.code : "MONID_ERROR", message: failureMessage(error) } };
+ if (!(error instanceof EndpointServiceError || error instanceof EndpointHttpError
+ || error instanceof EndpointTransportError || error instanceof EndpointResponseError)) throw error;
+ const code = error instanceof EndpointServiceError || error instanceof EndpointHttpError ? error.code : "MONID_ERROR";
+ return { status: "failed", failure: { code, message: failureMessage(error) } };
+}
+function retrying(error: unknown, handle: CanonicalValue, pollIntervalMs: number, deadlineAt?: number): EndpointOutcome | undefined {
+ const delay = error instanceof EndpointTransportError ? pollIntervalMs
+ : error instanceof EndpointHttpError && (error.status === 429 || error.status >= 500)
+ ? error.retryAfterMs ?? pollIntervalMs : undefined;
+ if (delay === undefined) return undefined;
+ const now = Date.now();
+ return { status: "pending", handle, wakeAt: Math.min(now + delay, deadlineAt ?? Number.MAX_SAFE_INTEGER), progress: { phase: "retrying" } };
+}
+function unknownSubmission(error: unknown): EndpointOutcome | undefined {
+ return error instanceof EndpointTransportError ? { status: "failed", failure: {
+ code: "MONID_SUBMISSION_UNKNOWN",
+ message: `Monid submission transport failed; remote outcome is unknown: ${error.message}`,
+ } } : undefined;
}
function runId(run: Record<string, unknown>): string {
- assert(typeof run.runId === "string" && run.runId.length > 0, "Monid response has no runId");
+ if (typeof run.runId !== "string" || run.runId.length === 0) throw new EndpointResponseError("Monid response has no runId");
return run.runId;
}
function httpsUrl(value: unknown, subject: string): string {
@@ -90,12 +110,11 @@ const extensions: Readonly<Record<string, string>> = {
class MonidClient {
constructor(readonly baseUrl: string, readonly timeout: number, readonly pollIntervalMs: number, readonly fetcher: typeof globalThis.fetch) {}
async json(path: string, key: string, init: RequestInit = {}): Promise<{ readonly status: number; readonly body: Record<string, unknown> }> {
- const deadline = requestDeadline(this.timeout, () => new EndpointTransportError("Monid request timed out"));
- try {
- const response = await transport(deadline.wait(this.fetcher(`${this.baseUrl}${path}`, {
- ...init, signal: deadline.signal, headers: { authorization: `Bearer ${key}`, ...(init.headers ?? {}) },
- })));
- const text = await transport(deadline.wait(response.text()));
+ return await withRequestDeadline(this.timeout, async ({ signal, wait }) => {
+ const response = await wait(this.fetcher(`${this.baseUrl}${path}`, {
+ ...init, signal, headers: { authorization: `Bearer ${key}`, ...(init.headers ?? {}) },
+ }));
+ const text = await wait(response.text());
let body: unknown;
try { body = text.length === 0 ? {} : JSON.parse(text); } catch { body = undefined; }
// A synchronous run mirrors the provider's HTTP status while still returning the run itself.
@@ -103,7 +122,7 @@ class MonidClient {
if (!response.ok && !run) throw new MonidHttpError(response.status, response, text, { method: init.method ?? "GET", path });
if (body === undefined) throw new EndpointResponseError(`Monid returned invalid JSON (${response.status})`);
return { status: response.status, body: object(body, "Monid response") };
- } finally { deadline.finish(); }
+ }, () => new EndpointTransportError("Monid request timed out", { timeout: true }));
}
async run(request: { readonly provider: string; readonly endpoint: string; readonly input: Record<string, unknown> }, key: string) {
return await this.json("/v1/run", key, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(request) });
@@ -115,16 +134,15 @@ class MonidClient {
async completeRun(request: { readonly provider: string; readonly endpoint: string; readonly input: Record<string, unknown> }, key: string): Promise<Record<string, unknown>> {
let run = (await this.run(request, key)).body;
const id = runId(run);
- const deadline = requestDeadline(this.timeout);
- try {
+ return await withRequestDeadline(this.timeout, async ({ wait }) => {
while (!monidTerminalStatuses.includes(String(run.status) as typeof monidTerminalStatuses[number])) {
- await deadline.wait(new Promise((resolve) => setTimeout(resolve, this.pollIntervalMs)));
+ await wait(new Promise((resolve) => setTimeout(resolve, this.pollIntervalMs)));
run = await this.getRun(id, key);
}
- } finally { deadline.finish(); }
- const rejected = monidRunFailure(run, id);
- if (rejected !== undefined) throw rejected;
- return object(run.output, `Monid ${request.provider}${request.endpoint} output`);
+ const rejected = monidRunFailure(run, id);
+ if (rejected !== undefined) throw rejected;
+ return object(run.output, `Monid ${request.provider}${request.endpoint} output`);
+ });
}
/** Upload through the workspace file system (`sfs`) and mint a URL third parties can fetch. */
async publish(artifact: BlobRef, resources: ResourceStore, key: string): Promise<string> {
@@ -133,21 +151,19 @@ class MonidClient {
const path = `hypit/${artifact.resource}.${extensions[artifact.mediaType] ?? artifact.mediaType.split("/")[1] ?? "bin"}`;
const put = await this.completeRun({ provider: "sfs", endpoint: "/put", input: { path, sizeBytes: bytes.byteLength } }, key);
const uploadUrl = httpsUrl(put.uploadUrl, "Monid sfs /put output");
- const deadline = requestDeadline(this.timeout);
- try {
- const response = await deadline.wait(this.fetcher(uploadUrl, { method: "PUT", body: new Blob([new Uint8Array(bytes)]), signal: deadline.signal }));
- assert(response.ok, `Monid file upload returned HTTP ${response.status}`);
- } finally { deadline.finish(); }
+ await withRequestDeadline(this.timeout, async ({ signal, wait }) => {
+ const response = await wait(this.fetcher(uploadUrl, { method: "PUT", body: new Blob([new Uint8Array(bytes)]), signal }));
+ if (!response.ok) throw new MonidHttpError(response.status, response, "", { method: "PUT", path: uploadUrl });
+ });
const cat = await this.completeRun({ provider: "sfs", endpoint: "/cat", input: { path, ttl: "1d" } }, key);
return httpsUrl(cat.url, "Monid sfs /cat output");
}
async download(url: string): Promise<{ readonly bytes: Uint8Array; readonly mediaType: string }> {
- const deadline = requestDeadline(this.timeout);
- try {
- const response = await deadline.wait(this.fetcher(url, { signal: deadline.signal }));
- if (!response.ok) throw new Error(`Monid asset returned HTTP ${response.status}`);
- return { bytes: new Uint8Array(await deadline.wait(response.arrayBuffer())), mediaType: response.headers.get("content-type")?.split(";", 1)[0] ?? "application/octet-stream" };
- } finally { deadline.finish(); }
+ return await withRequestDeadline(this.timeout, async ({ signal, wait }) => {
+ const response = await wait(this.fetcher(url, { signal }));
+ if (!response.ok) throw new MonidHttpError(response.status, response, "", { method: "GET", path: url });
+ return { bytes: new Uint8Array(await wait(response.arrayBuffer())), mediaType: response.headers.get("content-type")?.split(";", 1)[0] ?? "application/octet-stream" };
+ });
}
}
@@ -172,15 +188,16 @@ function endpoint(client: MonidClient, pollIntervalMs: number, maxOperationMs: n
assert(route !== undefined, "Monid does not implement this exact capability");
const request = route.prepare(context.need.constraints);
await context.reportProgress?.({ phase: `Preparing Monid request: ${request.service} ${request.endpoint}` });
- let input: Record<string, unknown>;
+ const input = await request.compile(resolverFor(client, context, publicAssetUrl));
+ await context.reportProgress?.({ phase: `Submitting Monid request: ${request.service} ${request.endpoint}` });
+ let run: Record<string, unknown>;
try {
- input = await request.compile(resolverFor(client, context, publicAssetUrl));
+ ({ body: run } = await client.run({ provider: request.service, endpoint: request.endpoint, input }, apiKey(context.credentials)));
} catch (error) {
- throw new MonidServiceError(error instanceof EndpointServiceError ? error.code : "MONID_ERROR",
- `Monid request preparation failed; endpoint=${request.endpoint}; generation not submitted: ${failureMessage(error)}`);
+ const unknown = unknownSubmission(error);
+ if (unknown !== undefined) return unknown;
+ throw error;
}
- await context.reportProgress?.({ phase: `Submitting Monid request: ${request.service} ${request.endpoint}` });
- const { body: run } = await client.run({ provider: request.service, endpoint: request.endpoint, input }, apiKey(context.credentials));
const handle: Handle = { contract: "hypit.monid-operation@1", runId: runId(run), route: route.key, startedAt: Date.now() };
const receipt = { id: handle.runId };
const ended = monidTerminalStatuses.includes(String(run.status) as typeof monidTerminalStatuses[number]);
@@ -194,12 +211,14 @@ function endpoint(client: MonidClient, pollIntervalMs: number, maxOperationMs: n
}
},
async poll(context) {
+ let operationDeadlineAt: number | undefined;
try {
const handle = object(context.handle, "Monid handle") as unknown as Handle;
const route = monidRouteForCapability(context.need.capability);
assert(route !== undefined && handle.contract === "hypit.monid-operation@1" && handle.route === route.key, "Monid handle is invalid");
const receipt = { id: handle.runId };
- if (Date.now() - handle.startedAt > maxOperationMs) {
+ operationDeadlineAt = handle.startedAt + maxOperationMs;
+ if (Date.now() >= operationDeadlineAt) {
return { status: "failed", receipt, failure: { code: "MONID_OPERATION_TIMEOUT", message: `Monid run ${handle.runId} exceeded this Provider's operationTimeoutMs (${maxOperationMs}); remote outcome is unknown` } };
}
const run = await client.getRun(handle.runId, apiKey(context.credentials));
@@ -211,7 +230,7 @@ function endpoint(client: MonidClient, pollIntervalMs: number, maxOperationMs: n
if (rejected !== undefined) return { ...failure(rejected), receipt };
return { status: "ready", handle: canonicalize({ ...handle, urls: outputUrls(run) }), receipt };
} catch (error) {
- return pollAgainOrFail(error, { handle: context.handle, pollIntervalMs, failure });
+ return retrying(error, context.handle, pollIntervalMs, operationDeadlineAt) ?? failure(error);
}
},
async collect(context) {
@@ -229,7 +248,7 @@ function endpoint(client: MonidClient, pollIntervalMs: number, maxOperationMs: n
}
return { status: "completed", result: { value: route.packageResult(blobs) }, receipt: { id: handle.runId } };
} catch (error) {
- return failure(error);
+ return retrying(error, context.handle, pollIntervalMs) ?? failure(error);
}
},
};
@@ -244,10 +263,10 @@ export function createMonidProvider(options: CreateMonidProviderOptions = {}) {
}
const client = new MonidClient(apiBaseUrl(options.baseUrl ?? "https://api.monid.ai"), requestTimeoutMs, Math.min(pollIntervalMs, 5_000), options.fetch ?? globalThis.fetch);
const asyncEndpoint = endpoint(client, pollIntervalMs, operationTimeoutMs, options.publicAssetUrl);
- return defineEndpointPackage({
- module: monidProviderModuleRef, facet: "gateway", instance: options.instance ?? "monid.default", pool: options.pool ?? options.instance ?? "monid.default",
+ return defineEndpoint({
+ instance: options.instance ?? "monid.default", pool: options.pool ?? options.instance ?? "monid.default",
pricing: { kind: "page", url: "https://monid.ai/tools" },
- credentials: { apiKey: options.apiKey ?? credentialRef("os", "monid.api-key") },
+ credentials: { apiKey: options.apiKey ?? credentialRef("local", "monid.api-key") },
credentialInputs: { apiKey: { label: "Monid API key" } },
defaultConcurrency: options.defaultConcurrency ?? 4,
...(options.actionLimits === undefined ? {} : { actionLimits: options.actionLimits }),
diff --git a/packages/provider-monid/src/routes.ts b/packages/provider-monid/src/routes.ts
index 72564b89..284a3528 100644
--- a/packages/provider-monid/src/routes.ts
+++ b/packages/provider-monid/src/routes.ts
@@ -4,11 +4,11 @@ import {
generationTypes,
sealGeneratedImageSet,
sealGeneratedVideoSet,
-} from "@hypit/generation";
-import type { GenerationArtifactUrlResolver, GenerationRequest } from "@hypit/generation";
-import { canonicalize } from "@hypit/protocol";
-import type { BlobRef, CapabilityRef, CanonicalValue, StoredValue, TypeRef } from "@hypit/protocol";
-import type { EndpointRequest, EndpointSupport } from "@hypit/endpoint-kit";
+} from "@hypit/hypit/generation";
+import type { GenerationArtifactUrlResolver, GenerationRequest } from "@hypit/hypit/generation";
+import { canonicalize } from "@hypit/hypit/protocol";
+import type { BlobRef, CapabilityRef, CanonicalValue, StoredValue, TypeRef } from "@hypit/hypit/protocol";
+import type { EndpointRequest, EndpointSupport } from "@hypit/hypit/endpoint";
import { monidMappings } from "./mapping.js";
import type { MonidMapping } from "./mapping.js";
diff --git a/packages/provider-pollo/README.md b/packages/provider-pollo/README.md
index e6c381af..eba1eaff 100644
--- a/packages/provider-pollo/README.md
+++ b/packages/provider-pollo/README.md
@@ -40,8 +40,8 @@ Runtime Profile example:
"format": "hypit.runtime-local@1",
"dataRoot": ".hypit/runtimes/local",
"credentials": {
- "platform": {
- "use": "@hypit/credential-store-platform"
+ "local": {
+ "use": "@hypit/credential-store-local"
}
},
"endpoints": {
@@ -49,7 +49,7 @@ Runtime Profile example:
"use": "@hypit/provider-pollo",
"pool": "pollo.default",
"config": {
- "apiKey": { "store": "platform", "key": "pollo.api-key" },
+ "apiKey": { "store": "local", "key": "pollo.api-key" },
"defaultConcurrency": 3,
"pollIntervalMs": 10000
}
@@ -65,3 +65,5 @@ Runtime Profile example:
concurrency. HTTP failures keep Pollo's `errorCode`, message and `requestId`; a failed generation
keeps its `failMsg`, with any signed URL in the message redacted. Pollo stores generated files for
14 days; the Provider downloads them when the task completes.
+Polling transport failures and HTTP 429/5xx preserve the same task and honor standard `Retry-After`;
+the scheduled wake never passes the original operation deadline. Other errors end the local attempt.
diff --git a/packages/provider-pollo/package.json b/packages/provider-pollo/package.json
index b7b50266..7de025e6 100644
--- a/packages/provider-pollo/package.json
+++ b/packages/provider-pollo/package.json
@@ -5,15 +5,19 @@
"private": true,
"type": "module",
"exports": { ".": "./src/index.ts" },
+ "files": ["dist", "README.md"],
"hypit": { "activation": "./src/activation.ts" },
- "dependencies": {
- "@hypit/endpoint-kit": "workspace:*",
+ "peerDependencies": {
+ "@hypit/hypit": "workspace:^",
+ "@hypit/runtime-local": "workspace:^"
+ },
+ "devDependencies": {
+ "@hypit/endpoint": "workspace:*",
"@hypit/generation": "workspace:*",
+ "@hypit/hypit": "workspace:*",
"@hypit/protocol": "workspace:*",
"@hypit/runtime": "workspace:*",
- "@hypit/runtime-kit": "workspace:*"
- },
- "devDependencies": {
+ "@hypit/runtime-local": "workspace:*",
"@hypit/gpt-image": "workspace:*",
"@hypit/grok-imagine": "workspace:*",
"@hypit/minimax-h3": "workspace:*",
diff --git a/packages/provider-pollo/src/activation.ts b/packages/provider-pollo/src/activation.ts
index a2d13c61..117dfa57 100644
--- a/packages/provider-pollo/src/activation.ts
+++ b/packages/provider-pollo/src/activation.ts
@@ -6,7 +6,7 @@ import {
runtimeConfigObject,
runtimeConfigPositiveInteger,
runtimeConfigString,
-} from "@hypit/runtime-kit";
+} from "@hypit/runtime-local/extension";
import { createPolloProvider } from "./provider.js";
@@ -55,8 +55,8 @@ const adapter = createRuntimeEndpointAdapterFacet({
});
export const hypitPackage = {
- format: "hypit.node-package@1" as const,
- hostFacets: [adapter],
+ format: "hypit.package@1" as const,
+ facets: [adapter],
};
export default hypitPackage;
diff --git a/packages/provider-pollo/src/errors.ts b/packages/provider-pollo/src/errors.ts
index d2d69df4..c29f955d 100644
--- a/packages/provider-pollo/src/errors.ts
+++ b/packages/provider-pollo/src/errors.ts
@@ -1,4 +1,5 @@
-import { EndpointHttpError, EndpointServiceError } from "@hypit/endpoint-kit";
+import { EndpointServiceError } from "@hypit/hypit/endpoint";
+import { EndpointHttpError, retryAfterMs } from "@hypit/hypit/endpoint/http";
/** Pollo's `{ errorCode, message, code, requestId }` envelope and generation `failMsg`, kept at the service boundary. */
function record(value: unknown): Record<string, unknown> | undefined {
@@ -17,7 +18,8 @@ export function safePolloReason(value: string): string {
export class PolloServiceError extends EndpointServiceError {}
export class PolloHttpError extends EndpointHttpError {
- constructor(status: number, bodyText: string, request: { readonly method: string; readonly path: string }) {
+ constructor(status: number, response: { readonly headers: Headers }, bodyText: string,
+ request: { readonly method: string; readonly path: string }) {
let body: Record<string, unknown> | undefined;
try { body = record(JSON.parse(bodyText)); } catch { /* Non-JSON gateway failures still have HTTP evidence. */ }
const code = text(body?.errorCode) ?? "POLLO_HTTP_ERROR";
@@ -27,7 +29,8 @@ export class PolloHttpError extends EndpointHttpError {
`Pollo HTTP ${status}`, code, `${request.method} ${request.path}`,
...(requestId === undefined ? [] : [`request=${requestId}`]),
];
- super(code, `${facts.join("; ")}${reason === undefined ? "" : `: ${safePolloReason(reason)}`}`, status);
+ super(code, `${facts.join("; ")}${reason === undefined ? "" : `: ${safePolloReason(reason)}`}`,
+ status, retryAfterMs(response.headers));
}
}
diff --git a/packages/provider-pollo/src/mapping.ts b/packages/provider-pollo/src/mapping.ts
index 50d97b3b..eacfdf9d 100644
--- a/packages/provider-pollo/src/mapping.ts
+++ b/packages/provider-pollo/src/mapping.ts
@@ -1,5 +1,5 @@
-import type { ModuleRef } from "@hypit/protocol";
-import type { GenerationWireMapping } from "@hypit/generation";
+import type { ModuleRef } from "@hypit/hypit/protocol";
+import type { GenerationWireMapping } from "@hypit/hypit/generation";
const MINIMAX: ModuleRef = { name: "@hypit/minimax-h3", version: "1" };
const GROK: ModuleRef = { name: "@hypit/grok-imagine", version: "1" };
diff --git a/packages/provider-pollo/src/provider.ts b/packages/provider-pollo/src/provider.ts
index 50f29491..b9f000f1 100644
--- a/packages/provider-pollo/src/provider.ts
+++ b/packages/provider-pollo/src/provider.ts
@@ -1,11 +1,11 @@
-import { requestDeadline } from "@hypit/runtime-kit";
-import type { AsyncEndpoint, EndpointCredential, EndpointInvocationContext, EndpointOutcome } from "@hypit/endpoint-kit";
-import { EndpointResponseError, EndpointServiceError, EndpointTransportError, defineEndpointPackage, pollAgainOrFail, transport, wakeAfter } from "@hypit/endpoint-kit";
-import type { GenerationArtifactUrlResolver } from "@hypit/generation";
-import { canonicalize } from "@hypit/protocol";
-import type { BlobRef, CapabilityRef } from "@hypit/protocol";
-import { credentialRef } from "@hypit/runtime";
-import type { CredentialRef, ResourceStore } from "@hypit/runtime";
+import type { AsyncEndpoint, EndpointCredential, EndpointInvocationContext, EndpointOutcome } from "@hypit/hypit/endpoint";
+import { EndpointServiceError, defineEndpoint, wakeAfter } from "@hypit/hypit/endpoint";
+import { EndpointHttpError, EndpointResponseError, EndpointTransportError, withRequestDeadline } from "@hypit/hypit/endpoint/http";
+import type { GenerationArtifactUrlResolver } from "@hypit/hypit/generation";
+import { canonicalize } from "@hypit/hypit/protocol";
+import type { BlobRef, CanonicalValue, CapabilityRef } from "@hypit/hypit/protocol";
+import { credentialRef } from "@hypit/hypit/endpoint";
+import type { CredentialRef, ResourceStore } from "@hypit/hypit/endpoint";
import { polloRouteForCapability, polloRoutes } from "./routes.js";
import { PolloHttpError, PolloServiceError, polloTaskFailure } from "./errors.js";
@@ -17,7 +17,7 @@ export type CreatePolloProviderOptions = {
readonly baseUrl?: string;
readonly apiKey?: CredentialRef;
readonly defaultConcurrency?: number;
- readonly actionLimits?: import("@hypit/endpoint-kit").EndpointActionLimits;
+ readonly actionLimits?: import("@hypit/hypit/endpoint").EndpointActionLimits;
readonly pollIntervalMs?: number;
readonly requestTimeoutMs?: number;
readonly operationTimeoutMs?: number;
@@ -48,38 +48,56 @@ function apiBaseUrl(value: string): string {
}
function apiKey(credentials: Readonly<Record<string, EndpointCredential>>): string {
const value = credentials.apiKey?.secret;
- assert(typeof value === "string" && value.length > 0, "Pollo apiKey credential is unavailable; store a Pollo API key for this Endpoint");
+ if (typeof value !== "string" || value.length === 0) {
+ throw new PolloServiceError("POLLO_CREDENTIAL_UNAVAILABLE",
+ "Pollo apiKey credential is unavailable; store a Pollo API key for this Endpoint");
+ }
return value;
}
function failureMessage(error: unknown): string {
return error instanceof Error ? error.message : String(error);
}
function failure(error: unknown): EndpointOutcome {
- return { status: "failed", failure: { code: error instanceof EndpointServiceError ? error.code : "POLLO_ERROR", message: failureMessage(error) } };
+ if (!(error instanceof EndpointServiceError || error instanceof EndpointHttpError
+ || error instanceof EndpointTransportError || error instanceof EndpointResponseError)) throw error;
+ const code = error instanceof EndpointServiceError || error instanceof EndpointHttpError ? error.code : "POLLO_ERROR";
+ return { status: "failed", failure: { code, message: failureMessage(error) } };
+}
+function retrying(error: unknown, handle: CanonicalValue, pollIntervalMs: number, deadlineAt?: number): EndpointOutcome | undefined {
+ const delay = error instanceof EndpointTransportError ? pollIntervalMs
+ : error instanceof EndpointHttpError && (error.status === 429 || error.status >= 500)
+ ? error.retryAfterMs ?? pollIntervalMs : undefined;
+ if (delay === undefined) return undefined;
+ const now = Date.now();
+ return { status: "pending", handle, wakeAt: Math.min(now + delay, deadlineAt ?? Number.MAX_SAFE_INTEGER), progress: { phase: "retrying" } };
+}
+function unknownSubmission(error: unknown): EndpointOutcome | undefined {
+ return error instanceof EndpointTransportError ? { status: "failed", failure: {
+ code: "POLLO_SUBMISSION_UNKNOWN",
+ message: `Pollo submission transport failed; remote outcome is unknown: ${error.message}`,
+ } } : undefined;
}
class PolloClient {
constructor(readonly baseUrl: string, readonly timeout: number, readonly fetcher: typeof globalThis.fetch) {}
async json(path: string, key: string, init: RequestInit = {}): Promise<Record<string, unknown>> {
- const deadline = requestDeadline(this.timeout, () => new EndpointTransportError("Pollo request timed out"));
- try {
- const response = await transport(deadline.wait(this.fetcher(`${this.baseUrl}${path}`, {
- ...init, signal: deadline.signal, headers: { "x-api-key": key, ...(init.headers ?? {}) },
- })));
- const text = await transport(deadline.wait(response.text()));
- if (!response.ok) throw new PolloHttpError(response.status, text, { method: init.method ?? "GET", path });
+ return await withRequestDeadline(this.timeout, async ({ signal, wait }) => {
+ const response = await wait(this.fetcher(`${this.baseUrl}${path}`, {
+ ...init, signal, headers: { "x-api-key": key, ...(init.headers ?? {}) },
+ }));
+ const text = await wait(response.text());
+ if (!response.ok) throw new PolloHttpError(response.status, response, text, { method: init.method ?? "GET", path });
let body: unknown;
try { body = text.length === 0 ? {} : JSON.parse(text); } catch { throw new EndpointResponseError(`Pollo returned invalid JSON (${response.status})`); }
return object(body, "Pollo response");
- } finally { deadline.finish(); }
+ }, () => new EndpointTransportError("Pollo request timed out", { timeout: true }));
}
async download(url: string): Promise<{ readonly bytes: Uint8Array; readonly mediaType: string }> {
- const deadline = requestDeadline(this.timeout);
- try {
- const response = await deadline.wait(this.fetcher(url, { signal: deadline.signal }));
- if (!response.ok) throw new Error(`Pollo asset returned HTTP ${response.status}`);
- return { bytes: new Uint8Array(await deadline.wait(response.arrayBuffer())), mediaType: response.headers.get("content-type")?.split(";", 1)[0] ?? "application/octet-stream" };
- } finally { deadline.finish(); }
+ return await withRequestDeadline(this.timeout, async ({ signal, wait }) => {
+ const response = await wait(this.fetcher(url, { signal }));
+ if (!response.ok) throw new PolloHttpError(response.status, response, "", { method: "GET", path: url });
+ return { bytes: new Uint8Array(await wait(response.arrayBuffer())), mediaType: response.headers.get("content-type")?.split(";", 1)[0] ?? "application/octet-stream" };
+ });
}
}
@@ -104,18 +122,19 @@ function endpoint(client: PolloClient, pollIntervalMs: number, maxOperationMs: n
assert(route !== undefined, "Pollo does not implement this exact capability");
const request = route.prepare(context.need.constraints);
await context.reportProgress?.({ phase: `Preparing Pollo request: ${request.path}` });
- let body: Record<string, unknown>;
+ const body = await request.compile(resolverFor(context, publicAssetUrl));
+ await context.reportProgress?.({ phase: `Submitting Pollo request: ${request.path}` });
+ let response: Record<string, unknown>;
try {
- body = await request.compile(resolverFor(context, publicAssetUrl));
+ response = await client.json(request.path, apiKey(context.credentials), {
+ method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body),
+ });
} catch (error) {
- throw new PolloServiceError(error instanceof EndpointServiceError ? error.code : "POLLO_ERROR",
- `Pollo request preparation failed; path=${request.path}; generation not submitted: ${failureMessage(error)}`);
+ const unknown = unknownSubmission(error);
+ if (unknown !== undefined) return unknown;
+ throw error;
}
- await context.reportProgress?.({ phase: `Submitting Pollo request: ${request.path}` });
- const response = await client.json(request.path, apiKey(context.credentials), {
- method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body),
- });
- assert(typeof response.taskId === "string" && response.taskId.length > 0, "Pollo response has no taskId");
+ if (typeof response.taskId !== "string" || response.taskId.length === 0) throw new EndpointResponseError("Pollo response has no taskId");
const handle: Handle = { contract: "hypit.pollo-operation@1", taskId: response.taskId, route: route.key, startedAt: Date.now() };
const receipt = { id: handle.taskId };
await context.checkpoint?.({ handle: canonicalize(handle), receipt });
@@ -125,32 +144,34 @@ function endpoint(client: PolloClient, pollIntervalMs: number, maxOperationMs: n
}
},
async poll(context) {
+ let operationDeadlineAt: number | undefined;
try {
const handle = object(context.handle, "Pollo handle") as unknown as Handle;
const route = polloRouteForCapability(context.need.capability);
assert(route !== undefined && handle.contract === "hypit.pollo-operation@1" && handle.route === route.key, "Pollo handle is invalid");
const receipt = { id: handle.taskId };
- if (Date.now() - handle.startedAt > maxOperationMs) {
+ operationDeadlineAt = handle.startedAt + maxOperationMs;
+ if (Date.now() >= operationDeadlineAt) {
return { status: "failed", receipt, failure: { code: "POLLO_OPERATION_TIMEOUT", message: `Pollo task ${handle.taskId} exceeded this Provider's operationTimeoutMs (${maxOperationMs}); remote outcome is unknown` } };
}
const task = await client.json(`/v1/generation/${encodeURIComponent(handle.taskId)}/status`, apiKey(context.credentials));
- assert(Array.isArray(task.generations) && task.generations.length > 0, "Pollo task has no generations");
+ if (!Array.isArray(task.generations) || task.generations.length === 0) throw new EndpointResponseError("Pollo task has no generations");
const generations = task.generations.map((item, index) => object(item, `Pollo generation ${index + 1}`));
const rejected = polloTaskFailure(generations, handle.taskId);
if (rejected !== undefined) return { ...failure(rejected), receipt };
const pending = generations.find((generation) => generation.status !== "succeed");
if (pending !== undefined) {
const status = String(pending.status);
- assert(status === "waiting" || status === "processing", `Pollo returned unknown generation status ${status}`);
+ if (status !== "waiting" && status !== "processing") throw new EndpointResponseError(`Pollo returned unknown generation status ${status}`);
return { ...wakeAfter(canonicalize(handle), pollIntervalMs, Date.now(), { phase: status }), receipt };
}
const urls = generations.map((generation, index) => {
- assert(typeof generation.url === "string" && /^https?:\/\//u.test(generation.url), `Pollo generation ${index + 1} has no URL`);
+ if (typeof generation.url !== "string" || !/^https?:\/\//u.test(generation.url)) throw new EndpointResponseError(`Pollo generation ${index + 1} has no URL`);
return generation.url;
});
return { status: "ready", handle: canonicalize({ ...handle, urls }), receipt };
} catch (error) {
- return pollAgainOrFail(error, { handle: context.handle, pollIntervalMs, failure });
+ return retrying(error, context.handle, pollIntervalMs, operationDeadlineAt) ?? failure(error);
}
},
async collect(context) {
@@ -166,7 +187,7 @@ function endpoint(client: PolloClient, pollIntervalMs: number, maxOperationMs: n
}
return { status: "completed", result: { value: route.packageResult(blobs) }, receipt: { id: handle.taskId } };
} catch (error) {
- return failure(error);
+ return retrying(error, context.handle, pollIntervalMs) ?? failure(error);
}
},
};
@@ -180,10 +201,10 @@ export function createPolloProvider(options: CreatePolloProviderOptions = {}) {
}
const client = new PolloClient(apiBaseUrl(options.baseUrl ?? "https://pollo.ai/api/platform"), requestTimeoutMs, options.fetch ?? globalThis.fetch);
const asyncEndpoint = endpoint(client, options.pollIntervalMs ?? 10_000, operationTimeoutMs, options.publicAssetUrl);
- return defineEndpointPackage({
- module: polloProviderModuleRef, facet: "gateway", instance: options.instance ?? "pollo.default", pool: options.pool ?? options.instance ?? "pollo.default",
+ return defineEndpoint({
+ instance: options.instance ?? "pollo.default", pool: options.pool ?? options.instance ?? "pollo.default",
pricing: { kind: "page", url: "https://api.pollo.ai/pricing" },
- credentials: { apiKey: options.apiKey ?? credentialRef("os", "pollo.api-key") },
+ credentials: { apiKey: options.apiKey ?? credentialRef("local", "pollo.api-key") },
credentialInputs: { apiKey: { label: "Pollo API key" } },
defaultConcurrency: options.defaultConcurrency ?? 4,
...(options.actionLimits === undefined ? {} : { actionLimits: options.actionLimits }),
diff --git a/packages/provider-pollo/src/routes.ts b/packages/provider-pollo/src/routes.ts
index 9b9e77f1..6905a080 100644
--- a/packages/provider-pollo/src/routes.ts
+++ b/packages/provider-pollo/src/routes.ts
@@ -4,11 +4,11 @@ import {
generationTypes,
sealGeneratedImageSet,
sealGeneratedVideoSet,
-} from "@hypit/generation";
-import type { GenerationArtifactUrlResolver, GenerationRequest, GenerationWireMapping } from "@hypit/generation";
-import { canonicalize } from "@hypit/protocol";
-import type { BlobRef, CapabilityRef, CanonicalValue, StoredValue, TypeRef } from "@hypit/protocol";
-import type { EndpointRequest, EndpointSupport } from "@hypit/endpoint-kit";
+} from "@hypit/hypit/generation";
+import type { GenerationArtifactUrlResolver, GenerationRequest, GenerationWireMapping } from "@hypit/hypit/generation";
+import { canonicalize } from "@hypit/hypit/protocol";
+import type { BlobRef, CapabilityRef, CanonicalValue, StoredValue, TypeRef } from "@hypit/hypit/protocol";
+import type { EndpointRequest, EndpointSupport } from "@hypit/hypit/endpoint";
import { polloMappings } from "./mapping.js";
export type PolloPreparedRequest = {
diff --git a/packages/provider-tokendance/README.md b/packages/provider-tokendance/README.md
index 2137a225..459eacaa 100644
--- a/packages/provider-tokendance/README.md
+++ b/packages/provider-tokendance/README.md
@@ -49,8 +49,8 @@ Runtime Profile example:
"format": "hypit.runtime-local@1",
"dataRoot": ".hypit/runtimes/local",
"credentials": {
- "platform": {
- "use": "@hypit/credential-store-platform"
+ "local": {
+ "use": "@hypit/credential-store-local"
}
},
"endpoints": {
@@ -58,7 +58,7 @@ Runtime Profile example:
"use": "@hypit/provider-tokendance",
"pool": "tokendance.default",
"config": {
- "apiKey": { "store": "platform", "key": "tokendance.api-key" },
+ "apiKey": { "store": "local", "key": "tokendance.api-key" },
"defaultConcurrency": 3,
"pollIntervalMs": 10000
}
@@ -73,3 +73,5 @@ Runtime Profile example:
`operationTimeoutMs` and `actionLimits` bound single HTTP calls, the whole remote task and action
concurrency. Task and HTTP failures keep TokenDance's `error.code` and message, with any signed URL
in the message redacted.
+Polling transport failures and HTTP 429/5xx preserve the same task and honor standard `Retry-After`;
+the scheduled wake never passes the original operation deadline. Other errors end the local attempt.
diff --git a/packages/provider-tokendance/package.json b/packages/provider-tokendance/package.json
index 78a714d6..d8aa4a6a 100644
--- a/packages/provider-tokendance/package.json
+++ b/packages/provider-tokendance/package.json
@@ -5,15 +5,19 @@
"private": true,
"type": "module",
"exports": { ".": "./src/index.ts" },
+ "files": ["dist", "README.md"],
"hypit": { "activation": "./src/activation.ts" },
- "dependencies": {
- "@hypit/endpoint-kit": "workspace:*",
+ "peerDependencies": {
+ "@hypit/hypit": "workspace:^",
+ "@hypit/runtime-local": "workspace:^"
+ },
+ "devDependencies": {
+ "@hypit/endpoint": "workspace:*",
"@hypit/generation": "workspace:*",
+ "@hypit/hypit": "workspace:*",
"@hypit/protocol": "workspace:*",
"@hypit/runtime": "workspace:*",
- "@hypit/runtime-kit": "workspace:*"
- },
- "devDependencies": {
+ "@hypit/runtime-local": "workspace:*",
"@hypit/minimax-h3": "workspace:*",
"@hypit/seedance": "workspace:*",
"@hypit/seedream": "workspace:*"
diff --git a/packages/provider-tokendance/src/activation.ts b/packages/provider-tokendance/src/activation.ts
index 2a2eec12..c3beb046 100644
--- a/packages/provider-tokendance/src/activation.ts
+++ b/packages/provider-tokendance/src/activation.ts
@@ -6,7 +6,7 @@ import {
runtimeConfigObject,
runtimeConfigPositiveInteger,
runtimeConfigString,
-} from "@hypit/runtime-kit";
+} from "@hypit/runtime-local/extension";
import { createTokenDanceProvider } from "./provider.js";
@@ -55,8 +55,8 @@ const adapter = createRuntimeEndpointAdapterFacet({
});
export const hypitPackage = {
- format: "hypit.node-package@1" as const,
- hostFacets: [adapter],
+ format: "hypit.package@1" as const,
+ facets: [adapter],
};
export default hypitPackage;
diff --git a/packages/provider-tokendance/src/errors.ts b/packages/provider-tokendance/src/errors.ts
index 1e0af040..6eb985cc 100644
--- a/packages/provider-tokendance/src/errors.ts
+++ b/packages/provider-tokendance/src/errors.ts
@@ -1,4 +1,5 @@
-import { EndpointHttpError, EndpointServiceError } from "@hypit/endpoint-kit";
+import { EndpointServiceError } from "@hypit/hypit/endpoint";
+import { EndpointHttpError, retryAfterMs } from "@hypit/hypit/endpoint/http";
/** TokenDance relays each protocol's own error body; keep the code, the message and the HTTP facts. */
function record(value: unknown): Record<string, unknown> | undefined {
@@ -31,7 +32,8 @@ export class TokenDanceHttpError extends EndpointHttpError {
...(request.model === undefined ? [] : [`model=${request.model}`]),
...(requestId === undefined ? [] : [`request=${requestId}`]),
];
- super(code, `${facts.join("; ")}${reason === undefined ? "" : `: ${safeTokenDanceReason(reason)}`}`, status);
+ super(code, `${facts.join("; ")}${reason === undefined ? "" : `: ${safeTokenDanceReason(reason)}`}`,
+ status, retryAfterMs(response.headers));
}
}
diff --git a/packages/provider-tokendance/src/mapping.ts b/packages/provider-tokendance/src/mapping.ts
index b10f2c27..1eb0ce3b 100644
--- a/packages/provider-tokendance/src/mapping.ts
+++ b/packages/provider-tokendance/src/mapping.ts
@@ -1,5 +1,5 @@
-import type { ModuleRef } from "@hypit/protocol";
-import type { GenerationWireMapping } from "@hypit/generation";
+import type { ModuleRef } from "@hypit/hypit/protocol";
+import type { GenerationWireMapping } from "@hypit/hypit/generation";
const SEEDANCE: ModuleRef = { name: "@hypit/seedance", version: "1" };
const SEEDREAM: ModuleRef = { name: "@hypit/seedream", version: "1" };
diff --git a/packages/provider-tokendance/src/provider.ts b/packages/provider-tokendance/src/provider.ts
index 29b5af92..bc3d74d7 100644
--- a/packages/provider-tokendance/src/provider.ts
+++ b/packages/provider-tokendance/src/provider.ts
@@ -1,11 +1,11 @@
-import { requestDeadline } from "@hypit/runtime-kit";
-import type { AsyncEndpoint, EndpointCredential, EndpointInvocationContext, EndpointOutcome, ImmediateEndpointHandler } from "@hypit/endpoint-kit";
-import { EndpointResponseError, EndpointServiceError, EndpointTransportError, defineEndpointPackage, pollAgainOrFail, transport, wakeAfter } from "@hypit/endpoint-kit";
-import type { GenerationArtifactUrlResolver } from "@hypit/generation";
-import { canonicalize } from "@hypit/protocol";
-import type { BlobRef, CapabilityRef } from "@hypit/protocol";
-import { credentialRef } from "@hypit/runtime";
-import type { CredentialRef, ResourceStore } from "@hypit/runtime";
+import type { AsyncEndpoint, EndpointCredential, EndpointInvocationContext, EndpointOutcome, ImmediateEndpointHandler } from "@hypit/hypit/endpoint";
+import { EndpointServiceError, defineEndpoint, wakeAfter } from "@hypit/hypit/endpoint";
+import { EndpointHttpError, EndpointResponseError, EndpointTransportError, withRequestDeadline } from "@hypit/hypit/endpoint/http";
+import type { GenerationArtifactUrlResolver } from "@hypit/hypit/generation";
+import { canonicalize } from "@hypit/hypit/protocol";
+import type { BlobRef, CanonicalValue, CapabilityRef } from "@hypit/hypit/protocol";
+import { credentialRef } from "@hypit/hypit/endpoint";
+import type { CredentialRef, ResourceStore } from "@hypit/hypit/endpoint";
import { tokenDanceRouteForCapability, tokenDanceRoutes } from "./routes.js";
import type { TokenDanceRoute } from "./routes.js";
import { TokenDanceHttpError, TokenDanceServiceError, tokenDanceTaskFailure } from "./errors.js";
@@ -18,7 +18,7 @@ export type CreateTokenDanceProviderOptions = {
readonly baseUrl?: string;
readonly apiKey?: CredentialRef;
readonly defaultConcurrency?: number;
- readonly actionLimits?: import("@hypit/endpoint-kit").EndpointActionLimits;
+ readonly actionLimits?: import("@hypit/hypit/endpoint").EndpointActionLimits;
readonly pollIntervalMs?: number;
readonly requestTimeoutMs?: number;
readonly operationTimeoutMs?: number;
@@ -49,14 +49,34 @@ function apiBaseUrl(value: string): string {
}
function apiKey(credentials: Readonly<Record<string, EndpointCredential>>): string {
const value = credentials.apiKey?.secret;
- assert(typeof value === "string" && value.length > 0, "TokenDance apiKey credential is unavailable; store a TokenDance API key for this Endpoint");
+ if (typeof value !== "string" || value.length === 0) {
+ throw new TokenDanceServiceError("TOKENDANCE_CREDENTIAL_UNAVAILABLE",
+ "TokenDance apiKey credential is unavailable; store a TokenDance API key for this Endpoint");
+ }
return value;
}
function failureMessage(error: unknown): string {
return error instanceof Error ? error.message : String(error);
}
function failure(error: unknown): EndpointOutcome {
- return { status: "failed", failure: { code: error instanceof EndpointServiceError ? error.code : "TOKENDANCE_ERROR", message: failureMessage(error) } };
+ if (!(error instanceof EndpointServiceError || error instanceof EndpointHttpError
+ || error instanceof EndpointTransportError || error instanceof EndpointResponseError)) throw error;
+ const code = error instanceof EndpointServiceError || error instanceof EndpointHttpError ? error.code : "TOKENDANCE_ERROR";
+ return { status: "failed", failure: { code, message: failureMessage(error) } };
+}
+function retrying(error: unknown, handle: CanonicalValue, pollIntervalMs: number, deadlineAt?: number): EndpointOutcome | undefined {
+ const delay = error instanceof EndpointTransportError ? pollIntervalMs
+ : error instanceof EndpointHttpError && (error.status === 429 || error.status >= 500)
+ ? error.retryAfterMs ?? pollIntervalMs : undefined;
+ if (delay === undefined) return undefined;
+ const now = Date.now();
+ return { status: "pending", handle, wakeAt: Math.min(now + delay, deadlineAt ?? Number.MAX_SAFE_INTEGER), progress: { phase: "retrying" } };
+}
+function unknownSubmission(error: unknown): EndpointOutcome | undefined {
+ return error instanceof EndpointTransportError ? { status: "failed", failure: {
+ code: "TOKENDANCE_SUBMISSION_UNKNOWN",
+ message: `TokenDance submission transport failed; remote outcome is unknown: ${error.message}`,
+ } } : undefined;
}
function httpsUrl(value: unknown, subject: string): string {
assert(typeof value === "string" && /^https?:\/\//u.test(value), `${subject} has no download URL`);
@@ -66,12 +86,11 @@ function httpsUrl(value: unknown, subject: string): string {
class TokenDanceClient {
constructor(readonly baseUrl: string, readonly timeout: number, readonly fetcher: typeof globalThis.fetch) {}
async json(path: string, key: string, init: RequestInit = {}): Promise<Record<string, unknown>> {
- const deadline = requestDeadline(this.timeout, () => new EndpointTransportError("TokenDance request timed out"));
- try {
- const response = await transport(deadline.wait(this.fetcher(`${this.baseUrl}${path}`, {
- ...init, signal: deadline.signal, headers: { authorization: `Bearer ${key}`, ...(init.headers ?? {}) },
- })));
- const text = await transport(deadline.wait(response.text()));
+ return await withRequestDeadline(this.timeout, async ({ signal, wait }) => {
+ const response = await wait(this.fetcher(`${this.baseUrl}${path}`, {
+ ...init, signal, headers: { authorization: `Bearer ${key}`, ...(init.headers ?? {}) },
+ }));
+ const text = await wait(response.text());
if (!response.ok) {
const input = typeof init.body === "string" ? JSON.parse(init.body) as Record<string, unknown> : undefined;
throw new TokenDanceHttpError(response.status, response, text, {
@@ -81,7 +100,7 @@ class TokenDanceClient {
let body: unknown;
try { body = text.length === 0 ? {} : JSON.parse(text); } catch { throw new EndpointResponseError(`TokenDance returned invalid JSON (${response.status})`); }
return object(body, "TokenDance response");
- } finally { deadline.finish(); }
+ }, () => new EndpointTransportError("TokenDance request timed out", { timeout: true }));
}
/** MiniMax's file API through the gateway; the returned id is referenced as `mm_file://{file_id}`. */
async uploadMiniMaxInput(bytes: Uint8Array, artifact: BlobRef, key: string): Promise<string> {
@@ -96,12 +115,11 @@ class TokenDanceClient {
return `mm_file://${String(id)}`;
}
async download(url: string): Promise<{ readonly bytes: Uint8Array; readonly mediaType: string }> {
- const deadline = requestDeadline(this.timeout);
- try {
- const response = await deadline.wait(this.fetcher(url, { signal: deadline.signal }));
- if (!response.ok) throw new Error(`TokenDance asset returned HTTP ${response.status}`);
- return { bytes: new Uint8Array(await deadline.wait(response.arrayBuffer())), mediaType: response.headers.get("content-type")?.split(";", 1)[0] ?? "application/octet-stream" };
- } finally { deadline.finish(); }
+ return await withRequestDeadline(this.timeout, async ({ signal, wait }) => {
+ const response = await wait(this.fetcher(url, { signal }));
+ if (!response.ok) throw new TokenDanceHttpError(response.status, response, "", { method: "GET", path: url });
+ return { bytes: new Uint8Array(await wait(response.arrayBuffer())), mediaType: response.headers.get("content-type")?.split(";", 1)[0] ?? "application/octet-stream" };
+ });
}
}
@@ -138,16 +156,10 @@ async function prepare(client: TokenDanceClient, context: EndpointInvocationCont
assert(route !== undefined, "TokenDance does not implement this exact capability");
const request = route.prepare(context.need.constraints);
await context.reportProgress?.({ phase: `Preparing TokenDance request: ${request.model}` });
- let body: string;
- try {
- body = JSON.stringify(await request.compile(resolverFor(client, route, context, publicAssetUrl)));
- const cap = route.mediaLimits.body;
- assert(cap === undefined || Buffer.byteLength(body) <= cap,
- `TokenDance ${route.protocol} accepts request bodies up to ${(cap ?? 0) / 1_000_000} MB; inline references make this one ${Buffer.byteLength(body)} bytes`);
- } catch (error) {
- throw new TokenDanceServiceError(error instanceof EndpointServiceError ? error.code : "TOKENDANCE_ERROR",
- `TokenDance request preparation failed; model=${request.model}; generation not submitted: ${failureMessage(error)}`);
- }
+ const body = JSON.stringify(await request.compile(resolverFor(client, route, context, publicAssetUrl)));
+ const cap = route.mediaLimits.body;
+ assert(cap === undefined || Buffer.byteLength(body) <= cap,
+ `TokenDance ${route.protocol} accepts request bodies up to ${(cap ?? 0) / 1_000_000} MB; inline references make this one ${Buffer.byteLength(body)} bytes`);
return { route, model: request.model, body };
}
@@ -167,7 +179,7 @@ const paths = {
function taskId(protocol: keyof typeof paths, response: Record<string, unknown>): string {
const id = protocol === "ark-video" ? response.id : response.task_id;
- assert(typeof id === "string" && id.length > 0, "TokenDance response has no task id");
+ if (typeof id !== "string" || id.length === 0) throw new EndpointResponseError("TokenDance response has no task id");
return id;
}
@@ -188,9 +200,16 @@ function endpoint(client: TokenDanceClient, pollIntervalMs: number, maxOperation
const { route, model, body } = await prepare(client, context, publicAssetUrl);
assert(route.protocol !== "ark-image", "TokenDance image capabilities use an immediate endpoint");
await context.reportProgress?.({ phase: `Submitting TokenDance request: ${model}` });
- const response = await client.json(paths[route.protocol].submit, apiKey(context.credentials), {
- method: "POST", headers: { "content-type": "application/json" }, body,
- });
+ let response: Record<string, unknown>;
+ try {
+ response = await client.json(paths[route.protocol].submit, apiKey(context.credentials), {
+ method: "POST", headers: { "content-type": "application/json" }, body,
+ });
+ } catch (error) {
+ const unknown = unknownSubmission(error);
+ if (unknown !== undefined) return unknown;
+ throw error;
+ }
const handle: Handle = { contract: "hypit.tokendance-operation@1", taskId: taskId(route.protocol, response), route: route.key, startedAt: Date.now() };
const receipt = { id: handle.taskId };
await context.checkpoint?.({ handle: canonicalize(handle), receipt });
@@ -200,12 +219,14 @@ function endpoint(client: TokenDanceClient, pollIntervalMs: number, maxOperation
}
},
async poll(context) {
+ let operationDeadlineAt: number | undefined;
try {
const handle = object(context.handle, "TokenDance handle") as unknown as Handle;
const route = tokenDanceRouteForCapability(context.need.capability);
assert(route !== undefined && handle.contract === "hypit.tokendance-operation@1" && handle.route === route.key && route.protocol !== "ark-image", "TokenDance handle is invalid");
const receipt = { id: handle.taskId };
- if (Date.now() - handle.startedAt > maxOperationMs) {
+ operationDeadlineAt = handle.startedAt + maxOperationMs;
+ if (Date.now() >= operationDeadlineAt) {
return { status: "failed", receipt, failure: { code: "TOKENDANCE_OPERATION_TIMEOUT", message: `TokenDance task ${handle.taskId} exceeded this Provider's operationTimeoutMs (${maxOperationMs}); remote outcome is unknown` } };
}
const task = taskBody(route.protocol, await client.json(paths[route.protocol].task(handle.taskId), apiKey(context.credentials)));
@@ -213,10 +234,10 @@ function endpoint(client: TokenDanceClient, pollIntervalMs: number, maxOperation
if (status === "queued" || status === "running") return { ...wakeAfter(canonicalize(handle), pollIntervalMs, Date.now(), { phase: status }), receipt };
const rejected = tokenDanceTaskFailure(task, handle.taskId);
if (rejected !== undefined) return { ...failure(rejected), receipt };
- assert(status === "succeeded", `TokenDance returned unknown task status ${status}`);
+ if (status !== "succeeded") throw new EndpointResponseError(`TokenDance returned unknown task status ${status}`);
return { status: "ready", handle: canonicalize({ ...handle, url: taskVideoUrl(route.protocol, task) }), receipt };
} catch (error) {
- return pollAgainOrFail(error, { handle: context.handle, pollIntervalMs, failure });
+ return retrying(error, context.handle, pollIntervalMs, operationDeadlineAt) ?? failure(error);
}
},
async collect(context) {
@@ -228,7 +249,7 @@ function endpoint(client: TokenDanceClient, pollIntervalMs: number, maxOperation
const blobs = await store(client, [httpsUrl(handle.url, "TokenDance handle")], context.resources);
return { status: "completed", result: { value: route.packageResult(blobs) }, receipt: { id: handle.taskId } };
} catch (error) {
- return failure(error);
+ return retrying(error, context.handle, pollIntervalMs) ?? failure(error);
}
},
};
@@ -254,10 +275,10 @@ export function createTokenDanceProvider(options: CreateTokenDanceProviderOption
await context.reportProgress?.({ phase: "Receiving generated images" });
return { value: route.packageResult(await store(client, urls, context.resources)) };
};
- return defineEndpointPackage({
- module: tokenDanceProviderModuleRef, facet: "gateway", instance: options.instance ?? "tokendance.default", pool: options.pool ?? options.instance ?? "tokendance.default",
+ return defineEndpoint({
+ instance: options.instance ?? "tokendance.default", pool: options.pool ?? options.instance ?? "tokendance.default",
pricing: { kind: "page", url: "https://tokendance.space/models" },
- credentials: { apiKey: options.apiKey ?? credentialRef("os", "tokendance.api-key") },
+ credentials: { apiKey: options.apiKey ?? credentialRef("local", "tokendance.api-key") },
credentialInputs: { apiKey: { label: "TokenDance API key" } },
defaultConcurrency: options.defaultConcurrency ?? 4,
...(options.actionLimits === undefined ? {} : { actionLimits: options.actionLimits }),
diff --git a/packages/provider-tokendance/src/routes.ts b/packages/provider-tokendance/src/routes.ts
index 5b0809a3..e0ac48dd 100644
--- a/packages/provider-tokendance/src/routes.ts
+++ b/packages/provider-tokendance/src/routes.ts
@@ -4,11 +4,11 @@ import {
generationTypes,
sealGeneratedImageSet,
sealGeneratedVideoSet,
-} from "@hypit/generation";
-import type { GenerationArtifactUrlResolver, GenerationRequest, GenerationWireMapping } from "@hypit/generation";
-import { canonicalize } from "@hypit/protocol";
-import type { BlobRef, CapabilityRef, CanonicalValue, StoredValue, TypeRef } from "@hypit/protocol";
-import type { EndpointRequest, EndpointSupport } from "@hypit/endpoint-kit";
+} from "@hypit/hypit/generation";
+import type { GenerationArtifactUrlResolver, GenerationRequest, GenerationWireMapping } from "@hypit/hypit/generation";
+import { canonicalize } from "@hypit/hypit/protocol";
+import type { BlobRef, CapabilityRef, CanonicalValue, StoredValue, TypeRef } from "@hypit/hypit/protocol";
+import type { EndpointRequest, EndpointSupport } from "@hypit/hypit/endpoint";
import { tokenDanceMappings } from "./mapping.js";
/** Which TokenDance protocol a capability submits through. */
diff --git a/packages/provider-whisperx-local/README.md b/packages/provider-whisperx-local/README.md
index f722845f..e94f364c 100644
--- a/packages/provider-whisperx-local/README.md
+++ b/packages/provider-whisperx-local/README.md
@@ -1,7 +1,8 @@
# @hypit/provider-whisperx-local
-Trusted local Provider for the explicit `@hypit/whisperx#whisperx-alignment` capability. It talks to
-the warm Python service in `services/whisperx` through `/health` and `/transcribe`.
+Trusted local Provider for the explicit `@hypit/whisperx#whisperx-alignment` capability. Its
+`runtime/` directory owns the warm Python service and frozen environment used through `/health`
+and `/transcribe`.
The Provider accepts only canonical 16 kHz mono PCM s16 WAV bytes produced by the separate media
projection Need. It validates those bytes and stages them unchanged. WhisperX is therefore never
@@ -99,7 +100,7 @@ service retains its earlier environment; arrange an idle restart when changing t
inference settings. Inspect its reported configuration and logs, and account for active work.
If NLTK refuses a proxied fetch during preparation, follow the service’s
-[explicit proxy preparation](../../services/whisperx/README.md#preparing-sentence-data-through-a-proxy).
+[explicit proxy preparation](./runtime/README.md#preparing-sentence-data-through-a-proxy).
Preparation commands write `install.log`; the running service writes `program.log`, with stderr in
`program.err.log` on Windows. Inspect service logs for Python model-loading and inference messages;
diff --git a/packages/provider-whisperx-local/package.json b/packages/provider-whisperx-local/package.json
index b8ef3064..3b9c7298 100644
--- a/packages/provider-whisperx-local/package.json
+++ b/packages/provider-whisperx-local/package.json
@@ -1,27 +1,28 @@
{
"name": "@hypit/provider-whisperx-local",
- "version": "0.0.0-dev",
+ "version": "0.1.0",
"license": "SEE LICENSE IN LICENSE",
"private": true,
"type": "module",
"exports": {
".": "./src/index.ts"
},
+ "files": ["dist", "runtime", "README.md"],
"hypit": {
"activation": "./src/activation.ts"
},
- "dependencies": {
- "@hypit/endpoint-kit": "workspace:*",
- "@hypit/package-loader-node": "workspace:*",
+ "peerDependencies": {
+ "@hypit/hypit": "workspace:^",
+ "@hypit/runtime-local": "workspace:^",
+ "@hypit/whisperx": "workspace:^"
+ },
+ "devDependencies": {
+ "@hypit/endpoint": "workspace:*",
+ "@hypit/hypit": "workspace:*",
"@hypit/protocol": "workspace:*",
- "@hypit/runtime-host-node": "workspace:*",
- "@hypit/runtime-kit": "workspace:*",
+ "@hypit/runtime-local": "workspace:*",
"@hypit/speech-evidence": "workspace:*",
"@hypit/whisperx": "workspace:*",
- "@hypit/whisperx-service-runtime": "workspace:*"
- },
- "devDependencies": {
- "@hypit/driver-node": "workspace:*",
- "@hypit/speech": "workspace:*"
+ "@hypit/executor": "workspace:*"
}
}
diff --git a/services/whisperx/.python-version b/packages/provider-whisperx-local/runtime/.python-version
similarity index 100%
rename from services/whisperx/.python-version
rename to packages/provider-whisperx-local/runtime/.python-version
diff --git a/services/whisperx/README.md b/packages/provider-whisperx-local/runtime/README.md
similarity index 91%
rename from services/whisperx/README.md
rename to packages/provider-whisperx-local/runtime/README.md
index d337b3cc..2640140b 100644
--- a/services/whisperx/README.md
+++ b/packages/provider-whisperx-local/runtime/README.md
@@ -1,7 +1,7 @@
-# SVML WhisperX Service
+# Hypit local WhisperX runtime
-This is the trusted, warm Python process used by `@hypit/provider-whisperx-local`. It is a Runtime
-deployment package, not an author-importable SVML module and not part of Core.
+This is the trusted, warm Python process owned and shipped by `@hypit/provider-whisperx-local`.
+It is Provider material, not another package, an author-importable SVML module or part of Core.
The service has one narrow job:
@@ -29,9 +29,9 @@ WhisperX 3.8.6 supports Python 3.10 through 3.13. The checked-in lock selects Py
```bash
uv python install 3.13
-uv sync --project services/whisperx --frozen
-HYPIT_WHISPERX_ALIGNMENT_LANGUAGES="zh en" services/whisperx/.venv/bin/hypit-whisperx-prepare
-HYPIT_WHISPERX_ALIGNMENT_LANGUAGES="zh en" services/whisperx/.venv/bin/hypit-whisperx-check --models
+uv sync --project packages/provider-whisperx-local/runtime --frozen
+HYPIT_WHISPERX_ALIGNMENT_LANGUAGES="zh en" packages/provider-whisperx-local/runtime/.venv/bin/hypit-whisperx-prepare
+HYPIT_WHISPERX_ALIGNMENT_LANGUAGES="zh en" packages/provider-whisperx-local/runtime/.venv/bin/hypit-whisperx-check --models
```
`hypit-whisperx-prepare` explicitly prepares the selected ASR model, language alignment weights and
@@ -51,7 +51,7 @@ selected language's sentence data. The example shell paths are POSIX; Windows en
## Run
```bash
-services/whisperx/.venv/bin/hypit-whisperx-service
+packages/provider-whisperx-local/runtime/.venv/bin/hypit-whisperx-service
curl http://127.0.0.1:8765/health
```
diff --git a/services/whisperx/deploy/hypit-whisperx.service.example b/packages/provider-whisperx-local/runtime/deploy/hypit-whisperx.service.example
similarity index 78%
rename from services/whisperx/deploy/hypit-whisperx.service.example
rename to packages/provider-whisperx-local/runtime/deploy/hypit-whisperx.service.example
index 4d55d879..ae4998c3 100644
--- a/services/whisperx/deploy/hypit-whisperx.service.example
+++ b/packages/provider-whisperx-local/runtime/deploy/hypit-whisperx.service.example
@@ -18,8 +18,8 @@ Environment=TORCH_FORCE_NO_WEIGHTS_ONLY_LOAD=1
Environment=HTTP_PROXY=
Environment=HTTPS_PROXY=
Environment=ALL_PROXY=
-ExecStartPre=/opt/hypit/services/whisperx/.venv/bin/hypit-whisperx-check
-ExecStart=/opt/hypit/services/whisperx/.venv/bin/hypit-whisperx-service
+ExecStartPre=/opt/hypit/packages/provider-whisperx-local/runtime/.venv/bin/hypit-whisperx-check
+ExecStart=/opt/hypit/packages/provider-whisperx-local/runtime/.venv/bin/hypit-whisperx-service
Restart=on-failure
RestartSec=5
TimeoutStopSec=30
diff --git a/services/whisperx/pyproject.toml b/packages/provider-whisperx-local/runtime/pyproject.toml
similarity index 100%
rename from services/whisperx/pyproject.toml
rename to packages/provider-whisperx-local/runtime/pyproject.toml
diff --git a/services/whisperx/src/hypit_whisperx_service/__init__.py b/packages/provider-whisperx-local/runtime/src/hypit_whisperx_service/__init__.py
similarity index 100%
rename from services/whisperx/src/hypit_whisperx_service/__init__.py
rename to packages/provider-whisperx-local/runtime/src/hypit_whisperx_service/__init__.py
diff --git a/services/whisperx/src/hypit_whisperx_service/__main__.py b/packages/provider-whisperx-local/runtime/src/hypit_whisperx_service/__main__.py
similarity index 100%
rename from services/whisperx/src/hypit_whisperx_service/__main__.py
rename to packages/provider-whisperx-local/runtime/src/hypit_whisperx_service/__main__.py
diff --git a/services/whisperx/src/hypit_whisperx_service/application.py b/packages/provider-whisperx-local/runtime/src/hypit_whisperx_service/application.py
similarity index 100%
rename from services/whisperx/src/hypit_whisperx_service/application.py
rename to packages/provider-whisperx-local/runtime/src/hypit_whisperx_service/application.py
diff --git a/services/whisperx/src/hypit_whisperx_service/audio.py b/packages/provider-whisperx-local/runtime/src/hypit_whisperx_service/audio.py
similarity index 100%
rename from services/whisperx/src/hypit_whisperx_service/audio.py
rename to packages/provider-whisperx-local/runtime/src/hypit_whisperx_service/audio.py
diff --git a/services/whisperx/src/hypit_whisperx_service/check.py b/packages/provider-whisperx-local/runtime/src/hypit_whisperx_service/check.py
similarity index 100%
rename from services/whisperx/src/hypit_whisperx_service/check.py
rename to packages/provider-whisperx-local/runtime/src/hypit_whisperx_service/check.py
diff --git a/services/whisperx/src/hypit_whisperx_service/config.py b/packages/provider-whisperx-local/runtime/src/hypit_whisperx_service/config.py
similarity index 100%
rename from services/whisperx/src/hypit_whisperx_service/config.py
rename to packages/provider-whisperx-local/runtime/src/hypit_whisperx_service/config.py
diff --git a/services/whisperx/src/hypit_whisperx_service/engine.py b/packages/provider-whisperx-local/runtime/src/hypit_whisperx_service/engine.py
similarity index 98%
rename from services/whisperx/src/hypit_whisperx_service/engine.py
rename to packages/provider-whisperx-local/runtime/src/hypit_whisperx_service/engine.py
index 74bbb032..e6204a49 100644
--- a/services/whisperx/src/hypit_whisperx_service/engine.py
+++ b/packages/provider-whisperx-local/runtime/src/hypit_whisperx_service/engine.py
@@ -100,7 +100,7 @@ class WhisperXEngine:
import whisperx as whisperx_module
except ImportError as error:
raise RuntimeError(
- "WhisperX runtime is unavailable; run `uv sync --project services/whisperx --frozen`"
+ "WhisperX runtime is unavailable; prepare the selected local WhisperX Provider"
) from error
self._numpy = numpy_module
self._whisperx = whisperx_module
diff --git a/services/whisperx/src/hypit_whisperx_service/models.py b/packages/provider-whisperx-local/runtime/src/hypit_whisperx_service/models.py
similarity index 100%
rename from services/whisperx/src/hypit_whisperx_service/models.py
rename to packages/provider-whisperx-local/runtime/src/hypit_whisperx_service/models.py
diff --git a/services/whisperx/src/hypit_whisperx_service/prepare.py b/packages/provider-whisperx-local/runtime/src/hypit_whisperx_service/prepare.py
similarity index 100%
rename from services/whisperx/src/hypit_whisperx_service/prepare.py
rename to packages/provider-whisperx-local/runtime/src/hypit_whisperx_service/prepare.py
diff --git a/services/whisperx/src/hypit_whisperx_service/resources.py b/packages/provider-whisperx-local/runtime/src/hypit_whisperx_service/resources.py
similarity index 100%
rename from services/whisperx/src/hypit_whisperx_service/resources.py
rename to packages/provider-whisperx-local/runtime/src/hypit_whisperx_service/resources.py
diff --git a/services/whisperx/src/hypit_whisperx_service/server.py b/packages/provider-whisperx-local/runtime/src/hypit_whisperx_service/server.py
similarity index 100%
rename from services/whisperx/src/hypit_whisperx_service/server.py
rename to packages/provider-whisperx-local/runtime/src/hypit_whisperx_service/server.py
diff --git a/services/whisperx/uv.lock b/packages/provider-whisperx-local/runtime/uv.lock
similarity index 100%
rename from services/whisperx/uv.lock
rename to packages/provider-whisperx-local/runtime/uv.lock
diff --git a/packages/provider-whisperx-local/src/activation.ts b/packages/provider-whisperx-local/src/activation.ts
index f17d8ec5..2182cd45 100644
--- a/packages/provider-whisperx-local/src/activation.ts
+++ b/packages/provider-whisperx-local/src/activation.ts
@@ -5,7 +5,7 @@ import {
runtimeConfigObject,
runtimeConfigPositiveInteger,
runtimeConfigString,
-} from "@hypit/runtime-kit";
+} from "@hypit/runtime-local/extension";
import { createLocalWhisperXProvider, localWhisperXDefaults } from "./provider.js";
import { localWhisperXProgram } from "./program.js";
@@ -95,8 +95,8 @@ const localWhisperXRuntimeAdapter = createRuntimeEndpointAdapterFacet({
});
export const hypitPackage = {
- format: "hypit.node-package@1" as const,
- hostFacets: [localWhisperXRuntimeAdapter],
+ format: "hypit.package@1" as const,
+ facets: [localWhisperXRuntimeAdapter],
};
export default hypitPackage;
diff --git a/packages/provider-whisperx-local/src/program.ts b/packages/provider-whisperx-local/src/program.ts
index 26c5ac31..e15d49d5 100644
--- a/packages/provider-whisperx-local/src/program.ts
+++ b/packages/provider-whisperx-local/src/program.ts
@@ -1,14 +1,14 @@
import { execFile } from "node:child_process";
import { existsSync } from "node:fs";
import { join } from "node:path";
+import { fileURLToPath } from "node:url";
-import { resolveNodePackageResource } from "@hypit/package-loader-node";
import type {
ManagedProgram,
ManagedProgramCommand,
ManagedProgramState,
-} from "@hypit/runtime-kit";
-import { pythonEnvironmentCommand } from "@hypit/runtime-host-node";
+} from "@hypit/runtime-local/extension";
+import { pythonEnvironmentCommand } from "@hypit/runtime-local/node";
/**
* WhisperX loads multi-gigabyte weights before it can answer, so it is a warm
@@ -20,10 +20,7 @@ import { pythonEnvironmentCommand } from "@hypit/runtime-host-node";
* program home, while this read-only project remains replaceable Distribution
* input. A custom service command transfers process ownership to that deployment.
*/
-export const localWhisperXManagedProject = join(
- resolveNodePackageResource("@hypit/whisperx-service-runtime", "pyproject.toml", { from: import.meta.url }),
- "..",
-);
+export const localWhisperXManagedProject = fileURLToPath(new URL("../runtime", import.meta.url));
function run(command: ManagedProgramCommand): Promise<{ readonly ok: boolean; readonly output: string }> {
return new Promise((resolve) => {
diff --git a/packages/provider-whisperx-local/src/provider.ts b/packages/provider-whisperx-local/src/provider.ts
index 99c37d3b..86fa0697 100644
--- a/packages/provider-whisperx-local/src/provider.ts
+++ b/packages/provider-whisperx-local/src/provider.ts
@@ -1,12 +1,12 @@
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
-import { sealAlignedTranscriptEvidence, speechEvidenceTypes } from "@hypit/speech-evidence";
-import type { AlignedTranscriptEvidence } from "@hypit/speech-evidence";
-import type { EndpointInvocationContext, EndpointFulfillment } from "@hypit/endpoint-kit";
-import { canonicalize } from "@hypit/protocol";
-import type { CanonicalValue } from "@hypit/protocol";
-import { defineEndpointPackage } from "@hypit/endpoint-kit";
+import { sealAlignedTranscriptEvidence, speechEvidenceTypes } from "@hypit/hypit/speech-evidence";
+import type { AlignedTranscriptEvidence } from "@hypit/hypit/speech-evidence";
+import type { EndpointInvocationContext, EndpointFulfillment } from "@hypit/hypit/endpoint";
+import { canonicalize } from "@hypit/hypit/protocol";
+import type { CanonicalValue } from "@hypit/hypit/protocol";
+import { defineEndpoint } from "@hypit/hypit/endpoint";
import {
assertWhisperXEvidenceWav,
interpretWhisperXTranscript,
@@ -119,9 +119,7 @@ export function createLocalWhisperXProvider(config: CreateLocalWhisperXProviderO
const requestTimeoutMs = positiveInteger(config.requestTimeoutMs ?? 10 * 60_000, "requestTimeoutMs");
const maxResponseBytes = positiveInteger(config.maxResponseBytes ?? 64 * 1024 * 1024, "maxResponseBytes");
- return defineEndpointPackage({
- module: localWhisperXProviderModuleRef,
- facet: "alignment",
+ return defineEndpoint({
instance: config.instance ?? "whisperx.local",
pool: config.pool ?? config.instance ?? "whisperx.local",
pricing: { kind: "local" },
diff --git a/packages/provider-whisperx-local/test/provider.test.ts b/packages/provider-whisperx-local/test/provider.test.ts
index 36262212..1c8a3fb8 100644
--- a/packages/provider-whisperx-local/test/provider.test.ts
+++ b/packages/provider-whisperx-local/test/provider.test.ts
@@ -2,7 +2,7 @@ import { readFile } from "node:fs/promises";
import test from "node:test";
import { sealSpeechEvidenceAudio, speechEvidenceTypes } from "@hypit/speech-evidence";
import assert from "node:assert/strict";
-import { MemoryResourceStore, EndpointRegistry } from "@hypit/driver-node";
+import { MemoryResourceStore, EndpointRegistry } from "@hypit/executor";
import type { Need } from "@hypit/protocol";
import {
whisperXCapabilities,
diff --git a/services/whisperx/tests/test_models.py b/packages/provider-whisperx-local/test/service/test_models.py
similarity index 97%
rename from services/whisperx/tests/test_models.py
rename to packages/provider-whisperx-local/test/service/test_models.py
index c37f702a..01b4e63f 100644
--- a/services/whisperx/tests/test_models.py
+++ b/packages/provider-whisperx-local/test/service/test_models.py
@@ -6,7 +6,7 @@ import unittest
from pathlib import Path
from unittest.mock import patch
-sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
+sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "runtime" / "src"))
from hypit_whisperx_service.config import ServiceConfig
from hypit_whisperx_service.models import asr_path, use_local_resources_only, alignment_selection
from hypit_whisperx_service.engine import WhisperXEngine, InferenceInputError
diff --git a/services/whisperx/tests/test_service.py b/packages/provider-whisperx-local/test/service/test_service.py
similarity index 99%
rename from services/whisperx/tests/test_service.py
rename to packages/provider-whisperx-local/test/service/test_service.py
index 353457aa..c724378b 100644
--- a/services/whisperx/tests/test_service.py
+++ b/packages/provider-whisperx-local/test/service/test_service.py
@@ -9,7 +9,7 @@ import unittest
import wave
-sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
+sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "runtime" / "src"))
from hypit_whisperx_service import PROTOCOL, SERVICE_VERSION # noqa: E402
from hypit_whisperx_service.application import RequestError, WhisperXApplication # noqa: E402
diff --git a/packages/resource-store-fs/README.md b/packages/resource-store-fs/README.md
deleted file mode 100644
index 672a449c..00000000
--- a/packages/resource-store-fs/README.md
+++ /dev/null
@@ -1,13 +0,0 @@
-# `@hypit/resource-store-fs`
-
-Filesystem implementation of the Runtime's transient byte port. The local Runtime gives each Build
-its own working directory and removes it after the project Build Result has accepted the public
-Outputs.
-
-The Runtime Profile does not select this package or its path. It stores no Build Result, credentials
-or author source. Code embedding the Runtime directly may still construct `FileResourceStore`.
-
-Read and write methods accept `{ signal }`. Reads close their file stream on cancellation; writes
-close the file and remove the unfinished `.incoming` file before rejecting. Existing resources are
-retained. For `putStream` and `writeStream`, the caller's chunk producer observes the same signal
-while waiting for input.
diff --git a/packages/resource-store-fs/package.json b/packages/resource-store-fs/package.json
deleted file mode 100644
index 47d9c80a..00000000
--- a/packages/resource-store-fs/package.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "name": "@hypit/resource-store-fs",
- "version": "0.0.0-dev",
- "license": "SEE LICENSE IN LICENSE",
- "private": true,
- "type": "module",
- "exports": {
- ".": "./src/index.ts"
- },
- "dependencies": {
- "@hypit/protocol": "workspace:*",
- "@hypit/runtime": "workspace:*"
- }
-}
diff --git a/packages/resource-store-fs/src/index.ts b/packages/resource-store-fs/src/index.ts
deleted file mode 100644
index 2b6aeac5..00000000
--- a/packages/resource-store-fs/src/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export { FileResourceStore } from "./store.js";
-export type * from "./store.js";
diff --git a/packages/resource-store-s3/README.md b/packages/resource-store-s3/README.md
deleted file mode 100644
index 8f8e99b1..00000000
--- a/packages/resource-store-s3/README.md
+++ /dev/null
@@ -1,15 +0,0 @@
-# `@hypit/resource-store-s3`
-
-S3 implementation of the Runtime's internal byte port. It is a library for a Runtime implementation
-that deliberately embeds it; the local Runtime does not expose it as a Runtime Profile choice.
-
-This package is not a Build Result repository and is not needed for ordinary local use. A project that
-wants complete, reusable Build Results in S3 selects `@hypit/build-result-s3` instead. The injected AWS
-client owns authentication; this package stores no Build history or credentials.
-
-Resource methods accept `{ signal }` and forward it to the object client. The AWS implementation
-aborts both pending HTTP requests and response-body reads. Stream producers supplied to writes use
-the same signal. A cancelled multipart write aborts its known upload with a separate five-second
-cleanup deadline; if cleanup fails, the error includes the upload id. Completed objects are retained.
-Streaming writes require the client's create, part-upload, completion and abort methods as well as
-streaming reads. This transfer cleanup does not resume or resubmit a Build.
diff --git a/packages/resource-store-s3/package.json b/packages/resource-store-s3/package.json
deleted file mode 100644
index d0487722..00000000
--- a/packages/resource-store-s3/package.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "name": "@hypit/resource-store-s3",
- "version": "0.0.0-dev",
- "license": "SEE LICENSE IN LICENSE",
- "private": true,
- "type": "module",
- "exports": {
- ".": "./src/index.ts"
- },
- "dependencies": {
- "@aws-sdk/client-s3": "3.1103.0",
- "@hypit/protocol": "workspace:*",
- "@hypit/runtime": "workspace:*"
- }
-}
diff --git a/packages/resource-store-s3/src/client.ts b/packages/resource-store-s3/src/client.ts
deleted file mode 100644
index e5114ccc..00000000
--- a/packages/resource-store-s3/src/client.ts
+++ /dev/null
@@ -1,138 +0,0 @@
-import { addAbortSignal, Readable } from "node:stream";
-import type { ResourceIOOptions } from "@hypit/runtime";
-import {
- AbortMultipartUploadCommand,
- CompleteMultipartUploadCommand,
- CreateMultipartUploadCommand,
- GetObjectCommand,
- HeadObjectCommand,
- PutObjectCommand,
- S3Client,
- UploadPartCommand,
-} from "@aws-sdk/client-s3";
-import type {
- AbortMultipartUploadCommandInput,
- CompleteMultipartUploadCommandInput,
- CreateMultipartUploadCommandInput,
- GetObjectCommandInput,
- PutObjectCommandInput,
- S3ClientConfig,
- UploadPartCommandInput,
-} from "@aws-sdk/client-s3";
-
-/**
- * `put` and `get` are the whole port. The rest are optional: a client that
- * omits them leaves the store implementing only the ResourceStore,
- * which is exactly what the optional Streaming facet means.
- */
-export type S3ObjectClient = {
- put(input: PutObjectCommandInput, options?: ResourceIOOptions): Promise<void>;
- get(input: GetObjectCommandInput, options?: ResourceIOOptions): Promise<Uint8Array | undefined>;
- /**
- * The object's bytes as they arrive. Separate from `get` because an Artifact
- * may be a whole programme: a caller that asked to stream must not have the
- * object assembled in memory on its behalf.
- */
- open?(input: GetObjectCommandInput, options?: ResourceIOOptions): Promise<AsyncIterable<Uint8Array> | undefined>;
- /** Undefined when the key is absent. */
- head?(input: GetObjectCommandInput, options?: ResourceIOOptions): Promise<{ readonly size: number } | undefined>;
- createMultipart?(input: CreateMultipartUploadCommandInput, options?: ResourceIOOptions): Promise<string>;
- uploadPart?(input: UploadPartCommandInput, options?: ResourceIOOptions): Promise<{ readonly etag: string }>;
- completeMultipart?(input: CompleteMultipartUploadCommandInput, options?: ResourceIOOptions): Promise<void>;
- abortMultipart?(input: AbortMultipartUploadCommandInput, options?: ResourceIOOptions): Promise<void>;
-};
-
-function statusCode(error: unknown): number | undefined {
- if (typeof error !== "object" || error === null || !("$metadata" in error)) return undefined;
- const metadata = error.$metadata;
- if (typeof metadata !== "object" || metadata === null || !("httpStatusCode" in metadata)) return undefined;
- return typeof metadata.httpStatusCode === "number" ? metadata.httpStatusCode : undefined;
-}
-
-function absent(error: unknown): boolean {
- return statusCode(error) === 404
- || (error instanceof Error && (error.name === "NoSuchKey" || error.name === "NotFound"));
-}
-
-export class AwsS3ObjectClient implements S3ObjectClient {
- readonly #client: S3Client;
-
- constructor(config: S3ClientConfig = {}) {
- // Credentials come from the SDK default chain and are never rebuilt here
- // from AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY. A managed runtime also
- // injects AWS_SESSION_TOKEN, and a hand-assembled two-field credential
- // object silently drops it — every request then fails InvalidAccessKeyId.
- this.#client = new S3Client(config);
- }
-
- async put(input: PutObjectCommandInput, options: ResourceIOOptions = {}): Promise<void> {
- await this.#client.send(new PutObjectCommand(input), (options.signal === undefined ? {} : { abortSignal: options.signal }));
- }
-
- async get(input: GetObjectCommandInput, options: ResourceIOOptions = {}): Promise<Uint8Array | undefined> {
- const source = await this.open(input, options);
- if (source === undefined) return undefined;
- const chunks: Uint8Array[] = [];
- for await (const chunk of source) chunks.push(chunk);
- return Uint8Array.from(Buffer.concat(chunks));
- }
-
- async open(input: GetObjectCommandInput, options: ResourceIOOptions = {}): Promise<AsyncIterable<Uint8Array> | undefined> {
- options.signal?.throwIfAborted();
- let body: Readable;
- try {
- const response = await this.#client.send(new GetObjectCommand(input), (options.signal === undefined ? {} : { abortSignal: options.signal }));
- if (response.Body === undefined) throw new Error(`S3 object ${input.Key ?? "<unknown>"} has no body`);
- body = response.Body as Readable;
- // open() can be cancelled before its caller starts consuming the body.
- body.on("error", () => {});
- if (options.signal !== undefined) addAbortSignal(options.signal, body);
- } catch (error) {
- if (absent(error)) return undefined;
- throw error;
- }
- return (async function* () {
- try {
- for await (const chunk of body) {
- options.signal?.throwIfAborted();
- yield Uint8Array.from(chunk as Buffer);
- }
- } finally { body.destroy(); }
- })();
- }
-
- async head(input: GetObjectCommandInput, options: ResourceIOOptions = {}): Promise<{ readonly size: number } | undefined> {
- try {
- const response = await this.#client.send(new HeadObjectCommand({
- Bucket: input.Bucket,
- Key: input.Key,
- ...(input.ExpectedBucketOwner === undefined ? {} : { ExpectedBucketOwner: input.ExpectedBucketOwner }),
- }), (options.signal === undefined ? {} : { abortSignal: options.signal }));
- return { size: response.ContentLength ?? 0 };
- } catch (error) {
- if (absent(error)) return undefined;
- throw error;
- }
- }
-
- async createMultipart(input: CreateMultipartUploadCommandInput, options: ResourceIOOptions = {}): Promise<string> {
- const response = await this.#client.send(new CreateMultipartUploadCommand(input), (options.signal === undefined ? {} : { abortSignal: options.signal }));
- if (response.UploadId === undefined) throw new Error("S3 did not return a multipart upload id");
- return response.UploadId;
- }
-
- async uploadPart(input: UploadPartCommandInput, options: ResourceIOOptions = {}): Promise<{ readonly etag: string }> {
- const response = await this.#client.send(new UploadPartCommand(input), (options.signal === undefined ? {} : { abortSignal: options.signal }));
- if (response.ETag === undefined) throw new Error("S3 did not return a part ETag");
- return { etag: response.ETag };
- }
-
- async completeMultipart(input: CompleteMultipartUploadCommandInput, options: ResourceIOOptions = {}): Promise<void> {
- await this.#client.send(new CompleteMultipartUploadCommand(input), (options.signal === undefined ? {} : { abortSignal: options.signal }));
- }
-
- async abortMultipart(input: AbortMultipartUploadCommandInput, options: ResourceIOOptions = {}): Promise<void> {
- await this.#client.send(new AbortMultipartUploadCommand(input), (options.signal === undefined ? {} : { abortSignal: options.signal }));
- }
-
-}
diff --git a/packages/resource-store-s3/src/index.ts b/packages/resource-store-s3/src/index.ts
deleted file mode 100644
index 48e1d513..00000000
--- a/packages/resource-store-s3/src/index.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-export { AwsS3ObjectClient } from "./client.js";
-export type { S3ObjectClient } from "./client.js";
-export {
- S3ResourceStore,
- createS3ResourceStore,
- normalizeS3ResourcePrefix,
- s3ResourceKey,
- s3ResourceStoreModuleRef,
-} from "./store.js";
-export type * from "./store.js";
diff --git a/packages/resource-store-s3/src/store.ts b/packages/resource-store-s3/src/store.ts
deleted file mode 100644
index e710d75a..00000000
--- a/packages/resource-store-s3/src/store.ts
+++ /dev/null
@@ -1,258 +0,0 @@
-import { randomUUID } from "node:crypto";
-
-import { isResourceId } from "@hypit/protocol";
-import type { BlobRef, ResourceId } from "@hypit/protocol";
-import type { ResourceIOOptions, ResourceStore } from "@hypit/runtime";
-
-import { AwsS3ObjectClient } from "./client.js";
-import type { S3ObjectClient } from "./client.js";
-
-export const s3ResourceStoreModuleRef = {
- name: "@hypit/resource-store-s3",
- version: "1",
-} as const;
-
-export function normalizeS3ResourcePrefix(prefix: string | undefined): string {
- if (prefix === undefined || prefix.length === 0) return "";
- const normalized = prefix.replace(/^\/+|\/+$/gu, "");
- assert(normalized.length > 0, "S3 Resource prefix must contain a non-slash character");
- assert(!normalized.split("/").some((part) => part === "." || part === ".."),
- "S3 Resource prefix cannot contain dot path segments");
- return normalized;
-}
-
-export function s3ResourceKey(prefix: string | undefined, resource: ResourceId): string {
- if (!isResourceId(resource)) throw new Error("Resource id is invalid");
- const normalized = normalizeS3ResourcePrefix(prefix);
- const relative = `resources/${resource}`;
- return normalized.length === 0 ? relative : `${normalized}/${relative}`;
-}
-
-type S3Location = {
- readonly bucket: string;
- readonly prefix?: string;
- readonly expectedBucketOwner?: string;
-};
-
-export type S3ResourceStoreOptions = S3Location & {
- readonly client: S3ObjectClient;
- readonly partSizeBytes?: number;
-};
-
-export type CreateS3ResourceStorePackageOptions = S3Location & {
- readonly instance?: string;
- readonly partSizeBytes?: number;
- readonly region?: string;
- readonly endpoint?: string;
- readonly forcePathStyle?: boolean;
- readonly client?: S3ObjectClient;
-};
-
-function assert(condition: unknown, message: string): asserts condition {
- if (!condition) throw new Error(message);
-}
-
-function positiveInteger(value: number, subject: string): number {
- assert(Number.isSafeInteger(value) && value > 0, `${subject} must be a positive safe integer`);
- return value;
-}
-
-/** Optional S3 byte store for Runtime implementations that deliberately embed it. */
-export class S3ResourceStore implements ResourceStore {
- readonly #client: S3ObjectClient;
- readonly #bucket: string;
- readonly #prefix: string;
- readonly #expectedBucketOwner: string | undefined;
- readonly #partSizeBytes: number;
- readonly open?: (resource: ResourceId, options?: ResourceIOOptions) => Promise<AsyncIterable<Uint8Array> | undefined>;
- readonly putStream?: (chunks: AsyncIterable<Uint8Array>, mediaType: string, options?: ResourceIOOptions) => Promise<BlobRef>;
- readonly writeStream?: (resource: BlobRef, chunks: AsyncIterable<Uint8Array>, options?: ResourceIOOptions) => Promise<void>;
-
- constructor(options: S3ResourceStoreOptions) {
- assert(options.bucket.trim().length > 0, "S3 Resource bucket must not be empty");
- if (options.expectedBucketOwner !== undefined) {
- assert(options.expectedBucketOwner.trim().length > 0, "expected S3 bucket owner must not be empty");
- }
- this.#client = options.client;
- this.#bucket = options.bucket;
- this.#prefix = normalizeS3ResourcePrefix(options.prefix);
- this.#expectedBucketOwner = options.expectedBucketOwner;
- this.#partSizeBytes = positiveInteger(options.partSizeBytes ?? 16 * 1024 * 1024, "partSizeBytes");
- assert(this.#partSizeBytes >= 5 * 1024 * 1024, "S3 requires multipart parts of at least 5 MiB");
- const client = options.client;
- if (client.open !== undefined && client.createMultipart !== undefined && client.uploadPart !== undefined
- && client.completeMultipart !== undefined && client.abortMultipart !== undefined) {
- this.open = (resource, options = {}) => this.#openStream(resource, options);
- this.putStream = (chunks, mediaType, options = {}) => this.#putStream(chunks, mediaType, options);
- this.writeStream = async (resource, chunks, options = {}) => {
- await this.#storeStream(resource.resource, chunks, resource.mediaType, options, resource.size);
- };
- }
- }
-
- key(resource: ResourceId): string {
- return s3ResourceKey(this.#prefix, resource);
- }
-
- #owner(): { readonly ExpectedBucketOwner?: string } {
- return this.#expectedBucketOwner === undefined ? {} : { ExpectedBucketOwner: this.#expectedBucketOwner };
- }
-
- async put(bytes: Uint8Array, mediaType: string, options: ResourceIOOptions = {}): Promise<BlobRef> {
- assert(mediaType.trim().length > 0, "Resource mediaType must not be empty");
- options.signal?.throwIfAborted();
- const copy = Uint8Array.from(bytes);
- const resource = `res_${randomUUID()}` as ResourceId;
- await this.#client.put({
- Bucket: this.#bucket,
- Key: this.key(resource),
- Body: copy,
- ContentLength: copy.byteLength,
- ContentType: mediaType,
- ...this.#owner(),
- }, options);
- return { kind: "blob", resource, size: copy.byteLength, mediaType };
- }
-
- async write(resource: BlobRef, bytes: Uint8Array, options: ResourceIOOptions = {}): Promise<void> {
- options.signal?.throwIfAborted();
- const copy = Uint8Array.from(bytes);
- assert(copy.byteLength === resource.size,
- `Resource ${resource.resource} has size ${copy.byteLength}, expected ${resource.size}`);
- await this.#client.put({
- Bucket: this.#bucket,
- Key: this.key(resource.resource),
- Body: copy,
- ContentLength: copy.byteLength,
- ContentType: resource.mediaType,
- ...this.#owner(),
- }, options);
- }
-
- async get(resource: ResourceId, options: ResourceIOOptions = {}): Promise<Uint8Array | undefined> {
- options.signal?.throwIfAborted();
- const bytes = await this.#client.get({
- Bucket: this.#bucket,
- Key: this.key(resource),
- ...this.#owner(),
- }, options);
- return bytes === undefined ? undefined : Uint8Array.from(bytes);
- }
-
- async has(resource: ResourceId, options: ResourceIOOptions = {}): Promise<boolean> {
- options.signal?.throwIfAborted();
- if (this.#client.head === undefined) {
- return await this.#client.get({ Bucket: this.#bucket, Key: this.key(resource), ...this.#owner() }, options) !== undefined;
- }
- return await this.#client.head({ Bucket: this.#bucket, Key: this.key(resource), ...this.#owner() }, options) !== undefined;
- }
-
- async #openStream(resource: ResourceId, options: ResourceIOOptions = {}): Promise<AsyncIterable<Uint8Array> | undefined> {
- options.signal?.throwIfAborted();
- return await this.#client.open!({
- Bucket: this.#bucket,
- Key: this.key(resource),
- ...this.#owner(),
- }, options);
- }
-
- async #putStream(chunks: AsyncIterable<Uint8Array>, mediaType: string, options: ResourceIOOptions = {}): Promise<BlobRef> {
- assert(mediaType.trim().length > 0, "Resource mediaType must not be empty");
- const resource = `res_${randomUUID()}` as ResourceId;
- const size = await this.#storeStream(resource, chunks, mediaType, options);
- return { kind: "blob", resource, size, mediaType };
- }
-
- async #storeStream(
- resource: ResourceId,
- chunks: AsyncIterable<Uint8Array>,
- mediaType: string,
- options: ResourceIOOptions,
- expectedSize?: number,
- ): Promise<number> {
- options.signal?.throwIfAborted();
- const client = this.#client as Required<Pick<S3ObjectClient,
- "createMultipart" | "uploadPart" | "completeMultipart">> & S3ObjectClient;
- const key = this.key(resource);
- const owner = this.#owner();
- const uploadId = await client.createMultipart({
- Bucket: this.#bucket, Key: key, ContentType: mediaType, ...owner,
- }, options);
- const parts: { PartNumber: number; ETag: string }[] = [];
- let pending: Uint8Array[] = [];
- let pendingBytes = 0;
- let size = 0;
- const flush = async (): Promise<void> => {
- options.signal?.throwIfAborted();
- if (pendingBytes === 0 && parts.length > 0) return;
- const body = new Uint8Array(pendingBytes);
- let offset = 0;
- for (const piece of pending) {
- body.set(piece, offset);
- offset += piece.byteLength;
- }
- pending = [];
- pendingBytes = 0;
- const partNumber = parts.length + 1;
- const { etag } = await client.uploadPart({
- Bucket: this.#bucket, Key: key, UploadId: uploadId,
- PartNumber: partNumber, Body: body, ContentLength: body.byteLength, ...owner,
- }, options);
- parts.push({ PartNumber: partNumber, ETag: etag });
- };
- try {
- for await (const value of chunks) {
- options.signal?.throwIfAborted();
- if (!(value instanceof Uint8Array)) throw new Error("Resource stream yielded non-bytes");
- const chunk = Uint8Array.from(value);
- size += chunk.byteLength;
- if (!Number.isSafeInteger(size)) throw new Error("Resource stream exceeds the supported size");
- let offset = 0;
- while (offset < chunk.byteLength) {
- const take = Math.min(this.#partSizeBytes - pendingBytes, chunk.byteLength - offset);
- pending.push(chunk.slice(offset, offset + take));
- pendingBytes += take;
- offset += take;
- if (pendingBytes === this.#partSizeBytes) await flush();
- }
- }
- if (pendingBytes > 0 || parts.length === 0) await flush();
- if (expectedSize !== undefined && size !== expectedSize) {
- throw new Error(`Resource ${resource} has size ${size}, expected ${expectedSize}`);
- }
- options.signal?.throwIfAborted();
- await client.completeMultipart({
- Bucket: this.#bucket, Key: key, UploadId: uploadId,
- MultipartUpload: { Parts: parts }, ...owner,
- }, options);
- return size;
- } catch (error) {
- try {
- await client.abortMultipart!({
- Bucket: this.#bucket, Key: key, UploadId: uploadId, ...owner,
- }, { signal: AbortSignal.timeout(5_000) });
- } catch (cleanupError) {
- throw new Error(`${String(error)}; S3 multipart cleanup failed for ${uploadId}: ${String(cleanupError)}`, { cause: error });
- }
- throw error;
- }
- }
-}
-
-export function createS3ResourceStore(
- options: CreateS3ResourceStorePackageOptions,
-): S3ResourceStore {
- const prefix = normalizeS3ResourcePrefix(options.prefix);
- const client = options.client ?? new AwsS3ObjectClient({
- ...(options.region === undefined ? {} : { region: options.region }),
- ...(options.endpoint === undefined ? {} : { endpoint: options.endpoint }),
- ...(options.forcePathStyle === undefined ? {} : { forcePathStyle: options.forcePathStyle }),
- });
- return new S3ResourceStore({
- client,
- bucket: options.bucket,
- ...(options.partSizeBytes === undefined ? {} : { partSizeBytes: options.partSizeBytes }),
- ...(prefix.length === 0 ? {} : { prefix }),
- ...(options.expectedBucketOwner === undefined ? {} : { expectedBucketOwner: options.expectedBucketOwner }),
- });
-}
diff --git a/packages/resource-store-s3/test/store.test.ts b/packages/resource-store-s3/test/store.test.ts
deleted file mode 100644
index 8db89871..00000000
--- a/packages/resource-store-s3/test/store.test.ts
+++ /dev/null
@@ -1,191 +0,0 @@
-import assert from "node:assert/strict";
-import test from "node:test";
-import { createServer } from "node:http";
-import { once } from "node:events";
-import { setTimeout as delay } from "node:timers/promises";
-
-import { S3ResourceStore } from "@hypit/resource-store-s3";
-import type { S3ObjectClient } from "@hypit/resource-store-s3";
-import { isStreamingResourceStore } from "@hypit/runtime";
-import type { ResourceIOOptions } from "@hypit/runtime";
-import { AwsS3ObjectClient } from "../src/client.js";
-
-test("cancelling an S3 body read closes the actual HTTP transfer", async () => {
- let reached!: () => void;
- let disconnected!: () => void;
- const received = new Promise<void>((resolve) => { reached = resolve; });
- const closed = new Promise<void>((resolve) => { disconnected = resolve; });
- const server = createServer((_request, response) => {
- response.writeHead(200, { "Content-Length": "100000", "Content-Type": "application/octet-stream" });
- response.write(Buffer.from([1]));
- response.once("close", disconnected);
- reached();
- });
- server.listen(0, "127.0.0.1");
- await once(server, "listening");
- const address = server.address();
- assert.ok(address !== null && typeof address !== "string");
- const controller = new AbortController();
- try {
- const store = new S3ResourceStore({ bucket: "fixture", client: new AwsS3ObjectClient({
- endpoint: `http://127.0.0.1:${address.port}`, region: "us-east-1", forcePathStyle: true,
- credentials: { accessKeyId: "local-test", secretAccessKey: "local-test" },
- }) });
- const source = await store.open!("res_stalled", { signal: controller.signal });
- assert.ok(source !== undefined);
- const iterator = source[Symbol.asyncIterator]();
- assert.deepEqual((await iterator.next()).value, new Uint8Array([1]));
- const rejected = assert.rejects(iterator.next());
- await received;
- controller.abort(new Error("transfer stopped"));
- await rejected;
- await closed;
- } finally { server.closeAllConnections(); await new Promise<void>((resolve) => server.close(() => resolve())); }
-});
-
-class FakeS3 implements S3ObjectClient {
- readonly values = new Map<string, Uint8Array>();
- gets = 0;
-
- async put(input: Parameters<S3ObjectClient["put"]>[0]): Promise<void> {
- const key = input.Key!;
- assert.ok(input.Body instanceof Uint8Array);
- this.values.set(key, Uint8Array.from(input.Body));
- }
-
- async get(input: Parameters<S3ObjectClient["get"]>[0]): Promise<Uint8Array | undefined> {
- this.gets += 1;
- const value = this.values.get(input.Key!);
- return value === undefined ? undefined : Uint8Array.from(value);
- }
-}
-
-test("S3 resources use independent execution-local keys", async () => {
- const client = new FakeS3();
- const store = new S3ResourceStore({ client, bucket: "fixture", prefix: "projects/acme" });
- const bytes = new TextEncoder().encode("one immutable remote artifact");
- const first = await store.put(bytes, "video/mp4");
- const second = await store.put(bytes, "video/mp4");
- assert.notEqual(first.resource, second.resource);
- assert.match(store.key(first.resource), /^projects\/acme\/resources\/res_/u);
- assert.deepEqual(await store.get(first.resource), bytes);
-});
-
-/** A client that can do everything, backed by an in-memory bucket. */
-class FullFakeS3 extends FakeS3 {
- readonly uploads = new Map<string, Uint8Array[]>();
- heads = 0;
-
- async open(input: Parameters<NonNullable<S3ObjectClient["open"]>>[0]) {
- const value = this.values.get(input.Key!);
- if (value === undefined) return undefined;
- // Two chunks, so a consumer cannot assume one whole-object read.
- const half = Math.ceil(value.byteLength / 2);
- return (async function* () {
- yield Uint8Array.from(value.subarray(0, half));
- yield Uint8Array.from(value.subarray(half));
- })();
- }
-
- async head(input: Parameters<NonNullable<S3ObjectClient["head"]>>[0]) {
- this.heads += 1;
- const value = this.values.get(input.Key!);
- return value === undefined ? undefined : { size: value.byteLength };
- }
-
- async createMultipart(input: Parameters<NonNullable<S3ObjectClient["createMultipart"]>>[0]) {
- const id = `upload-${this.uploads.size + 1}`;
- this.uploads.set(`${id}:${input.Key!}`, []);
- return id;
- }
-
- async uploadPart(input: Parameters<NonNullable<S3ObjectClient["uploadPart"]>>[0]) {
- const parts = this.uploads.get(`${input.UploadId!}:${input.Key!}`)!;
- parts[input.PartNumber! - 1] = Uint8Array.from(input.Body as Uint8Array);
- return { etag: `"etag-${input.PartNumber}"` };
- }
-
- async completeMultipart(input: Parameters<NonNullable<S3ObjectClient["completeMultipart"]>>[0]) {
- const parts = this.uploads.get(`${input.UploadId!}:${input.Key!}`)!;
- const size = parts.reduce((total, part) => total + part.byteLength, 0);
- const joined = new Uint8Array(size);
- let offset = 0;
- for (const part of parts) {
- joined.set(part, offset);
- offset += part.byteLength;
- }
- this.values.set(input.Key!, joined);
- }
-
- async abortMultipart() {}
-
-}
-
-test("cancelled S3 uploads abort their multipart transfer with a fresh cleanup signal", async () => {
- const controller = new AbortController();
- let aborted = false;
- class InterruptedS3 extends FullFakeS3 {
- override async uploadPart(_input: Parameters<NonNullable<S3ObjectClient["uploadPart"]>>[0], options: ResourceIOOptions = {}): Promise<{ etag: string }> {
- controller.abort(new Error("stop upload"));
- await delay(60_000, undefined, { signal: options.signal });
- throw new Error("unexpected completion");
- }
- override async abortMultipart(_input?: unknown, options: ResourceIOOptions = {}) {
- assert.equal(options.signal?.aborted, false);
- aborted = true;
- }
- }
- const client = new InterruptedS3();
- const store = new S3ResourceStore({ client, bucket: "fixture" });
- await assert.rejects(store.putStream!((async function* () { yield new Uint8Array([1]); })(),
- "video/mp4", { signal: controller.signal }));
- assert.equal(aborted, true);
- assert.equal(client.values.size, 0);
-});
-
-test("streaming is exposed only when the client supports it", () => {
- const store = new S3ResourceStore({ client: new FakeS3(), bucket: "fixture" });
- assert.equal(isStreamingResourceStore(store), false);
- const full = new S3ResourceStore({ client: new FullFakeS3(), bucket: "fixture" });
- assert.equal(isStreamingResourceStore(full), true);
-});
-
-test("a streamed Resource reaches its declared resource key", async () => {
- const client = new FullFakeS3();
- const store = new S3ResourceStore({ client, bucket: "fixture", prefix: "svml" });
- const parts = ["first ", "second ", "third"].map((text) => new TextEncoder().encode(text));
- const ref = await store.putStream!((async function* () { yield* parts; })(), "video/mp4");
-
- const whole = new TextEncoder().encode("first second third");
- assert.equal(ref.size, whole.byteLength);
- assert.deepEqual(await store.get(ref.resource), whole);
- assert.match(store.key(ref.resource), /^svml\/resources\/res_/u);
-});
-
-test("an empty Resource is legitimate even though S3 will not accept a partless upload", async () => {
- const store = new S3ResourceStore({ client: new FullFakeS3(), bucket: "fixture" });
- const ref = await store.putStream!((async function* () {})(), "application/octet-stream");
- assert.equal(ref.size, 0);
- assert.deepEqual(await store.get(ref.resource), new Uint8Array(0));
-});
-
-test("a streamed read hands back bytes as they arrive", async () => {
- const client = new FullFakeS3();
- const store = new S3ResourceStore({ client, bucket: "fixture" });
- const bytes = new TextEncoder().encode("streamed artifact bytes");
- const ref = await store.put(bytes, "text/plain");
-
- const chunks: Uint8Array[] = [];
- for await (const chunk of (await store.open!(ref.resource))!) chunks.push(chunk);
- assert.equal(chunks.length, 2, "the stream was not assembled on the caller's behalf");
-});
-
-test("presence uses object metadata without downloading bytes", async () => {
- const client = new FullFakeS3();
- const store = new S3ResourceStore({ client, bucket: "fixture" });
- const ref = await store.put(new TextEncoder().encode("present"), "text/plain");
- const gets = client.gets;
- assert.equal(await store.has(ref.resource), true);
- assert.equal(client.heads, 1);
- assert.equal(client.gets, gets, "has did not download the object");
-});
diff --git a/packages/runtime-host-node/README.md b/packages/runtime-host-node/README.md
deleted file mode 100644
index 7e558959..00000000
--- a/packages/runtime-host-node/README.md
+++ /dev/null
@@ -1,60 +0,0 @@
-# `@hypit/runtime-host-node`
-
-Node.js Runtime port shared by the generic CLI and an application's chosen Runtime implementation,
-plus environment helpers for Endpoint adapters.
-
-The package keeps Node-specific process control out of the host-neutral Runtime contracts. It provides:
-
-- project-root resolution for configured relative executable paths;
-- executable availability diagnostics for absolute, relative and `PATH` commands;
-- explicit environment-credential diagnostics.
-
-These functions produce `RuntimeDoctorDiagnostic` values only. They do not construct Endpoints,
-read secret values, execute commands or choose fallback Providers.
-
-The generic CLI depends only on this port. The official video application selects
-`@hypit/runtime-local` directly; Runtime Profiles vary credentials, Endpoints and their services
-rather than replacing the Runtime itself or selecting Build history storage. A second application
-may supply another `NodeRuntimeHost` at its Distribution assembly boundary; no unused Host plugin
-registry or selector is exposed in a local Profile.
-
-The same port lets an authoring application open a disposable transient execution. The caller hands
-over a graph state, deterministic Producers, validators and temporary Resources; the Runtime keeps
-Endpoint selection, handlers and concurrency for that disposable session private and returns the evaluated
-state. This is an execution boundary, not a second Runtime Profile, Build type, cross-Build scheduler or
-preview registry.
-
-`RuntimeHostControl.logs(build, lines)` optionally exposes a bounded tail of active Build evidence.
-Finished logs belong to `BuildResultManifest.executionLog` and are read through the project's Repository;
-reading a finished log needs no Runtime or execution Provider. Runtime process logs keep their separate
-process-control operation.
-
-`prepare`, `preflight`, `doctor` and Program lifecycle operations accept explicit Endpoint instance
-names. Build preflight uses resolved Endpoints, not every Provider offering the capability. Omitting
-a scope retains whole-Profile inspection or preparation.
-
-`prepareHostPackages` keeps exact releases in separate ordinary npm installations below the Host
-package home. `HostPackageProgress.logPath` identifies live and retained npm output; failures include
-that path. npm owns each installation's dependency tree and lockfile. No parallel package inventory is
-maintained. `RuntimeInvocationObservation` passes direct-call progress and diagnostics through the
-same Provider callbacks used in Builds, without giving immediate calls durable Operation semantics.
-
-## Execution choices and lifetime
-
-`createRuntime({ endpoints })` scopes a submission to the selected Endpoint instances. The local Host
-records those choices and its project package root with the active execution request. Its long-lived
-Worker supervises carriers with independent per-Build module and registry contexts. Managed
-Programs remain independently warm. `runWorker` accepts an internal carrier entry point; execution
-readiness and Endpoint capacity are independent of the number of unfinished Builds. Other Hosts own
-their choice of code-loading and physical execution mechanisms.
-
-Submission clients use `const controller = await host.controller(); await controller.worker.up()`
-to start execution, then `const runtime = await host.createRuntime(); await runtime.build(request)`
-to submit work. `RuntimeHostExecution` does not run a second embedded Worker loop. A local carrier
-may stop accepting new Builds and drain; its assigned Builds stay in place and all carriers continue
-using the same resource accounting. Process policy belongs to the local Runtime, not this Host ABI.
-
-`prepareHostPackages` accepts exact specifier strings or `{ specifier, env }` installation inputs.
-The optional environment is applied only to that npm child process, merged over its inherited
-environment. It is neither persisted as installation status nor returned in package reports.
-The shared installer does not interpret SDK-specific variables; their owning packages supply them.
diff --git a/packages/runtime-host-node/package.json b/packages/runtime-host-node/package.json
deleted file mode 100644
index f4b97360..00000000
--- a/packages/runtime-host-node/package.json
+++ /dev/null
@@ -1,20 +0,0 @@
-{
- "name": "@hypit/runtime-host-node",
- "version": "0.0.0-dev",
- "license": "SEE LICENSE IN LICENSE",
- "private": true,
- "type": "module",
- "exports": {
- ".": "./src/index.ts"
- },
- "dependencies": {
- "@hypit/build-result": "workspace:*",
- "@hypit/build-result-kit": "workspace:*",
- "@hypit/driver-node": "workspace:*",
- "@hypit/package-loader-node": "workspace:*",
- "@hypit/protocol": "workspace:*",
- "@hypit/runtime": "workspace:*",
- "@hypit/runtime-kit": "workspace:*",
- "@hypit/workspace": "workspace:*"
- }
-}
diff --git a/packages/runtime-host-node/src/packages.ts b/packages/runtime-host-node/src/packages.ts
deleted file mode 100644
index 87cfec8e..00000000
--- a/packages/runtime-host-node/src/packages.ts
+++ /dev/null
@@ -1,161 +0,0 @@
-import { spawn } from "node:child_process";
-import { mkdir, open, readFile, realpath, writeFile } from "node:fs/promises";
-import { join, resolve } from "node:path";
-import { externalPackageInstallRoot } from "@hypit/package-loader-node";
-
-export type RegistryPackageSpec = {
- readonly name: string;
- readonly version: string;
- readonly specifier: string;
-};
-
-export type HostPackageReport = RegistryPackageSpec & {
- readonly root: string;
- readonly logPath?: string;
- readonly action: "already-installed" | "installed";
-};
-
-export type HostPackageProgress = RegistryPackageSpec & {
- readonly phase: "checking" | "installing" | "ready";
- readonly logPath?: string;
-};
-
-function exactVersion(value: string): boolean {
- return /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/u.test(value);
-}
-
-/** Registry packages are pinned by version; npm owns their files and dependency graph. */
-export function parseRegistryPackageSpec(specifier: string): RegistryPackageSpec {
- const value = specifier.trim();
- const slash = value.startsWith("@") ? value.indexOf("/", 1) : -1;
- const at = value.lastIndexOf("@");
- const split = value.startsWith("@") ? (at > slash ? at : -1) : at;
- const name = split > 0 ? value.slice(0, split) : "";
- const version = split > 0 ? value.slice(split + 1) : "";
- if (name.length === 0 || name.startsWith("@hypit/") || !exactVersion(version)) {
- throw new Error(
- `${specifier} must name one external npm registry package at an exact version, for example [email protected]`,
- );
- }
- if (name.startsWith("@") && (slash < 2 || slash >= name.length - 1)) {
- throw new Error(`${specifier} is not a valid scoped npm package specifier`);
- }
- if (!name.startsWith("@") && !/^[a-z0-9][a-z0-9._-]*$/u.test(name)) {
- throw new Error(`${specifier} is not a valid npm package specifier`);
- }
- return { name, version, specifier: `${name}@${version}` };
-}
-
-async function installedVersion(root: string, name: string): Promise<string | undefined> {
- try {
- const manifest = JSON.parse(await readFile(
- join(root, "node_modules", ...name.split("/"), "package.json"),
- "utf8",
- )) as { readonly name?: unknown; readonly version?: unknown };
- return manifest.name === name && typeof manifest.version === "string"
- ? manifest.version
- : undefined;
- } catch (error) {
- if (error instanceof Error && "code" in error && error.code === "ENOENT") return undefined;
- throw error;
- }
-}
-
-export async function inspectHostPackage(
- specifier: string,
- root: string,
-): Promise<HostPackageReport | undefined> {
- const required = parseRegistryPackageSpec(specifier);
- const installation = externalPackageInstallRoot(root, required.name, required.version);
- const version = await installedVersion(installation, required.name);
- return version === required.version
- ? { ...required, root: installation, action: "already-installed" }
- : undefined;
-}
-
-async function runNpm(root: string, specifiers: readonly string[], logPath: string, env?: Readonly<Record<string, string>>): Promise<void> {
- // npm's prefix and cwd must denote the same physical project (not /tmp vs /private/tmp).
- const cwd = await realpath(root);
- const npmArgs = [
- "install",
- "--prefix", cwd,
- "--save-exact",
- "--no-audit",
- "--no-fund",
- "--omit=dev",
- ...specifiers,
- ];
- const windows = process.platform === "win32";
- const command = windows ? (process.env.ComSpec ?? "cmd.exe") : "npm";
- const args = windows ? ["/d", "/s", "/c", "npm.cmd", ...npmArgs] : npmArgs;
- const log = await open(logPath, "a");
- await log.write(`\n${new Date().toISOString()} npm ${npmArgs.join(" ")}\n`);
- try {
- await new Promise<void>((done, reject) => {
- const child = spawn(command, args, {
- cwd,
- shell: false,
- windowsHide: true,
- env: { ...process.env, ...env },
- stdio: ["ignore", log.fd, log.fd],
- });
- child.on("error", (error) => reject(new Error(`Cannot start npm: ${error.message}. Log: ${logPath}`, { cause: error })));
- child.on("close", (code) => {
- if (code === 0) done();
- else reject(new Error(`npm install failed (exit ${code ?? "signal"}). Log: ${logPath}`));
- });
- });
- } finally {
- await log.close();
- }
-}
-
-/**
- * Reuse each exact upstream release in its own npm installation. npm owns its
- * package.json, lockfile and dependencies; Hypit keeps no parallel inventory.
- */
-export async function prepareHostPackages(
- specifiers: readonly (string | { readonly specifier: string; readonly env?: Readonly<Record<string, string>> })[],
- options: {
- readonly root: string;
- readonly onProgress?: (event: HostPackageProgress) => void;
- },
-): Promise<readonly HostPackageReport[]> {
- const root = resolve(options.root);
- const bySpecifier = new Map<string, RegistryPackageSpec & { readonly env?: Readonly<Record<string, string>> }>();
- for (const specifier of specifiers) {
- const parsed = parseRegistryPackageSpec(typeof specifier === "string" ? specifier : specifier.specifier);
- const env = { ...bySpecifier.get(parsed.specifier)?.env };
- for (const [key, value] of Object.entries(typeof specifier === "string" ? {} : specifier.env ?? {})) {
- if (env[key] !== undefined && env[key] !== value) throw new Error(`Conflicting installation environment ${key} for ${parsed.specifier}`);
- env[key] = value;
- }
- bySpecifier.set(parsed.specifier, { ...parsed, ...(Object.keys(env).length === 0 ? {} : { env }) });
- }
- const required = [...bySpecifier.values()].sort((left, right) => left.specifier.localeCompare(right.specifier));
- const reports: HostPackageReport[] = [];
- for (const { env, ...item } of required) {
- const installation = externalPackageInstallRoot(root, item.name, item.version);
- options.onProgress?.({ ...item, phase: "checking" });
- const missing = await installedVersion(installation, item.name) !== item.version;
- const logPath = join(installation, "install.log");
- if (missing) {
- await mkdir(installation, { recursive: true });
- await writeFile(join(installation, "package.json"), `${JSON.stringify({
- name: "hypit-machine-packages",
- private: true,
- description: "Upstream npm packages used on demand by Hypit",
- dependencies: { [item.name]: item.version },
- }, null, 2)}\n`, "utf8");
- options.onProgress?.({ ...item, phase: "installing", logPath });
- await runNpm(installation, [item.specifier], logPath, env);
- }
- const version = await installedVersion(installation, item.name);
- if (version !== item.version) {
- throw new Error(`npm did not install ${item.specifier} into ${installation}. Log: ${logPath}`);
- }
- options.onProgress?.({ ...item, phase: "ready" });
- reports.push({ ...item, root: installation, ...(missing ? { logPath } : {}), action: missing ? "installed" : "already-installed" });
- }
- return reports;
-}
diff --git a/packages/runtime-host-node/test/runtime-host-node.test.ts b/packages/runtime-host-node/test/runtime-host-node.test.ts
deleted file mode 100644
index 8e62e79b..00000000
--- a/packages/runtime-host-node/test/runtime-host-node.test.ts
+++ /dev/null
@@ -1,92 +0,0 @@
-import assert from "node:assert/strict";
-import { chmod, mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
-import { tmpdir } from "node:os";
-import { join } from "node:path";
-import test from "node:test";
-
-test("declared dependency installation environment reaches npm without changing the caller", {
- skip: process.platform === "win32",
-}, async () => {
- const root = await mkdtemp(join(tmpdir(), "hypit-package-install-env-"));
- const originalPath = process.env.PATH;
- const originalValue = process.env.HYPIT_TEST_INSTALL_OPTION;
- try {
- const npm = join(root, "npm");
- await writeFile(npm, `#!${process.execPath}
-const fs = require('node:fs');
-fs.writeFileSync('received.json', JSON.stringify({option: process.env.HYPIT_TEST_INSTALL_OPTION}));
-fs.mkdirSync('node_modules/example-sdk', {recursive: true});
-fs.writeFileSync('node_modules/example-sdk/package.json', JSON.stringify({name:'example-sdk', version:'1.2.3'}));
-`);
- await chmod(npm, 0o755);
- process.env.PATH = root;
- const reports = await prepareHostPackages([{ specifier: "[email protected]", env: { HYPIT_TEST_INSTALL_OPTION: "selected" } }], { root: join(root, "packages") });
- assert.equal(JSON.parse(await readFile(join(reports[0]!.root, "received.json"), "utf8")).option, "selected");
- assert.equal(process.env.HYPIT_TEST_INSTALL_OPTION, originalValue);
- assert.equal("env" in reports[0]!, false, "installation parameters are not output metadata");
- await assert.rejects(prepareHostPackages([
- { specifier: "[email protected]", env: { OPTION: "a" } },
- { specifier: "[email protected]", env: { OPTION: "b" } },
- ], { root }), /Conflicting installation environment/u);
- } finally {
- if (originalPath === undefined) delete process.env.PATH; else process.env.PATH = originalPath;
- await rm(root, { recursive: true, force: true });
- }
-});
-
-import {
- diagnoseRuntimeExecutable,
- hypitHostPackageRoot,
- parseRegistryPackageSpec,
- prepareHostPackages,
- resolveRuntimeExecutable,
-} from "@hypit/runtime-host-node";
-
-test("configured executable paths are rooted at the Runtime Profile project", async () => {
- const root = await mkdtemp(join(tmpdir(), "hypit-runtime-host-node-"));
- try {
- const path = join(root, "tools", "fixture");
- await mkdir(join(root, "tools"), { recursive: true });
- await writeFile(path, "#!/bin/sh\n", "utf8");
- await chmod(path, 0o755);
- assert.equal(resolveRuntimeExecutable(root, "./tools/fixture"), path);
- assert.deepEqual(await diagnoseRuntimeExecutable({
- root,
- configured: "./tools/fixture",
- fallback: "unused",
- subject: "fixture",
- }), []);
- } finally {
- await rm(root, { recursive: true, force: true });
- }
-});
-
-test("machine packages reuse exact releases without overwriting another version", async () => {
- const root = await mkdtemp(join(tmpdir(), "hypit-machine-packages-"));
- try {
- const packageRoot = hypitHostPackageRoot(root);
- const installation = join(packageRoot, "hyperframes", "0.7.101");
- await mkdir(join(installation, "node_modules", "hyperframes"), { recursive: true });
- await writeFile(join(installation, "node_modules", "hyperframes", "package.json"), JSON.stringify({
- name: "hyperframes",
- version: "0.7.101",
- }));
- assert.deepEqual(parseRegistryPackageSpec("[email protected]"), {
- name: "hyperframes",
- version: "0.7.101",
- specifier: "[email protected]",
- });
- assert.throws(() => parseRegistryPackageSpec("@hypit/[email protected]"), /external npm registry package/u);
- const reports = await prepareHostPackages(["[email protected]"], { root: packageRoot });
- assert.equal(reports[0]?.action, "already-installed");
- assert.equal(reports[0]?.root, installation);
- const other = join(packageRoot, "hyperframes", "0.7.102");
- await mkdir(join(other, "node_modules", "hyperframes"), { recursive: true });
- await writeFile(join(other, "node_modules", "hyperframes", "package.json"), JSON.stringify({ name: "hyperframes", version: "0.7.102" }));
- assert.equal((await prepareHostPackages(["[email protected]"], { root: packageRoot }))[0]?.root, other);
- assert.equal((await prepareHostPackages(["[email protected]"], { root: packageRoot }))[0]?.action, "already-installed");
- assert.equal((await prepareHostPackages(["[email protected]", "[email protected]"], { root: packageRoot })).length, 2);
- } finally {
- await rm(root, { recursive: true, force: true });
- }
-});
diff --git a/packages/runtime-local/README.md b/packages/runtime-local/README.md
index 3dc23d0e..a179ad07 100644
--- a/packages/runtime-local/README.md
+++ b/packages/runtime-local/README.md
@@ -3,6 +3,12 @@
The default local Runtime for Hypit. It owns the Worker, scheduler and active SQLite execution
worklist. Project-owned Build Results hold finished public Outputs.
+This package also exports `@hypit/runtime-local/cli`, the command contribution that owns
+`runtime`, `programs`, `paths` and the internal Worker entry. The generic `@hypit/cli` Host owns
+none of that local process vocabulary: it consumes a narrow `CliRuntimeHost` port for Build,
+Result, credential and transient-execution operations. The root Hypit application explicitly
+selects this contribution and keeps one `hypit` executable.
+
Managed Program preparation writes subprocess stdout and stderr directly to that Program's
`install.log`, so dependency-download output is readable before installation finishes. Installation
and startup progress expose `logPath`; failed installation reports retain it with a short error.
@@ -70,15 +76,8 @@ client supplies its temporary Resources and receives no Endpoint registry. Decla
inside that one disposable session only. A Provider that needs durable or cross-Build quota admission must
not opt that capability into transient execution.
-A project that wants a non-default Result repository owns a separate `hypit.results.json`:
-
-```json
-{
- "format": "hypit.build-results@1",
- "use": "@hypit/build-result-s3",
- "config": { "bucket": "team-results", "prefix": "projects/episode-12" }
-}
-```
+Build Results belong to the project at `.hypit/results`. Archiving or moving completed Results is a
+post-Build project operation, not a Runtime repository choice.
Submitting a Build stores it and returns. The Worker may advance unrelated Builds together; only the
resources declared by their Commands constrain execution. An Endpoint instance owns its capacity by
@@ -114,10 +113,9 @@ serialized, while network actions and local work remain concurrent under their d
HypiHub can be the explicitly selected gateway for users without their own service keys. A bound
Provider's authentication, quota or transport error never changes that selection. Separate accounts use separate pools even when they implement the same model.
-Without `hypit.results.json`, the official video Distribution selects the filesystem adapter at the
-project's `.hypit/results` directory, with no cloud account or service. Runtime Local opens that default
-through the same adapter registry as an explicit `@hypit/build-result-s3` selection; it contains no
-filesystem Repository shortcut.
+The official video Distribution writes Results to the project's `.hypit/results` directory, with no
+cloud account or service. The filesystem implementation belongs to this single-host Runtime rather
+than a public adapter registry.
Runtime working Resources remain internal and Build-local; there is no ResourceStore selector. After
a Result has an outcome, history is read from the selected repository, not Runtime SQLite.
The submission passes known Resource references to the Result writer, separately from the execution
@@ -133,14 +131,14 @@ to completed, failed and cancelled Builds alike.
Saving a finished Result is a separate, idempotent storage action. If that write is interrupted, the
Build keeps its already-decided outcome and reports exact operator attention. `hypit result finish
<build-id>` performs only that pending write and active-state cleanup; it does not run the execution
-Worker, call a Producer or load Provider Endpoint packages. `hypit result discard <build-id>` is only
+Worker, call a Producer or load Provider packages. `hypit result discard <build-id>` is only
for a submission that never became active and therefore has no Result to save.
Source imports select author packages. Runtime Profile entries select only code allowed to access files,
credentials, processes or networks. Installing a package changes neither selection.
Endpoint scoping happens before activation when explicit instance IDs are supplied, or when every
-requested capability has a binding. Otherwise discovery loads the Profile's Endpoint packages to
+requested capability has a binding. Otherwise discovery loads the Profile's Provider packages to
find eligible implementations. Thus unused service readiness is not required, but an uninstalled
declared package can still prevent unbound discovery. `scopedProfile` owns this distinction; package
names are not used to guess which capabilities they supply.
diff --git a/packages/runtime-local/package.json b/packages/runtime-local/package.json
index 1443d74a..a204f751 100644
--- a/packages/runtime-local/package.json
+++ b/packages/runtime-local/package.json
@@ -1,34 +1,41 @@
{
"name": "@hypit/runtime-local",
- "version": "0.0.0-dev",
+ "version": "0.1.0",
"license": "SEE LICENSE IN LICENSE",
"private": true,
"type": "module",
"exports": {
".": "./src/index.ts",
+ "./cli": "./src/cli.ts",
+ "./extension": "./src/extension.ts",
+ "./node": "./src/node.ts",
"./config": "./src/config.ts",
"./programs": "./src/programs.ts",
"./worker-process": "./src/worker-process.ts"
},
+ "files": [
+ "dist",
+ "README.md"
+ ],
"dependencies": {
- "@hypit/resource-store-fs": "workspace:*",
- "@hypit/build-result": "workspace:*",
- "@hypit/build-result-fs": "workspace:*",
- "@hypit/build-result-kit": "workspace:*",
- "@hypit/component-kit": "workspace:*",
- "@hypit/core": "workspace:*",
- "@hypit/driver-node": "workspace:*",
- "@hypit/endpoint-kit": "workspace:*",
- "@hypit/package-loader-node": "workspace:*",
- "@hypit/protocol": "workspace:*",
- "@hypit/runtime": "workspace:*",
- "@hypit/runtime-kit": "workspace:*",
- "@hypit/runtime-host-node": "workspace:*",
- "@hypit/store-sqlite": "workspace:*",
- "@hypit/validation": "workspace:*",
"koffi": "3.2.1"
},
+ "peerDependencies": {
+ "@hypit/hypit": "workspace:^"
+ },
"devDependencies": {
- "@hypit/credential-store-env": "workspace:*"
+ "@hypit/admission": "workspace:*",
+ "@hypit/credential-store-env": "workspace:*",
+ "@hypit/endpoint": "workspace:*",
+ "@hypit/executor": "workspace:*",
+ "@hypit/hypit": "workspace:*",
+ "@hypit/kernel": "workspace:*",
+ "@hypit/loader": "workspace:*",
+ "@hypit/producer": "workspace:*",
+ "@hypit/project": "workspace:*",
+ "@hypit/protocol": "workspace:*",
+ "@hypit/result": "workspace:*",
+ "@hypit/runtime": "workspace:*",
+ "@hypit/workspace": "workspace:*"
}
}
diff --git a/packages/runtime-local/src/actions.ts b/packages/runtime-local/src/actions.ts
index 32ccb54c..5fbb581c 100644
--- a/packages/runtime-local/src/actions.ts
+++ b/packages/runtime-local/src/actions.ts
@@ -1,4 +1,5 @@
-import type { BuildExecutionStore, RuntimeActionExecutor } from "@hypit/runtime";
+import type { RuntimeActionExecutor } from "@hypit/hypit/runtime";
+import type { BuildExecutionStore } from "./execution.js";
/** All short Endpoint actions use the Runtime's existing shared resource authority. */
export function createActionExecutor(store: BuildExecutionStore): RuntimeActionExecutor {
diff --git a/packages/runtime-local/src/catalog.ts b/packages/runtime-local/src/catalog.ts
new file mode 100644
index 00000000..c3a7c382
--- /dev/null
+++ b/packages/runtime-local/src/catalog.ts
@@ -0,0 +1,34 @@
+import type {
+ LogicalOutputRef,
+} from "@hypit/hypit/protocol";
+
+export type BuildPublishedOutput = {
+ /** Author-provided display name; the Output identifier remains unchanged. */
+ readonly displayName?: string;
+ readonly name: string;
+ readonly ref: LogicalOutputRef;
+};
+
+export type BuildCatalogDescriptor = {
+ readonly source: {
+ readonly path: string;
+ };
+ readonly run?: {
+ readonly path: string;
+ };
+ /** Author-facing targets requested by the Run, including Outputs forwarded outside Core execution. */
+ readonly targets?: readonly LogicalOutputRef[];
+ readonly publishedOutputs: readonly BuildPublishedOutput[];
+};
+
+export type BuildCatalogEntry = BuildCatalogDescriptor & {
+ readonly build: string;
+};
+
+/** Host presentation index only. It is never Build truth. */
+export type BuildCatalog = {
+ record(build: string, descriptor: BuildCatalogDescriptor): Promise<BuildCatalogEntry>;
+ read(build: string): Promise<BuildCatalogEntry | undefined>;
+ /** Result manifests own finished presentation; Runtime Catalog covers active execution only. */
+ remove?(build: string): Promise<void>;
+};
diff --git a/packages/runtime-local/src/cli.ts b/packages/runtime-local/src/cli.ts
new file mode 100644
index 00000000..fea5172f
--- /dev/null
+++ b/packages/runtime-local/src/cli.ts
@@ -0,0 +1,370 @@
+import { writeFile } from "node:fs/promises";
+import { resolve } from "node:path";
+
+import { commandHint, hypitHostStateRoot, hypitProjectStateRoot, writeCliOutput } from "@hypit/hypit/cli";
+import type { CliApplicationContext, CliCommandModule, CliIo, CliMachineView, CliOutputOptions } from "@hypit/hypit/cli";
+import type { CanonicalValue } from "@hypit/hypit/protocol";
+
+import type { LocalRuntimeHost } from "./host-api.js";
+import type { ManagedProgramProgress, ManagedProgramReport } from "./programs.js";
+import { clearRuntimeProfile, findRuntimeProfile, selectRuntimeProfile } from "./profile-selection.js";
+
+type LocalCommand = {
+ readonly root: "runtime" | "programs" | "paths" | "_worker";
+ readonly action?: string;
+ readonly profile?: string;
+ readonly project?: string;
+ readonly packageRoot?: string;
+ readonly endpoints: readonly string[];
+ readonly maxWaitMs?: number;
+ readonly limit: number;
+ readonly lines: number;
+ readonly readyFile?: string;
+ readonly workerOwner?: string;
+ readonly executionRoot?: string;
+ readonly presentation: CliOutputOptions;
+};
+
+/** Product choice consumed only by the Local Runtime command contribution. */
+export type LocalRuntimeCliDistribution = {
+ readonly initialRuntimeProfile?: CanonicalValue;
+ openLocalRuntimeHost(path: string, options: {
+ readonly packageRoot: string;
+ readonly distributionPackageRoot?: string;
+ }): Promise<LocalRuntimeHost>;
+};
+
+function positiveInteger(value: string, name: string): number {
+ const parsed = Number(value);
+ if (!Number.isSafeInteger(parsed) || parsed < 1) throw new Error(`${name} requires a positive integer`);
+ return parsed;
+}
+
+function parse(argv: readonly string[], cwd: string): LocalCommand {
+ const root = argv[0];
+ if (root !== "runtime" && root !== "programs" && root !== "paths" && root !== "_worker") {
+ throw new Error(`Unknown Local Runtime command ${JSON.stringify(root)}`);
+ }
+ const positional: string[] = [];
+ const endpoints: string[] = [];
+ let project: string | undefined;
+ let packageRoot: string | undefined;
+ let runtime: string | undefined;
+ let maxWaitMs: number | undefined;
+ let limit = 20;
+ let lines = 200;
+ let readyFile: string | undefined;
+ let workerOwner: string | undefined;
+ let executionRoot: string | undefined;
+ let json = false;
+ let verbose = false;
+ let color: CliOutputOptions["color"] = "auto";
+ for (let index = 1; index < argv.length; index++) {
+ const value = argv[index]!;
+ const next = (name: string): string => {
+ const selected = argv[index + 1];
+ if (selected === undefined || selected.startsWith("--")) throw new Error(`${name} requires a value`);
+ index += 1;
+ return selected;
+ };
+ if (value === "--json") { json = true; continue; }
+ if (value === "--verbose") { verbose = true; continue; }
+ if (value === "--debug") continue;
+ if (value === "--no-color") { color = "never"; continue; }
+ if (value === "--color") {
+ const selected = next("--color");
+ if (selected !== "auto" && selected !== "always" && selected !== "never") throw new Error("--color takes auto, always or never");
+ color = selected;
+ continue;
+ }
+ if (value === "--project") { project = resolve(cwd, next("--project")); continue; }
+ if (value === "--package-root") { packageRoot = resolve(cwd, next("--package-root")); continue; }
+ if (value === "--runtime") { runtime = resolve(cwd, next("--runtime")); continue; }
+ if (value === "--endpoint") { endpoints.push(next("--endpoint")); continue; }
+ if (value === "--max-wait-ms") { maxWaitMs = positiveInteger(next("--max-wait-ms"), "--max-wait-ms"); continue; }
+ if (value === "--limit") { limit = positiveInteger(next("--limit"), "--limit"); continue; }
+ if (value === "--lines") { lines = positiveInteger(next("--lines"), "--lines"); continue; }
+ if (value === "--ready-file") { readyFile = resolve(cwd, next("--ready-file")); continue; }
+ if (value === "--worker-owner") { workerOwner = next("--worker-owner"); continue; }
+ if (value === "--execution-root") { executionRoot = resolve(cwd, next("--execution-root")); continue; }
+ if (value.startsWith("--")) throw new Error(`Unknown ${root} option ${value}`);
+ positional.push(value);
+ }
+ if (runtime !== undefined && positional.length > (root === "runtime" || root === "programs" ? 1 : 0)) {
+ throw new Error(`${root} accepts the Runtime Profile either positionally or with --runtime, not both`);
+ }
+ const action = root === "runtime" || root === "programs" ? positional.shift() : undefined;
+ const profileValue = root === "_worker" ? positional.shift() : positional.shift();
+ if (positional.length > 0) throw new Error(`${root} received too many positional arguments`);
+ const profile = runtime ?? (profileValue === undefined ? undefined : resolve(cwd, profileValue));
+ return {
+ root,
+ ...(action === undefined ? {} : { action }),
+ ...(profile === undefined ? {} : { profile }),
+ ...(project === undefined ? {} : { project }),
+ ...(packageRoot === undefined ? {} : { packageRoot }),
+ endpoints,
+ ...(maxWaitMs === undefined ? {} : { maxWaitMs }),
+ limit,
+ lines,
+ ...(readyFile === undefined ? {} : { readyFile }),
+ ...(workerOwner === undefined ? {} : { workerOwner }),
+ ...(executionRoot === undefined ? {} : { executionRoot }),
+ presentation: { json, color, verbose },
+ };
+}
+
+function programRecord(item: ManagedProgramReport) {
+ return {
+ ...item,
+ state: item.state.state,
+ ...(item.state.state === "ready" ? {} : { stateDetail: item.state.detail }),
+ };
+}
+
+function programDescription(item: ManagedProgramReport): string {
+ const details = [...new Set([
+ ...(item.state.state === "ready" ? [] : [item.state.detail]),
+ ...(item.detail === undefined ? [] : [item.detail]),
+ ])];
+ return `${item.id}: ${item.state.state}${details.length === 0 ? "" : ` — ${details.join("; ")}`}`
+ + (item.endpoint === item.id ? "" : ` · endpoint ${item.endpoint}`)
+ + (item.pid === undefined ? "" : ` · PID ${item.pid}`)
+ + (item.logPath === undefined ? "" : ` · log ${item.logPath}`)
+ + (item.installationLogPath === undefined || item.installationLogPath === item.logPath ? "" : ` · installation log ${item.installationLogPath}`)
+ + (item.errorLogPath === undefined ? "" : ` · stderr ${item.errorLogPath}`);
+}
+
+function write(io: CliIo, args: LocalCommand, machine: CliMachineView, title: string,
+ status: "success" | "warning" | "error" | "info" = "info",
+ facts: readonly (readonly [string, string])[] = [], lines: readonly string[] = []): void {
+ writeCliOutput(io, args.presentation, { kind: "operational", machine, title, status, facts, lines });
+}
+
+async function runLocal(argv: readonly string[], io: CliIo, context: CliApplicationContext): Promise<void> {
+ const args = parse(argv, context.cwd);
+ const localDistribution = context.distribution as typeof context.distribution & LocalRuntimeCliDistribution;
+ if (args.root === "_worker") {
+ const workerPackageRoot = args.packageRoot ?? localDistribution.packageRoot;
+ if (args.profile === undefined || args.readyFile === undefined || args.workerOwner === undefined || workerPackageRoot === undefined) {
+ throw new Error("internal Worker launch is incomplete");
+ }
+ const workerHost = await localDistribution.openLocalRuntimeHost(args.profile, {
+ packageRoot: workerPackageRoot,
+ ...(localDistribution.packageRoot === undefined ? {} : { distributionPackageRoot: localDistribution.packageRoot }),
+ });
+ await workerHost.runWorker(args.readyFile, args.workerOwner,
+ args.executionRoot === undefined ? undefined : { dataRoot: args.executionRoot });
+ return;
+ }
+ const projectRoot = await context.resolveProjectRoot(args.project);
+ const packageRoot = args.packageRoot ?? projectRoot;
+ const selected = args.profile === undefined ? await findRuntimeProfile(projectRoot) : undefined;
+ const profile = args.profile ?? selected?.profile;
+ const host = async (path: string): Promise<LocalRuntimeHost> => await localDistribution.openLocalRuntimeHost(path, {
+ packageRoot,
+ ...(localDistribution.packageRoot === undefined ? {} : { distributionPackageRoot: localDistribution.packageRoot }),
+ });
+ const progress = args.presentation.json ? io.writeProgress : io.writeProgress ?? io.write;
+ const onProgress = progress === undefined ? undefined : (event: ManagedProgramProgress): void => {
+ if (!args.presentation.verbose && event.detail === undefined && event.phase !== "installing" && event.phase !== "starting") return;
+ const verb = { checking: "Checking", installing: "Installing", starting: "Starting", waiting: "Waiting for", ready: "Ready" }[event.phase];
+ progress(` · ${verb} ${event.id}${event.detail === undefined ? "" : ` — ${event.detail}`}${event.logPath === undefined ? "" : ` · log ${event.logPath}`}\n`);
+ };
+
+ if (args.root === "runtime" && args.action === "init") {
+ if (localDistribution.initialRuntimeProfile === undefined) {
+ throw new Error("This Hypit Distribution does not provide an initial Runtime Profile");
+ }
+ const target = args.profile ?? resolve(projectRoot, "hypit.runtime.json");
+ try {
+ await writeFile(target, `${JSON.stringify(localDistribution.initialRuntimeProfile, undefined, 2)}\n`, { encoding: "utf8", flag: "wx" });
+ } catch (error) {
+ if (error instanceof Error && "code" in error && error.code === "EEXIST") {
+ throw new Error(`Runtime Profile already exists: ${target}; select it with hypit runtime use or choose another path`);
+ }
+ throw error;
+ }
+ const saved = await selectRuntimeProfile(projectRoot, target);
+ write(io, args, { format: "hypit.cli-runtime-init@1", profile: saved.profile, project: saved.projectRoot, selected: true },
+ "Runtime Profile created", "success", [["Profile", saved.profile], ["Project", saved.projectRoot]],
+ ["Review the Profile’s credential stores and Endpoint settings before login or runtime up.",
+ "No package was installed, no service was contacted and no Worker was started."]);
+ return;
+ }
+ if (args.root === "runtime" && args.action === "use") {
+ if (args.profile === undefined) throw new Error("runtime use requires a Runtime Profile");
+ const saved = await selectRuntimeProfile(projectRoot, args.profile);
+ write(io, args, { format: "hypit.cli-runtime-selection@1", selected: true, profile: saved.profile, project: saved.projectRoot },
+ "Runtime selected", "success", [["Profile", saved.profile], ["Project", saved.projectRoot]]);
+ return;
+ }
+ if (args.root === "runtime" && args.action === "unset") {
+ const cleared = await clearRuntimeProfile(projectRoot);
+ write(io, args, { format: "hypit.cli-runtime-selection@1", selected: false, removed: cleared !== undefined,
+ ...(cleared === undefined ? {} : { profile: cleared.profile, project: cleared.projectRoot }) },
+ cleared === undefined ? "No Runtime was selected" : "Runtime selection removed",
+ cleared === undefined ? "info" : "success", cleared === undefined ? [] : [["Profile", cleared.profile], ["Project", cleared.projectRoot]]);
+ return;
+ }
+
+ if (args.root === "paths") {
+ const runtimePaths = profile === undefined ? undefined : await (await host(profile)).resolvePaths();
+ const profileSource: "none" | "project" | "argument" = profile === undefined ? "none" : args.profile === undefined ? "project" : "argument";
+ const machine = {
+ format: "hypit.cli-paths@1", project: projectRoot, profileSource,
+ selectionFile: resolve(projectRoot, ".hypit/runtime"), projectState: hypitProjectStateRoot(projectRoot),
+ ...(profile === undefined ? {} : { profile }),
+ ...(runtimePaths === undefined ? {} : { runtimeData: runtimePaths.runtimeDataRoot }),
+ hostState: hypitHostStateRoot(),
+ ...(localDistribution.packageRoot === undefined ? {} : { distribution: localDistribution.packageRoot }),
+ } as const;
+ write(io, args, machine, "Hypit paths", "info", [
+ ["Project", projectRoot], ["Project state", machine.projectState], ["Runtime Profile", profile ?? "not selected"],
+ ["Runtime selection", args.profile === undefined ? selected?.selectionFile ?? "none" : "command argument (this invocation only)"],
+ ["Runtime data", runtimePaths?.runtimeDataRoot ?? "not selected"], ["Host state", machine.hostState],
+ ["Distribution", localDistribution.packageRoot ?? "embedded"],
+ ]);
+ return;
+ }
+
+ if (profile === undefined) {
+ throw new Error(`${args.root} requires a Runtime; run hypit runtime init, select one with runtime use, or pass --runtime <profile>`);
+ }
+ const opened = await host(profile);
+ const controller = await opened.controller({ packageRoot });
+
+ if (args.root === "programs") {
+ if (args.action !== "prepare" && args.action !== "up" && args.action !== "down" && args.action !== "status") {
+ throw new Error("programs takes prepare, up, down or status");
+ }
+ if (args.action !== "up" && args.maxWaitMs !== undefined) throw new Error("--max-wait-ms applies to programs up");
+ const scope = args.endpoints.length === 0 ? {} : { endpoints: args.endpoints };
+ const result = args.action === "up"
+ ? await controller.programs.up({ ...scope, ...(args.maxWaitMs === undefined ? {} : { maxWaitMs: args.maxWaitMs }), ...(onProgress === undefined ? {} : { onProgress }) })
+ : args.action === "prepare"
+ ? await controller.programs.prepare({ ...scope, ...(onProgress === undefined ? {} : { onProgress }) })
+ : args.action === "down" ? await controller.programs.down(scope) : await controller.programs.report(scope);
+ const ready = result.programs.every((item) => item.state.state === "ready");
+ const needsAttention = (item: ManagedProgramReport) => args.action === "down"
+ ? item.action !== "nothing-to-stop" && (item.state.state !== "down" || item.action !== "stopped")
+ : item.state.state !== "ready";
+ const ok = args.action === "status" || !result.programs.some(needsAttention);
+ const relevant = result.programs.filter((item) => args.presentation.verbose || args.action === "status" || needsAttention(item));
+ const urgent = relevant.filter(needsAttention);
+ const shown = [...urgent, ...relevant.filter((item) => !needsAttention(item)).slice(0, Math.max(0, args.limit - urgent.length))];
+ const omitted = relevant.length - shown.length;
+ const stoppedAny = result.programs.some((item) => item.action === "stopped");
+ const title = args.action === "prepare" ? ok ? "External program resources prepared" : "External program preparation needs attention"
+ : args.action === "up" ? ok ? "External programs ready" : "External programs need attention"
+ : args.action === "down" ? ok ? stoppedAny ? "External programs stopped" : "No external programs to stop" : "External program stop needs attention"
+ : "External program status";
+ write(io, args, { format: "hypit.cli-programs@1", action: args.action, ok, ready,
+ programCount: result.programs.length, readyCount: result.programs.filter((item) => item.state.state === "ready").length,
+ programs: shown.map(programRecord), ...(omitted === 0 ? {} : { omittedPrograms: omitted }) },
+ title, args.action === "status" ? ready ? "success" : "info" : ok ? "success" : "warning",
+ !args.presentation.verbose && ok && args.action !== "status" ? [] : [
+ ["Programs", String(result.programs.length)], ["Ready", String(result.programs.filter((item) => item.state.state === "ready").length)],
+ ], shown.map(programDescription).concat(omitted === 0 ? [] : [`${omitted} more programs · use --limit <count>`]));
+ if (!ok) io.setExitCode?.(1);
+ return;
+ }
+
+ if (args.action !== "up" && args.action !== "down" && args.action !== "status" && args.action !== "logs") {
+ throw new Error("runtime takes init, use, unset, up, down, status or logs");
+ }
+ if (args.action === "up") {
+ const validated = await opened.createRuntime(args.endpoints.length === 0 ? {} : { endpoints: args.endpoints });
+ await validated.close();
+ const external = await controller.programs.up({
+ ...(args.endpoints.length === 0 ? {} : { endpoints: args.endpoints }),
+ ...(args.maxWaitMs === undefined ? {} : { maxWaitMs: args.maxWaitMs }),
+ ...(onProgress === undefined ? {} : { onProgress }),
+ });
+ const worker = await controller.worker.up(args.maxWaitMs === undefined ? {} : { maxWaitMs: args.maxWaitMs });
+ const ok = worker.state === "running" && external.programs.every((item) => item.state.state === "ready");
+ write(io, args, { format: "hypit.cli-runtime-up@1", ready: ok, worker: worker.state,
+ programs: { total: external.programs.length, ready: external.programs.filter((item) => item.state.state === "ready").length,
+ items: external.programs.filter((item) => args.presentation.verbose || item.state.state !== "ready").map(programRecord) } },
+ ok ? "Local Runtime ready" : "Local Runtime needs attention", ok ? "success" : "warning",
+ !args.presentation.verbose && ok ? [] : [["Worker", worker.state],
+ ["Managed programs", `${external.programs.filter((item) => item.state.state === "ready").length}/${external.programs.length} ready`]],
+ external.programs.filter((item) => args.presentation.verbose || item.state.state !== "ready").map(programDescription));
+ if (!ok) io.setExitCode?.(1);
+ return;
+ }
+ if (args.action === "logs") {
+ const logs = await controller.worker.logs();
+ const all = logs.text.length === 0 ? [] : logs.text.replace(/\n$/u, "").split("\n");
+ const shown = all.slice(-args.lines);
+ write(io, args, { format: "hypit.cli-runtime-logs@1", lines: shown, totalLines: all.length,
+ omittedLines: Math.max(0, all.length - shown.length), ...(args.presentation.verbose ? { path: logs.path } : {}) },
+ "Runtime logs", "info", [["Lines", `${shown.length}/${all.length}`], ...(args.presentation.verbose ? [["Path", logs.path] as const] : [])],
+ shown.length === 0 ? ["No log output."] : shown);
+ return;
+ }
+ if (args.action === "down") {
+ const worker = await controller.worker.down(args.maxWaitMs === undefined ? {} : { maxWaitMs: args.maxWaitMs });
+ const stopped = worker.state === "stopped";
+ write(io, args, { format: "hypit.cli-runtime-down@1", worker: worker.state },
+ stopped ? "Runtime Worker is down" : "Runtime Worker is still running", stopped ? "success" : "warning",
+ [["Worker", worker.state]], [`Managed Programs are unchanged. To stop processes started by Hypit: ${commandHint(
+ ["programs", "down"], { projectRoot, runtimeProfile: resolve(profile) },
+ )}`]);
+ if (!stopped) io.setExitCode?.(1);
+ return;
+ }
+
+ const control = await opened.openControl({ readOnly: true });
+ try {
+ const [worker, external, activity] = await Promise.all([controller.worker.status(), controller.programs.report(), control.activity()]);
+ const unavailable = external.programs.filter((item) => item.state.state !== "ready");
+ const ready = worker.state === "running" && unavailable.length === 0;
+ const attention = activity.builds.some((item) => item.issue !== undefined) || (activity.builds.length > 0 && !ready);
+ const counts = {
+ submitting: activity.builds.filter((item) => item.activity === "submitting").length,
+ working: activity.builds.filter((item) => item.activity === "ready" || item.activity === "running" || item.activity === "waiting").length,
+ savingResult: activity.builds.filter((item) => item.activity === "saving-result").length,
+ };
+ write(io, args, { format: "hypit.cli-runtime-status@1", ready, attention, worker: { state: worker.state }, builds: counts,
+ programs: { total: external.programs.length, ready: external.programs.length - unavailable.length, unavailable: unavailable.map(programRecord) },
+ capacity: { active: activity.capacity.length } },
+ attention ? "Local Runtime needs attention" : ready ? "Local Runtime ready"
+ : worker.state === "running" ? "Runtime Worker running; Programs not ready" : "Runtime Worker stopped",
+ attention ? "warning" : ready ? "success" : "info", [
+ ["Worker", worker.state], ["Active Builds", String(activity.builds.length)],
+ ["Programs", `${external.programs.length - unavailable.length}/${external.programs.length} ready`],
+ ...(args.presentation.verbose ? [["Submitting", String(counts.submitting)] as const, ["Working", String(counts.working)] as const,
+ ["Saving Result", String(counts.savingResult)] as const, ["Capacity in use", String(activity.capacity.length)] as const] : []),
+ ], unavailable.map(programDescription));
+ } finally { await control.close(); }
+}
+
+function writeRootHelp(io: CliIo): void {
+ io.write("\nLocal Runtime\n"
+ + " runtime init|use|unset|up|status|logs|down\n"
+ + " programs prepare|up|status|down\n"
+ + " paths\n");
+}
+
+function writeHelp(argv: readonly string[], io: CliIo): void {
+ const topic = argv[0] === "help" ? argv[1] : argv[0];
+ if (topic === "runtime") io.write("hypit runtime\nSelect a Local Runtime Profile and operate its Build Worker.\n\n"
+ + " hypit runtime init [<profile>] [--project <project>]\n"
+ + " hypit runtime use <profile> [--project <project>]\n"
+ + " hypit runtime unset [--project <project>]\n"
+ + " hypit runtime up|status|logs|down [<profile>] [--project <project>]\n");
+ else if (topic === "programs") io.write("hypit programs\nOperate external programs declared by the selected Local Runtime Profile.\n\n"
+ + " hypit programs prepare|up|status|down [<profile>] [--project <project>]\n");
+ else if (topic === "paths") io.write("hypit paths\nShow project, Local Runtime and host state locations.\n\n"
+ + " hypit paths [--project <project>] [--runtime <profile>]\n");
+}
+
+export const cliCommandModules = [{
+ format: "hypit.cli-command@1",
+ id: "@hypit/runtime-local#cli",
+ commands: ["runtime", "programs", "paths", "_worker"],
+ writeRootHelp,
+ writeHelp,
+ run: runLocal,
+}] as const satisfies readonly CliCommandModule[];
diff --git a/packages/runtime-local/src/config.ts b/packages/runtime-local/src/config.ts
index 57c4a6ef..bf2cf13b 100644
--- a/packages/runtime-local/src/config.ts
+++ b/packages/runtime-local/src/config.ts
@@ -1,42 +1,35 @@
import { fileExecutionLogs } from "./log.js";
-import { readFile, rm, stat } from "node:fs/promises";
+import { constants } from "node:fs";
+import { access, readFile, rm, stat } from "node:fs/promises";
import { dirname, relative, resolve, sep } from "node:path";
import {
- collectLoadedNodePackageComponents,
- distributionExternalPackageRequirements,
loadNodePackageSelection,
-} from "@hypit/package-loader-node";
-import type { NodePackageSelectionRequest } from "@hypit/package-loader-node";
-import { EndpointRegistry, NodeDriver } from "@hypit/driver-node";
-import type { EndpointCredential, EndpointFulfillment, EndpointPackage, EndpointRegistrar, EndpointScheduling } from "@hypit/endpoint-kit";
-import { endpointResourceClaims, verifyEndpointPricingDocument } from "@hypit/endpoint-kit";
-import { assertBuildId, canonicalize, canonicalStringify } from "@hypit/protocol";
-import type { CanonicalValue, CapabilityRef, Need } from "@hypit/protocol";
+} from "@hypit/hypit/loader/node";
+import { verifyPackageContributions } from "@hypit/hypit/loader";
+import type { NodePackageSelectionRequest } from "@hypit/hypit/loader/node";
+import { hypitHostStateRoot } from "@hypit/hypit/cli";
+import { EndpointRegistry, Executor } from "@hypit/hypit/executor";
+import type { EndpointCredential, EndpointFulfillment, EndpointInstance, EndpointRegistrar, EndpointScheduling } from "@hypit/hypit/endpoint";
+import { endpointResourceClaims, verifyEndpointPricingDocument } from "@hypit/hypit/endpoint";
+import { assertBuildId, canonicalize, canonicalStringify } from "@hypit/hypit/protocol";
+import type { CanonicalValue, CapabilityRef, Need } from "@hypit/hypit/protocol";
import {
CompositeCredentialStore,
capacityUnits,
writableCredentialStore,
-} from "@hypit/runtime";
-import type { CredentialStore, CredentialValue, ResourceStore } from "@hypit/runtime";
-import { FileResourceStore } from "@hypit/resource-store-fs";
+} from "@hypit/hypit/runtime";
+import type { CredentialStore, CredentialValue, ResourceStore } from "@hypit/hypit/runtime";
+import type { BuildResultRepositoryLocation } from "./execution.js";
+import { FileBuildResultRepository } from "@hypit/hypit/result/node";
+import type { BuildResultRepository } from "@hypit/hypit/result";
+import { FileResourceStore } from "./resource-store.js";
import {
- buildResultRepositoryHostAbi,
- BuildResultRepositoryRegistry,
- isBuildResultRepositoryHostFacet,
-} from "@hypit/build-result-kit";
-import type {
- BuildResultRepositoryDiagnostic,
- BuildResultRepositoryLocation,
- BuildResultRepositoryOpened,
- BuildResultRepositorySelection,
-} from "@hypit/build-result-kit";
-import {
- isRuntimeAdapterHostFacet,
- runtimeCredentialStoreAdapterHostAbi,
- runtimeEndpointAdapterHostAbi,
+ isRuntimeAdapterFacet,
+ runtimeCredentialStoreAdapterFacetAbi,
+ runtimeEndpointAdapterFacetAbi,
RuntimeAdapterRegistry,
-} from "@hypit/runtime-kit";
+} from "@hypit/runtime-local/extension";
import type {
ManagedProgram,
ManagedProgramState,
@@ -44,22 +37,15 @@ import type {
RuntimeDoctorDiagnostic,
RuntimeEndpointActivation,
RuntimeOpened,
-} from "@hypit/runtime-kit";
-import {
- hypitHostPackageRoot,
- hypitHostStateRoot,
- prepareHostPackages,
-} from "@hypit/runtime-host-node";
+} from "@hypit/runtime-local/extension";
import type {
- HostPackageProgress,
- HostPackageReport,
RuntimeHostCapabilityPricing,
RuntimeHostCapabilityProvider,
RuntimeHostProviderQuery,
RuntimeHostTransientExecution,
RuntimeInvocationObservation,
-} from "@hypit/runtime-host-node";
-import { SqliteRuntimeState } from "@hypit/store-sqlite";
+} from "./host-api.js";
+import { SqliteRuntimeState } from "./sqlite-state.js";
import { applyEndpointBindings, createLocalRuntime, parseCapabilityKey } from "./runtime.js";
import {
@@ -96,20 +82,13 @@ export type LocalRuntimeProfile = {
readonly bindings: Readonly<Record<string, string>>;
};
-export type ProjectBuildResultConfig = {
- readonly format: "hypit.build-results@1";
- readonly use: string;
- readonly config?: CanonicalValue;
-};
-
export type ProjectBuildResultDoctorResult = {
readonly location?: BuildResultRepositoryLocation;
- readonly diagnostics: readonly BuildResultRepositoryDiagnostic[];
+ readonly diagnostics: readonly RuntimeDoctorDiagnostic[];
};
export type LoadRuntimeConfigOptions = {
readonly registry?: RuntimeAdapterRegistry;
- readonly resultRegistry?: BuildResultRepositoryRegistry;
/** Execution-owned module bindings; omitted for ordinary short-lived CLI calls. */
readonly importModule?: (url: string) => Promise<unknown>;
readonly endpoints?: readonly string[];
@@ -277,23 +256,16 @@ function runtimePackageSelection(document: LocalRuntimeProfile): NodePackageSele
return {
selected: [],
logical: [
- ...document.credentials.map((item) => ({ abi: runtimeCredentialStoreAdapterHostAbi, name: item.use })),
- ...document.endpoints.map((item) => ({ abi: runtimeEndpointAdapterHostAbi, name: item.use })),
+ ...document.credentials.map((item) => ({ abi: runtimeCredentialStoreAdapterFacetAbi, name: item.use })),
+ ...document.endpoints.map((item) => ({ abi: runtimeEndpointAdapterFacetAbi, name: item.use })),
],
};
}
-function resultPackageSelection(use: string): NodePackageSelectionRequest {
- return {
- selected: [],
- logical: [{ abi: buildResultRepositoryHostAbi, name: use }],
- };
-}
-
-function endpointPackageSelection(document: LocalRuntimeProfile): NodePackageSelectionRequest {
+function endpointAdapterSelection(document: LocalRuntimeProfile): NodePackageSelectionRequest {
return {
selected: [],
- logical: document.endpoints.map((item) => ({ abi: runtimeEndpointAdapterHostAbi, name: item.use })),
+ logical: document.endpoints.map((item) => ({ abi: runtimeEndpointAdapterFacetAbi, name: item.use })),
};
}
@@ -305,131 +277,76 @@ async function installRuntimeAdapters(
importModule?: (url: string) => Promise<unknown>,
): Promise<void> {
const logical = selection.logical?.filter((address) => {
- if (address.abi === runtimeEndpointAdapterHostAbi) return !registry.has(address.name, "endpoint");
- if (address.abi === runtimeCredentialStoreAdapterHostAbi) return !registry.has(address.name, "credential-store");
+ if (address.abi === runtimeEndpointAdapterFacetAbi) return !registry.has(address.name, "endpoint");
+ if (address.abi === runtimeCredentialStoreAdapterFacetAbi) return !registry.has(address.name, "credential-store");
return true;
}) ?? [];
if (selection.selected.length === 0 && logical.length === 0) return;
const loaded = await loadNodePackageSelection({ selected: selection.selected, logical }, packageRoot, {
- deferExternalDependencies: true,
- ...(importModule === undefined ? {} : { importModule }),
- ...(distributionPackageRoot === undefined ? {} : { fallbackRoots: [distributionPackageRoot] }),
- });
- for (const item of loaded) {
- for (const facet of item.contribution.hostFacets ?? []) {
- if (isRuntimeAdapterHostFacet(facet)) registry.registerFacet(facet);
- }
- }
-}
-
-async function installBuildResultAdapter(
- registry: BuildResultRepositoryRegistry,
- packageRoot: string,
- use: string,
- distributionPackageRoot?: string,
- importModule?: (url: string) => Promise<unknown>,
-): Promise<void> {
- if (registry.has(use)) return;
- const loaded = await loadNodePackageSelection(resultPackageSelection(use), packageRoot, {
...(importModule === undefined ? {} : { importModule }),
...(distributionPackageRoot === undefined ? {} : { fallbackRoots: [distributionPackageRoot] }),
});
for (const item of loaded) {
- for (const facet of item.contribution.hostFacets ?? []) {
- if (isBuildResultRepositoryHostFacet(facet)) registry.registerFacet(facet);
+ for (const facet of item.contribution.facets ?? []) {
+ if (isRuntimeAdapterFacet(facet)) registry.registerFacet(facet);
}
}
- if (!registry.has(use)) throw new Error(`Package selection did not provide Build Result Repository ${use}`);
}
async function openBuildResultLocation(
location: BuildResultRepositoryLocation,
- options: LoadRuntimeConfigOptions,
- packageRoot: string,
- registry: BuildResultRepositoryRegistry,
-): Promise<BuildResultRepositoryOpened> {
- await installBuildResultAdapter(registry, packageRoot, location.selection.use, options.distributionPackageRoot, options.importModule);
- return await registry.open(location.selection, location.root);
+): Promise<{ readonly repository: BuildResultRepository }> {
+ return { repository: new FileBuildResultRepository(resolve(location.root, location.path)) };
}
export async function openBuildResultRepositoryLocation(
location: BuildResultRepositoryLocation,
- options: LoadRuntimeConfigOptions = {},
-): Promise<BuildResultRepositoryOpened> {
- const root = resolve(location.root);
- const registry = options.resultRegistry ?? new BuildResultRepositoryRegistry();
- return await openBuildResultLocation(location, options, resolve(options.packageRoot ?? root), registry);
+): Promise<{ readonly repository: BuildResultRepository }> {
+ return await openBuildResultLocation(location);
}
export async function openProjectBuildResultRepository(
projectRoot: string,
- options: LoadRuntimeConfigOptions & {
- readonly defaultSelection: BuildResultRepositorySelection;
- },
-): Promise<BuildResultRepositoryOpened & { readonly location: BuildResultRepositoryLocation }> {
- const root = resolve(projectRoot);
- const location = await projectBuildResultLocation(root, options.defaultSelection);
- const registry = options.resultRegistry ?? new BuildResultRepositoryRegistry();
- const result = await openBuildResultLocation(location, options, resolve(options.packageRoot ?? root), registry);
+): Promise<{ readonly repository: BuildResultRepository; readonly location: BuildResultRepositoryLocation }> {
+ const location = projectBuildResultLocation(projectRoot);
+ const result = await openBuildResultLocation(location);
return { ...result, location };
}
-async function projectBuildResultLocation(
- root: string,
- defaultSelection: BuildResultRepositorySelection,
-): Promise<BuildResultRepositoryLocation> {
- const configPath = resolve(root, "hypit.results.json");
- const text = await readFile(configPath, "utf8").catch((error: unknown) => {
- if (error instanceof Error && "code" in error && error.code === "ENOENT") return undefined;
- throw error;
- });
- let selection: BuildResultRepositoryLocation["selection"];
- if (text === undefined) {
- selection = defaultSelection;
- } else {
- const item = object(JSON.parse(text), "$results");
- exactKeys(item, ["format", "use", "config"], "$results");
- if (item.format !== "hypit.build-results@1") {
- throw new Error("$results.format must be hypit.build-results@1");
- }
- selection = {
- use: requiredString(item.use, "$results.use"),
- ...(item.config === undefined ? {} : { config: canonicalize(item.config) }),
- };
- }
- return { root, selection };
+function projectBuildResultLocation(projectRoot: string): BuildResultRepositoryLocation {
+ return { root: resolve(projectRoot), path: ".hypit/results" };
}
/** Diagnose the project-owned Result Store without reading Result history or mutating storage. */
export async function doctorProjectBuildResultRepository(
projectRoot: string,
- options: LoadRuntimeConfigOptions & {
- readonly defaultSelection: BuildResultRepositorySelection;
- },
): Promise<ProjectBuildResultDoctorResult> {
- const root = resolve(projectRoot);
- let location: BuildResultRepositoryLocation | undefined;
+ const location = projectBuildResultLocation(projectRoot);
+ const resultRoot = resolve(location.root, location.path);
+ let current = resultRoot;
try {
- location = await projectBuildResultLocation(root, options.defaultSelection);
- const registry = options.resultRegistry ?? new BuildResultRepositoryRegistry();
- await installBuildResultAdapter(
- registry,
- resolve(options.packageRoot ?? root),
- location.selection.use,
- options.distributionPackageRoot,
- );
- return {
- location,
- diagnostics: await registry.doctor(location.selection, location.root),
- };
+ while (true) {
+ const found = await stat(current).catch((error: unknown) => {
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") return undefined;
+ throw error;
+ });
+ if (found !== undefined) {
+ if (!found.isDirectory()) throw new Error(`${current} is not a directory`);
+ await access(current, constants.R_OK | constants.W_OK);
+ return { location, diagnostics: [] };
+ }
+ const parent = dirname(current);
+ if (parent === current) throw new Error(`no existing parent directory for ${resultRoot}`);
+ current = parent;
+ }
} catch (error) {
return {
- ...(location === undefined ? {} : { location }),
+ location,
diagnostics: [{
severity: "error",
- code: "RESULT_REPOSITORY_INVALID",
+ code: "RESULT_DIRECTORY_UNAVAILABLE",
message: error instanceof Error ? error.message : String(error),
- subject: resolve(root, "hypit.results.json"),
+ subject: resultRoot,
}],
};
}
@@ -443,31 +360,6 @@ export async function resolveRuntimeConfigPaths(
return { packageRoot: opened.packageRoot, dataRoot: opened.root };
}
-/** Explicit provisioning step used by runtime/programs up, never by plan or build. */
-export async function prepareRuntimeConfigPackages(
- path: string,
- options: LoadRuntimeConfigOptions & {
- readonly onProgress?: (event: HostPackageProgress) => void;
- readonly endpoints?: readonly string[];
- } = {},
-): Promise<readonly HostPackageReport[]> {
- if (options.distributionPackageRoot === undefined) return [];
- const opened = await openRuntimeConfig(path, options.packageRoot);
- const document = scopedProfile(opened.document, options);
- const registry = options.registry ?? new RuntimeAdapterRegistry();
- await installRuntimeAdapters(registry, opened.packageRoot, endpointPackageSelection(document), options.distributionPackageRoot);
- const activations = await activatedEndpoints(document, opened.root, resolve(options.hostStateRoot ?? hypitHostStateRoot()), registry);
- const credentials = credentialProfile(document, activations.map(({ activation }) => activation.endpoint));
- const requirements = await distributionExternalPackageRequirements([
- ...document.endpoints.map((item) => item.use),
- ...credentials.credentials.map((item) => item.use),
- ], options.distributionPackageRoot);
- return await prepareHostPackages(requirements, {
- root: hypitHostPackageRoot(options.hostStateRoot),
- ...(options.onProgress === undefined ? {} : { onProgress: options.onProgress }),
- });
-}
-
function capabilityKey(capability: CapabilityRef): string {
return `${capability.module.name}@${capability.module.version}#${capability.name}`;
}
@@ -510,7 +402,7 @@ async function activatedEndpoints(
})));
}
-function credentialProfile(document: LocalRuntimeProfile, endpoints: readonly EndpointPackage[]): LocalRuntimeProfile {
+function credentialProfile(document: LocalRuntimeProfile, endpoints: readonly EndpointInstance[]): LocalRuntimeProfile {
const used = new Set(endpoints.flatMap((endpoint) => endpoint.credentials.map((slot) => slot.ref.store)));
return { ...document, credentials: document.credentials.filter((item) => used.has(item.instance)) };
}
@@ -525,7 +417,7 @@ export async function declaredManagedPrograms(
if (options.capabilities?.length === 0) return { dataRoot: root, programs: [] };
const hostStateRoot = resolve(options.hostStateRoot ?? hypitHostStateRoot());
const registry = options.registry ?? new RuntimeAdapterRegistry();
- await installRuntimeAdapters(registry, packageRoot, endpointPackageSelection(document), options.distributionPackageRoot);
+ await installRuntimeAdapters(registry, packageRoot, endpointAdapterSelection(document), options.distributionPackageRoot);
const requested = options.capabilities === undefined
? undefined
: new Set(options.capabilities.map(capabilityKey));
@@ -657,7 +549,7 @@ export async function openTransientRuntimeConfigExecution(
if (closed) throw new Error("transient Runtime execution is closed");
activeEvaluations += 1;
try {
- return await new NodeDriver({
+ return await new Executor({
producers: input.producers,
validators: input.validators,
endpoints,
@@ -699,7 +591,7 @@ export async function describeRuntimeConfigProviders(
const document = scopedProfile(opened.document, { capabilities: requests.map((request) => request.capability) });
const hostStateRoot = resolve(options.hostStateRoot ?? hypitHostStateRoot());
const registry = options.registry ?? new RuntimeAdapterRegistry();
- await installRuntimeAdapters(registry, packageRoot, endpointPackageSelection(document), options.distributionPackageRoot);
+ await installRuntimeAdapters(registry, packageRoot, endpointAdapterSelection(document), options.distributionPackageRoot);
const activations = await activatedEndpoints(document, root, hostStateRoot, registry);
const endpoints = await installedEndpointRegistry(document, activations);
return requests.map((request): RuntimeHostCapabilityProvider => {
@@ -746,7 +638,7 @@ export async function describeRuntimeConfigProviders(
}
async function resolveEndpointCredentials(
- endpoint: EndpointPackage,
+ endpoint: EndpointInstance,
store: CredentialStore,
profile: string,
): Promise<Readonly<Record<string, EndpointCredential>>> {
@@ -782,11 +674,11 @@ export async function readRuntimeConfigPricing(
const document = scopedProfile(opened.document, { capabilities: requests.map((request) => request.capability) });
const hostStateRoot = resolve(options.hostStateRoot ?? hypitHostStateRoot());
const registry = options.registry ?? new RuntimeAdapterRegistry();
- await installRuntimeAdapters(registry, packageRoot, endpointPackageSelection(document), options.distributionPackageRoot);
+ await installRuntimeAdapters(registry, packageRoot, endpointAdapterSelection(document), options.distributionPackageRoot);
const activations = await activatedEndpoints(document, root, hostStateRoot, registry);
const endpoints = await installedEndpointRegistry(document, activations);
const stores = new Map<string, Awaited<ReturnType<typeof openCredentialStores>>>();
- const openedStores = async (endpoint: EndpointPackage) => {
+ const openedStores = async (endpoint: EndpointInstance) => {
let opened = stores.get(endpoint.instance.id);
if (opened === undefined) {
const selected = credentialProfile(document, [endpoint]);
@@ -907,7 +799,7 @@ export async function invokeRuntimeConfigNeed(
const document = scopedProfile(opened.document, { capabilities: [need.capability] });
const hostStateRoot = resolve(options.hostStateRoot ?? hypitHostStateRoot());
const registry = options.registry ?? new RuntimeAdapterRegistry();
- await installRuntimeAdapters(registry, packageRoot, endpointPackageSelection(document), options.distributionPackageRoot);
+ await installRuntimeAdapters(registry, packageRoot, endpointAdapterSelection(document), options.distributionPackageRoot);
const activations = await activatedEndpoints(document, root, hostStateRoot, registry);
const endpoints = await installedEndpointRegistry(document, activations);
const subject = capabilityKey(need.capability);
@@ -1016,7 +908,7 @@ async function inspectRuntimeConfig(
}
const registry = options.registry ?? new RuntimeAdapterRegistry();
try {
- await installRuntimeAdapters(registry, packageRoot, endpointPackageSelection(document), options.distributionPackageRoot);
+ await installRuntimeAdapters(registry, packageRoot, endpointAdapterSelection(document), options.distributionPackageRoot);
} catch (error) {
return { dataRoot: root, diagnostics: [diagnostic(error, "RUNTIME_PACKAGE_SELECTION_INVALID")] };
}
@@ -1106,7 +998,7 @@ async function inspectRuntimeConfig(
const credentialDocument = scoped ? credentialProfile(document, selectedEndpoints.map(({ activation }) => activation.endpoint)) : document;
try {
await installRuntimeAdapters(registry, packageRoot, {
- selected: [], logical: credentialDocument.credentials.map((item) => ({ abi: runtimeCredentialStoreAdapterHostAbi, name: item.use })),
+ selected: [], logical: credentialDocument.credentials.map((item) => ({ abi: runtimeCredentialStoreAdapterFacetAbi, name: item.use })),
}, options.distributionPackageRoot);
const storeSelections = [
...credentialDocument.credentials.map((item) => ({ item, kind: "credential-store" as const })),
@@ -1237,8 +1129,7 @@ async function createRuntimeFromOpened(opened: OpenedRuntimeConfig, options: Loa
let document = scopedProfile(opened.document, options);
const hostStateRoot = resolve(options.hostStateRoot ?? hypitHostStateRoot());
const registry = options.registry ?? new RuntimeAdapterRegistry();
- const resultRegistry = options.resultRegistry ?? new BuildResultRepositoryRegistry();
- await installRuntimeAdapters(registry, packageRoot, endpointPackageSelection(document), options.distributionPackageRoot, options.importModule);
+ await installRuntimeAdapters(registry, packageRoot, endpointAdapterSelection(document), options.distributionPackageRoot, options.importModule);
const state = execution?.state ?? new SqliteRuntimeState(statePath(root));
let credentials: Awaited<ReturnType<typeof openCredentialStores>> | undefined;
try {
@@ -1272,16 +1163,17 @@ async function createRuntimeFromOpened(opened: OpenedRuntimeConfig, options: Loa
clearBuildResources: async (build) => {
await rm(buildWorkPath(root, build), { recursive: true, force: true });
},
- openBuildResultRepository: async (location) => await openBuildResultLocation(location, options, packageRoot, resultRegistry),
+ openBuildResultRepository: openBuildResultLocation,
credentialStore: credentials.store,
- loadComponentPackages: async (specifiers) => {
+ loadProducerPackages: async (specifiers) => {
const loaded = await loadNodePackageSelection(specifiers, packageRoot, {
...(options.importModule === undefined ? {} : { importModule: options.importModule }),
...(options.distributionPackageRoot === undefined
? {}
: { fallbackRoots: [options.distributionPackageRoot] }),
});
- return collectLoadedNodePackageComponents(loaded);
+ verifyPackageContributions(loaded.map((item) => item.contribution));
+ return loaded;
},
endpoints,
bindings: document.bindings,
@@ -1324,9 +1216,7 @@ export async function createRuntimeResultControlFromConfig(
}
export function createRuntimeResultWriter(root: string, options: LoadRuntimeConfigOptions & { readonly packageRoot: string }): LocalResultWriter {
- const { packageRoot } = options;
const state = new SqliteRuntimeState(statePath(root));
- const resultRegistry = options.resultRegistry ?? new BuildResultRepositoryRegistry();
return createLocalResultWriter({
buildStore: state.builds,
operationStore: state.operations,
@@ -1340,8 +1230,7 @@ export function createRuntimeResultWriter(root: string, options: LoadRuntimeConf
clearBuildResources: async (build) => {
await rm(buildWorkPath(root, build), { recursive: true, force: true });
},
- openBuildResultRepository: async (location) =>
- await openBuildResultLocation(location, options, packageRoot, resultRegistry),
+ openBuildResultRepository: openBuildResultLocation,
close: () => state.close(),
});
}
@@ -1359,13 +1248,13 @@ export async function createRuntimeCredentialsFromConfig(
await installRuntimeAdapters(registry, packageRoot, runtimePackageSelection(document), options.distributionPackageRoot);
const credentials = await openCredentialStores(document, root, hostStateRoot, registry);
try {
- const endpointPackage = await registry.createEndpoint(endpoint.use, adapterContext(root, hostStateRoot, {
+ const endpointInstance = await registry.createEndpoint(endpoint.use, adapterContext(root, hostStateRoot, {
...endpoint,
pool: endpoint.pool ?? endpoint.instance,
}));
return createLocalCredentialControl({
credentialStore: credentials.store,
- endpoints: [endpointPackage],
+ endpoints: [endpointInstance],
close: credentials.close,
});
} catch (error) {
diff --git a/packages/runtime-local/src/control.ts b/packages/runtime-local/src/control.ts
index b9cde646..1ed005e4 100644
--- a/packages/runtime-local/src/control.ts
+++ b/packages/runtime-local/src/control.ts
@@ -2,16 +2,16 @@ import type {
CreateLocalRuntimeControlOptions,
LocalRuntimeControl,
} from "./types.js";
-import { buildExecutionActivity } from "@hypit/runtime";
+import { buildExecutionActivity } from "./execution.js";
import type {
- PendingBuildSubmission,
- BuildCatalogEntry,
- BuildExecutionSnapshot,
BuildSnapshot,
OperationSnapshot,
-} from "@hypit/runtime";
-import type { BuildView } from "@hypit/runtime-host-node";
-import { buildIdCreatedAt } from "@hypit/protocol";
+} from "@hypit/hypit/runtime";
+import type { PendingBuildSubmission } from "./submission.js";
+import type { BuildCatalogEntry } from "./catalog.js";
+import type { BuildExecutionSnapshot } from "./execution.js";
+import type { BuildView } from "./host-api.js";
+import { buildIdCreatedAt } from "@hypit/hypit/protocol";
function buildView(input: {
readonly build: string;
@@ -20,7 +20,7 @@ function buildView(input: {
readonly submission?: PendingBuildSubmission;
readonly execution?: BuildExecutionSnapshot;
readonly operations: readonly OperationSnapshot[];
- readonly commands: readonly import("@hypit/runtime").CommandExecutionReceipt[];
+ readonly commands: readonly import("@hypit/hypit/runtime").CommandExecutionReceipt[];
}): BuildView | undefined {
if (input.submission === undefined && input.execution === undefined) return undefined;
const createdAt = buildIdCreatedAt(input.build);
diff --git a/packages/runtime-local/src/credentials.ts b/packages/runtime-local/src/credentials.ts
index 650133c0..f880bcdc 100644
--- a/packages/runtime-local/src/credentials.ts
+++ b/packages/runtime-local/src/credentials.ts
@@ -1,6 +1,6 @@
import {
writableCredentialStore,
-} from "@hypit/runtime";
+} from "@hypit/hypit/runtime";
import type {
CreateLocalCredentialControlOptions,
diff --git a/packages/runtime-local/src/execution.ts b/packages/runtime-local/src/execution.ts
new file mode 100644
index 00000000..fe99adf4
--- /dev/null
+++ b/packages/runtime-local/src/execution.ts
@@ -0,0 +1,116 @@
+import type {
+ CapacityAcquire,
+ CapacityAcquireRequest,
+ CapacityReservation,
+} from "@hypit/hypit/runtime";
+
+export type BuildOutcome = "complete" | "failed" | "cancelled";
+
+/** Exact host-local directory chosen before a Build becomes active. */
+export type BuildResultRepositoryLocation = {
+ /** Project ownership boundary used to record portable Source and Run paths. */
+ readonly root: string;
+ /** Host-local filesystem path below the project root. */
+ readonly path: string;
+};
+
+export type BuildExecutionRequest = {
+ readonly build: string;
+ /** Host-owned execution choices. Opaque to the graph and Core. */
+ readonly context?: import("@hypit/hypit/protocol").CanonicalValue;
+ /** Installed execution packages loaded when this execution context starts. */
+ readonly executionPackages: readonly string[];
+ /** Exact project Result Repository selected at submission. */
+ readonly result: BuildResultRepositoryLocation;
+};
+
+export type BuildExecutionDecision = {
+ readonly outcome: BuildOutcome;
+ readonly reason?: string;
+};
+
+/** A durable instruction to stop launching work, independent of remote Operation termination. */
+export type BuildExecutionStop = {
+ readonly cause: "user-cancelled" | "execution-failed";
+ readonly reason?: string;
+};
+
+export type BuildExecutionAttention = {
+ readonly step: "result" | "cleanup";
+ readonly error: string;
+};
+
+export type BuildExecutionTurn = {
+ readonly owner: string;
+ readonly acquiredAt: number;
+};
+
+export type BuildResultWriteLease = BuildExecutionTurn;
+
+/**
+ * The complete active Runtime root for one Build.
+ *
+ * It has no persisted lifecycle phase. Scheduling is derived from `wakeAt` and `turn`; the one
+ * immutable execution conclusion is `decision`; `stop` records why new work must stop while
+ * the Result is written. Operator attention is an independent fact.
+ */
+export type BuildExecutionSnapshot = BuildExecutionRequest & {
+ readonly createdAt: number;
+ /** An execution context has been assigned; losing it ends this attempt. */
+ readonly startedAt?: number;
+ /** Absent when waiting for a resource release. */
+ readonly wakeAt?: number;
+ /** Only these Operations can advance the Build until their next outcome. */
+ readonly operationWait?: readonly string[];
+ readonly turn?: BuildExecutionTurn;
+ readonly resultWrite?: BuildResultWriteLease;
+ readonly stop?: BuildExecutionStop;
+ readonly decision?: BuildExecutionDecision;
+ readonly attention?: BuildExecutionAttention;
+};
+
+export type BuildExecutionActivity = "ready" | "running" | "waiting" | "saving-result";
+
+export function buildExecutionActivity(
+ execution: BuildExecutionSnapshot,
+ now = Date.now(),
+): BuildExecutionActivity {
+ if (execution.decision !== undefined) return "saving-result";
+ if (execution.turn !== undefined) return "running";
+ return execution.wakeAt === undefined || execution.wakeAt > now ? "waiting" : "ready";
+}
+
+/** Ephemeral acknowledgement returned after active Runtime state has been removed. */
+export type BuildCompletion = BuildExecutionDecision & {
+ readonly build: string;
+};
+
+export type BuildExecutionStore = {
+ create(request: BuildExecutionRequest, options?: { readonly now?: number }): Promise<BuildExecutionSnapshot>;
+ read(build: string): Promise<BuildExecutionSnapshot | undefined>;
+ list(): Promise<readonly BuildExecutionSnapshot[]>;
+ /** Lightweight scheduling views; no Definition, Profile or Operation payloads are loaded. */
+ listUnstarted(): Promise<readonly string[]>;
+ listReady(now?: number): Promise<readonly string[]>;
+ /** Atomically take one ready, undecided execution turn for this Worker owner. */
+ claim(owner: string, now?: number, build?: string): Promise<BuildExecutionSnapshot | undefined>;
+ start(build: string, now?: number): Promise<BuildExecutionSnapshot>;
+ /** Conclude after the owner confirms this execution context has ended. Never repeats external work. */
+ interrupt(build: string, reason: string): Promise<BuildExecutionSnapshot>;
+ /** An unobserved stop wakes the next turn immediately to finish the attempt. */
+ releaseTurn(build: string, owner: string, wakeAt: number | undefined, operationWait?: readonly string[]): Promise<BuildExecutionSnapshot>;
+ /** Freeze the one conclusion. An execution with a decision can never be claimed again. */
+ decide(build: string, owner: string, outcome: BuildOutcome, reason?: string): Promise<BuildExecutionSnapshot>;
+ /** Record the first stop request. Repeated requests cannot replace its cause or reason. */
+ requestStop(build: string, stop: BuildExecutionStop): Promise<BuildExecutionSnapshot>;
+ setAttention(build: string, attention: BuildExecutionAttention | undefined): Promise<BuildExecutionSnapshot>;
+ claimResultWrite(build: string, owner: string, now?: number): Promise<BuildExecutionSnapshot | undefined>;
+ releaseResultWrite(build: string, owner: string): Promise<BuildExecutionSnapshot>;
+ /** Clear only Result-writer ownership left by the previous Runtime process and record attention. */
+ reclaimResultWrites(): Promise<readonly string[]>;
+ acquireCapacity(request: CapacityAcquireRequest): Promise<CapacityAcquire>;
+ releaseCapacity(build: string, command: string): Promise<void>;
+ releaseBuildCapacity(build: string): Promise<void>;
+ reclaimActionCapacity(): Promise<void>;
+ listCapacity(): Promise<readonly CapacityReservation[]>;
+};
diff --git a/packages/runtime-local/src/executor.ts b/packages/runtime-local/src/executor.ts
index 88222669..fd7abcd4 100644
--- a/packages/runtime-local/src/executor.ts
+++ b/packages/runtime-local/src/executor.ts
@@ -1,6 +1,6 @@
import { setImmediate, setTimeout as pause } from "node:timers/promises";
-import { NodeModuleScope } from "@hypit/package-loader-node/module-scope";
-import { SqliteRuntimeState } from "@hypit/store-sqlite";
+import { NodeModuleScope } from "@hypit/hypit/loader/node/module-scope";
+import { SqliteRuntimeState } from "./sqlite-state.js";
import { createRuntimeForBuild, statePath } from "./config.js";
import type { LocalRuntime } from "./types.js";
diff --git a/packages/runtime-local/src/extension.ts b/packages/runtime-local/src/extension.ts
new file mode 100644
index 00000000..63e4b61b
--- /dev/null
+++ b/packages/runtime-local/src/extension.ts
@@ -0,0 +1,317 @@
+import { endpointActions } from "@hypit/hypit/endpoint";
+import type { EndpointInstance } from "@hypit/hypit/endpoint";
+import type { Facet } from "@hypit/hypit/facet";
+import type { CanonicalValue } from "@hypit/hypit/protocol";
+import { credentialRef } from "@hypit/hypit/runtime";
+import type { CredentialRef, CredentialStore, CredentialValue } from "@hypit/hypit/runtime";
+
+export { credentialRef, verifyCredentialRef } from "@hypit/hypit/runtime";
+export type {
+ CredentialRef,
+ CredentialStore,
+ CredentialValue,
+ WritableCredentialStore,
+} from "@hypit/hypit/runtime";
+
+export const runtimeEndpointAdapterFacetAbi = "hypit.runtime-local-endpoint-adapter@1";
+export const runtimeCredentialStoreAdapterFacetAbi = "hypit.runtime-local-credential-store-adapter@1";
+
+export type RuntimeAdapterKind = "endpoint" | "credential-store";
+
+type RuntimeAdapterAddress = {
+ readonly use: string;
+ readonly kind: RuntimeAdapterKind;
+};
+
+export type RuntimeAdapterFactoryContext = {
+ /** Persistent machine/user state supplied by the Host, outside every author project. */
+ readonly hostStateRoot: string;
+ /** Runtime/Profile state belonging to this project. */
+ readonly dataRoot: string;
+ readonly instance: string;
+ readonly pool?: string;
+ readonly config: CanonicalValue;
+};
+
+export type RuntimeDoctorDiagnostic = {
+ readonly severity: "error" | "warning" | "info";
+ readonly code: string;
+ readonly message: string;
+ readonly subject?: string;
+};
+
+export type ManagedProgramCommand = {
+ /** Optional human-readable purpose, supplied by the program owner. Not a lifecycle state. */
+ readonly label?: string;
+ readonly command: string;
+ readonly args: readonly string[];
+ readonly cwd?: string;
+ readonly env?: Readonly<Record<string, string>>;
+};
+
+export type ManagedProgramInstallation = {
+ /** Read-only inspection of the selected environment and resources; no downloads or receipts. */
+ probe(): Promise<ManagedProgramState>;
+ /** Reconcile an installed environment before a cold start, using its package manager's cache. */
+ readonly prepareBeforeStart?: boolean;
+ /** Explicit preparation commands, run for missing resources or cold reconciliation above. */
+ readonly commands: readonly ManagedProgramCommand[];
+};
+
+export type ManagedProgramState =
+ | { readonly state: "ready" }
+ | { readonly state: "down"; readonly detail: string }
+ | { readonly state: "mismatch"; readonly detail: string };
+
+export type ManagedProgram = {
+ readonly id: string;
+ /** Shared lifecycle files live here; absent means this Runtime owns them. */
+ readonly stateRoot?: string;
+ /** Installation and runtime readiness are deliberately separate states. */
+ readonly installation?: ManagedProgramInstallation;
+ probe(): Promise<ManagedProgramState>;
+ readonly start?: ManagedProgramCommand;
+};
+
+export type RuntimeEndpointActivation = {
+ readonly endpoint: EndpointInstance;
+ readonly program?: ManagedProgram;
+ readonly diagnose?: (context: {
+ readonly credentials: Readonly<Record<string, CredentialValue>>;
+ readonly capabilities?: readonly import("@hypit/hypit/protocol").CapabilityRef[];
+ }) => readonly RuntimeDoctorDiagnostic[] | Promise<readonly RuntimeDoctorDiagnostic[]>;
+};
+
+export type RuntimeOpened<T> = {
+ readonly value: T;
+ readonly close?: () => void | Promise<void>;
+};
+
+export type RuntimeEndpointAdapterImplementation = {
+ activate(context: RuntimeAdapterFactoryContext): RuntimeEndpointActivation | Promise<RuntimeEndpointActivation>;
+};
+
+type RuntimeStoreAdapterImplementation<T> = {
+ validate(context: RuntimeAdapterFactoryContext): void;
+ open(context: RuntimeAdapterFactoryContext): RuntimeOpened<T> | Promise<RuntimeOpened<T>>;
+ doctor?(context: RuntimeAdapterFactoryContext): readonly RuntimeDoctorDiagnostic[] | Promise<readonly RuntimeDoctorDiagnostic[]>;
+};
+
+type RuntimeAdapterImplementation =
+ | RuntimeEndpointAdapterImplementation
+ | RuntimeStoreAdapterImplementation<CredentialStore>;
+
+export type RuntimeAdapterFacet = Facet & {
+ readonly abi:
+ | typeof runtimeEndpointAdapterFacetAbi
+ | typeof runtimeCredentialStoreAdapterFacetAbi;
+ readonly implementation: RuntimeAdapterImplementation;
+};
+
+function assert(condition: unknown, message: string): asserts condition {
+ if (!condition) throw new Error(message);
+}
+
+function abiFor(kind: RuntimeAdapterKind): RuntimeAdapterFacet["abi"] {
+ if (kind === "endpoint") return runtimeEndpointAdapterFacetAbi;
+ return runtimeCredentialStoreAdapterFacetAbi;
+}
+
+function address(facet: RuntimeAdapterFacet): RuntimeAdapterAddress {
+ const kind = facet.abi === runtimeEndpointAdapterFacetAbi
+ ? "endpoint"
+ : facet.abi === runtimeCredentialStoreAdapterFacetAbi ? "credential-store" : undefined;
+ assert(kind !== undefined, `Runtime Adapter ${facet.abi} ABI is unsupported`);
+ assert(facet.offers?.length === 1 && facet.offers[0]!.trim().length > 0,
+ "Runtime Adapter must offer exactly one non-empty use name");
+ return { use: facet.offers[0]!, kind };
+}
+
+function verifyImplementation(value: unknown, subject: string, kind: RuntimeAdapterKind): RuntimeAdapterImplementation {
+ assert(value !== null && typeof value === "object", `${subject} implementation is not an object`);
+ if (kind === "endpoint") {
+ assert(typeof (value as { activate?: unknown }).activate === "function", `${subject} does not implement activate()`);
+ return value as RuntimeEndpointAdapterImplementation;
+ }
+ assert(typeof (value as { validate?: unknown }).validate === "function", `${subject} does not implement validate()`);
+ assert(typeof (value as { open?: unknown }).open === "function", `${subject} does not implement open()`);
+ const doctor = (value as { doctor?: unknown }).doctor;
+ assert(doctor === undefined || typeof doctor === "function", `${subject}.doctor must be a function`);
+ return value as RuntimeAdapterImplementation;
+}
+
+function storeFacet<T>(kind: "credential-store", options: {
+ readonly use: string;
+ readonly validate: RuntimeStoreAdapterImplementation<T>["validate"];
+ readonly open: RuntimeStoreAdapterImplementation<T>["open"];
+ readonly doctor?: RuntimeStoreAdapterImplementation<T>["doctor"];
+}): RuntimeAdapterFacet {
+ assert(options.use.trim().length > 0, "Runtime Adapter use name is empty");
+ const implementation = {
+ validate: options.validate,
+ open: options.open,
+ ...(options.doctor === undefined ? {} : { doctor: options.doctor }),
+ };
+ return {
+ abi: abiFor(kind),
+ offers: [options.use],
+ implementation: verifyImplementation(implementation, `Runtime Adapter ${options.use}`, kind),
+ };
+}
+
+export function createRuntimeEndpointAdapterFacet(options: {
+ readonly use: string;
+ readonly activate: RuntimeEndpointAdapterImplementation["activate"];
+}): RuntimeAdapterFacet {
+ assert(options.use.trim().length > 0, "Runtime Adapter use name is empty");
+ return {
+ abi: runtimeEndpointAdapterFacetAbi,
+ offers: [options.use],
+ implementation: verifyImplementation({ activate: options.activate }, `Runtime Adapter ${options.use}`, "endpoint"),
+ };
+}
+
+export function createRuntimeCredentialStoreAdapterFacet(options: {
+ readonly use: string;
+ readonly validate: RuntimeStoreAdapterImplementation<CredentialStore>["validate"];
+ readonly open: RuntimeStoreAdapterImplementation<CredentialStore>["open"];
+ readonly doctor?: RuntimeStoreAdapterImplementation<CredentialStore>["doctor"];
+}): RuntimeAdapterFacet {
+ return storeFacet("credential-store", options);
+}
+
+export function isRuntimeAdapterFacet(value: Facet): value is RuntimeAdapterFacet {
+ try {
+ const resolved = address(value as RuntimeAdapterFacet);
+ verifyImplementation(value.implementation, "Runtime Adapter", resolved.kind);
+ return true;
+ } catch {
+ return false;
+ }
+}
+
+export class RuntimeAdapterRegistry {
+ readonly #registrations = new Map<string, RuntimeAdapterImplementation>();
+
+ #key(use: string, kind: RuntimeAdapterKind): string {
+ return `${kind}\u0000${use}`;
+ }
+
+ registerFacet(facet: Facet): void {
+ assert(isRuntimeAdapterFacet(facet), `Facet ${facet.abi} is not a valid Runtime Adapter`);
+ const resolved = address(facet);
+ const key = this.#key(resolved.use, resolved.kind);
+ assert(!this.#registrations.has(key), `Runtime ${resolved.kind} Adapter ${resolved.use} is already registered`);
+ this.#registrations.set(key, facet.implementation);
+ }
+
+ has(use: string, kind: RuntimeAdapterKind): boolean {
+ return this.#registrations.has(this.#key(use, kind));
+ }
+
+ async activateEndpoint(use: string, context: RuntimeAdapterFactoryContext): Promise<RuntimeEndpointActivation> {
+ const implementation = this.#registrations.get(this.#key(use, "endpoint")) as RuntimeEndpointAdapterImplementation | undefined;
+ assert(implementation !== undefined, `Runtime Endpoint adapter ${use} is not registered`);
+ const activation = await implementation.activate(context);
+ assert(activation.endpoint.instance.id === context.instance,
+ `Runtime Endpoint adapter ${use} created Endpoint ${activation.endpoint.instance.id} outside configured instance ${context.instance}`);
+ return activation;
+ }
+
+ async createEndpoint(use: string, context: RuntimeAdapterFactoryContext): Promise<EndpointInstance> {
+ return (await this.activateEndpoint(use, context)).endpoint;
+ }
+
+ async #openStore<T>(use: string, kind: "credential-store", context: RuntimeAdapterFactoryContext): Promise<RuntimeOpened<T>> {
+ const implementation = this.#registrations.get(this.#key(use, kind)) as RuntimeStoreAdapterImplementation<T> | undefined;
+ assert(implementation !== undefined, `Runtime ${kind} adapter ${use} is not registered`);
+ implementation.validate(context);
+ const opened = await implementation.open(context);
+ assert(opened.value !== null && typeof opened.value === "object", `Runtime ${kind} adapter ${use} returned no value`);
+ return opened;
+ }
+
+ async openCredentialStore(use: string, context: RuntimeAdapterFactoryContext): Promise<RuntimeOpened<CredentialStore>> {
+ return await this.#openStore(use, "credential-store", context);
+ }
+
+ validate(use: string, kind: Exclude<RuntimeAdapterKind, "endpoint">, context: RuntimeAdapterFactoryContext): readonly RuntimeDoctorDiagnostic[] {
+ const implementation = this.#registrations.get(this.#key(use, kind)) as RuntimeStoreAdapterImplementation<unknown> | undefined;
+ if (implementation === undefined) return [{
+ severity: "error", code: "RUNTIME_ADAPTER_MISSING", message: `Runtime Adapter ${use} is not registered`, subject: use,
+ }];
+ implementation.validate(context);
+ return [];
+ }
+
+ async doctor(use: string, kind: Exclude<RuntimeAdapterKind, "endpoint">, context: RuntimeAdapterFactoryContext): Promise<readonly RuntimeDoctorDiagnostic[]> {
+ const implementation = this.#registrations.get(this.#key(use, kind)) as RuntimeStoreAdapterImplementation<unknown> | undefined;
+ if (implementation === undefined) return [{
+ severity: "error", code: "RUNTIME_ADAPTER_MISSING", message: `Runtime Adapter ${use} is not registered`, subject: use,
+ }];
+ return implementation.doctor === undefined ? [] : await implementation.doctor(context);
+ }
+}
+
+export function runtimeConfigObject(value: CanonicalValue, subject: string): Record<string, CanonicalValue> {
+ assert(value !== null && typeof value === "object" && !Array.isArray(value), `${subject} config must be an object`);
+ return value as Record<string, CanonicalValue>;
+}
+
+export function runtimeConfigExact(value: Record<string, CanonicalValue>, allowed: readonly string[], subject: string): void {
+ const unknown = Object.keys(value).filter((key) => !allowed.includes(key));
+ assert(unknown.length === 0, `${subject} config does not accept ${unknown[0]}`);
+}
+
+export function runtimeConfigString(value: CanonicalValue | undefined, subject: string): string | undefined {
+ if (value === undefined) return undefined;
+ assert(typeof value === "string" && value.trim().length > 0, `${subject} must be a non-empty string`);
+ return value;
+}
+
+export function runtimeConfigPositiveInteger(value: CanonicalValue | undefined, subject: string): number | undefined {
+ if (value === undefined) return undefined;
+ assert(typeof value === "number" && Number.isSafeInteger(value) && value > 0, `${subject} must be a positive integer`);
+ return value;
+}
+
+export function runtimeConfigBoolean(value: CanonicalValue | undefined, subject: string): boolean | undefined {
+ if (value === undefined) return undefined;
+ assert(typeof value === "boolean", `${subject} must be a boolean`);
+ return value;
+}
+
+export function runtimeConfigCredentialRef(
+ value: CanonicalValue | undefined,
+ subject: string,
+): CredentialRef | undefined {
+ if (value === undefined) return undefined;
+ const object = runtimeConfigObject(value, subject);
+ runtimeConfigExact(object, ["store", "key"], subject);
+ const store = runtimeConfigString(object.store, `${subject}.store`);
+ const key = runtimeConfigString(object.key, `${subject}.key`);
+ assert(store !== undefined && key !== undefined, `${subject} requires store and key`);
+ return credentialRef(store, key);
+}
+
+/** Common Profile representation for short action occupancy and rate budgets. */
+export function runtimeConfigActionLimits(value: CanonicalValue | undefined): import("@hypit/hypit/endpoint").EndpointActionLimits | undefined {
+ if (value === undefined) return undefined;
+ const actions = runtimeConfigObject(value, "actionLimits");
+ runtimeConfigExact(actions, endpointActions, "actionLimits");
+ return Object.fromEntries(Object.entries(actions).map(([action, raw]) => {
+ const limit = runtimeConfigObject(raw, `actionLimits.${action}`);
+ runtimeConfigExact(limit, ["concurrency", "rate"], `actionLimits.${action}`);
+ const concurrency = runtimeConfigPositiveInteger(limit.concurrency, `${action} concurrency`);
+ let rate: { limit: number; periodMs: number } | undefined;
+ if (limit.rate !== undefined) {
+ const item = runtimeConfigObject(limit.rate, `${action} rate`);
+ runtimeConfigExact(item, ["limit", "periodMs"], `${action} rate`);
+ const units = runtimeConfigPositiveInteger(item.limit, `${action} rate.limit`);
+ const periodMs = runtimeConfigPositiveInteger(item.periodMs, `${action} rate.periodMs`);
+ if (units === undefined || periodMs === undefined) throw new Error(`${action} rate requires limit and periodMs`);
+ rate = { limit: units, periodMs };
+ }
+ return [action, { ...(concurrency === undefined ? {} : { concurrency }), ...(rate === undefined ? {} : { rate }) }];
+ }));
+}
diff --git a/packages/runtime-host-node/src/index.ts b/packages/runtime-local/src/host-api.ts
similarity index 59%
rename from packages/runtime-host-node/src/index.ts
rename to packages/runtime-local/src/host-api.ts
index a106a904..08b1bc60 100644
--- a/packages/runtime-host-node/src/index.ts
+++ b/packages/runtime-local/src/host-api.ts
@@ -1,23 +1,17 @@
-import { access } from "node:fs/promises";
-import { constants } from "node:fs";
-import { homedir } from "node:os";
-import { delimiter, isAbsolute, join, resolve } from "node:path";
-import type { ArtifactAttachment } from "@hypit/workspace";
-import type { BuildResultForward } from "@hypit/build-result";
-import type { BuildResultRepositoryLocation } from "@hypit/build-result-kit";
-import type { DriverRunResult, NodeDriverOptions, ProducerRegistry } from "@hypit/driver-node";
-import type { BuildDefinition, BuildState, CanonicalValue, CapabilityRef, Need, StoredValue } from "@hypit/protocol";
+import type { BlobAttachment } from "@hypit/hypit/workspace";
+import type { BuildResultForward } from "@hypit/hypit/result";
+import type { ExecutorRunResult, ExecutorOptions, ProducerRegistry } from "@hypit/hypit/executor";
+import type { BuildDefinition, BuildState, CanonicalValue, CapabilityRef, Need, StoredValue } from "@hypit/hypit/protocol";
import type {
- BuildCatalogDescriptor,
- BuildCompletion,
- BuildExecutionStop,
CapacityReservation,
CredentialAcquisition,
CredentialRef,
OperationSnapshot,
ResourceStore,
-} from "@hypit/runtime";
-import type { RuntimeDoctorDiagnostic } from "@hypit/runtime-kit";
+} from "@hypit/hypit/runtime";
+import type { BuildCatalogDescriptor } from "./catalog.js";
+import type { BuildCompletion, BuildExecutionStop, BuildResultRepositoryLocation } from "./execution.js";
+import type { RuntimeDoctorDiagnostic } from "@hypit/runtime-local/extension";
export type RuntimeHostActiveBuildSubmission = {
readonly id: string;
@@ -37,7 +31,7 @@ export type BuildActivity = "submitting" | "ready" | "running" | "waiting" | "sa
export type BuildOperationView = {
readonly id?: string;
- readonly receipt?: import("@hypit/runtime").OperationReceipt;
+ readonly receipt?: import("@hypit/hypit/runtime").OperationReceipt;
readonly wakeAt?: number;
readonly endpoint: string;
readonly status: OperationSnapshot["status"];
@@ -86,7 +80,7 @@ export type RuntimeHostCredentialStatus = RuntimeHostCredentialDescription & {
export type RuntimeHostControl = {
/** Build evidence while active. Finished evidence is read through its Result Repository. */
- logs?(build: string, lines: number): Promise<import("@hypit/runtime").ExecutionLogView | undefined>;
+ logs?(build: string, lines: number): Promise<import("@hypit/hypit/runtime").ExecutionLogView | undefined>;
inspect(build: string): Promise<BuildView | undefined>;
activity(): Promise<{
readonly builds: readonly BuildView[];
@@ -123,15 +117,15 @@ export type RuntimeHostExecution = RuntimeHostControl & RuntimeHostCredentialCon
build(request: {
readonly id: string;
readonly definition: BuildDefinition;
- readonly componentPackages?: readonly string[];
+ readonly executionPackages?: readonly string[];
readonly catalog: BuildCatalogDescriptor;
- readonly attachments?: readonly ArtifactAttachment[];
+ readonly attachments?: readonly BlobAttachment[];
/** Project-owned Result destination, fixed before this Build becomes active. */
readonly result: {
readonly repository: BuildResultRepositoryLocation;
readonly title?: string;
readonly forwards?: readonly BuildResultForward[];
- readonly resourceReferences?: Readonly<Record<string, import("@hypit/build-result").BuildResultFileRef>>;
+ readonly resourceReferences?: Readonly<Record<string, import("@hypit/hypit/result").BuildResultFileRef>>;
};
}, options?: {
readonly follow?: boolean;
@@ -155,9 +149,9 @@ export type RuntimeHostTransientExecution = {
evaluate(input: {
readonly state: BuildState;
readonly producers: ProducerRegistry;
- readonly validators: NonNullable<NodeDriverOptions["validators"]>;
+ readonly validators: NonNullable<ExecutorOptions["validators"]>;
readonly resources: ResourceStore;
- }): Promise<DriverRunResult>;
+ }): Promise<ExecutorRunResult>;
close(): void | Promise<void>;
};
@@ -195,9 +189,9 @@ export type RuntimeHostCapabilityPricing = RuntimeHostCapabilityProvider & {
export type RuntimeHostProviderQuery = {
readonly request: string;
readonly capability: CapabilityRef;
- readonly returns: import("@hypit/protocol").TypeRef;
+ readonly returns: import("@hypit/hypit/protocol").TypeRef;
/** Complete support-relevant parameters available before the Build. */
- readonly constraints: import("@hypit/protocol").CanonicalValue;
+ readonly constraints: import("@hypit/hypit/protocol").CanonicalValue;
/** Future graph inputs described by the package that owns this request. */
readonly pendingInputs?: readonly {
readonly input: string;
@@ -205,28 +199,6 @@ export type RuntimeHostProviderQuery = {
}[];
};
-export type ManagedProgramProgress = {
- readonly id: string;
- readonly phase: "checking" | "installing" | "starting" | "waiting" | "ready";
- readonly logPath?: string;
- readonly detail?: string;
-};
-
-export type ManagedProgramReport = {
- readonly id: string;
- readonly endpoint: string;
- readonly action?: "already-running" | "installed" | "started" | "stopped" | "not-ours" | "nothing-to-stop" | "unchanged";
- readonly state:
- | { readonly state: "ready" }
- | { readonly state: "down"; readonly detail: string }
- | { readonly state: "mismatch"; readonly detail: string };
- readonly detail?: string;
- readonly logPath?: string;
- readonly installationLogPath?: string;
- readonly errorLogPath?: string;
- readonly pid?: number;
-};
-
export type RuntimeWorkerState = {
readonly state: "running" | "stopped";
readonly profile: string;
@@ -245,25 +217,28 @@ export type RuntimeController = {
down(options?: { readonly maxWaitMs?: number }): Promise<RuntimeWorkerState>;
};
readonly programs: {
- prepare(options?: { readonly endpoints?: readonly string[]; readonly onProgress?: (event: ManagedProgramProgress) => void }): Promise<{ readonly dataRoot: string; readonly programs: readonly ManagedProgramReport[] }>;
+ prepare(options?: { readonly endpoints?: readonly string[]; readonly onProgress?: (event: import("./programs.js").ManagedProgramProgress) => void }): Promise<{ readonly dataRoot: string; readonly programs: readonly import("./programs.js").ManagedProgramReport[] }>;
up(options: {
readonly maxWaitMs?: number;
- readonly onProgress?: (event: ManagedProgramProgress) => void;
+ readonly onProgress?: (event: import("./programs.js").ManagedProgramProgress) => void;
readonly capabilities?: readonly CapabilityRef[];
readonly endpoints?: readonly string[];
- }): Promise<{ readonly dataRoot: string; readonly programs: readonly ManagedProgramReport[] }>;
- down(options?: { readonly endpoints?: readonly string[] }): Promise<{ readonly dataRoot: string; readonly programs: readonly ManagedProgramReport[] }>;
- report(options?: { readonly endpoints?: readonly string[] }): Promise<{ readonly dataRoot: string; readonly programs: readonly ManagedProgramReport[] }>;
+ }): Promise<{ readonly dataRoot: string; readonly programs: readonly import("./programs.js").ManagedProgramReport[] }>;
+ down(options?: { readonly endpoints?: readonly string[] }): Promise<{ readonly dataRoot: string; readonly programs: readonly import("./programs.js").ManagedProgramReport[] }>;
+ report(options?: { readonly endpoints?: readonly string[] }): Promise<{ readonly dataRoot: string; readonly programs: readonly import("./programs.js").ManagedProgramReport[] }>;
};
};
export type RuntimeWorkerLaunch = {
readonly command: string;
readonly args: readonly string[];
+ readonly workerArgs?: readonly string[];
};
-export type NodeRuntimeHost = {
+export type LocalRuntimeHost = {
readonly profile: string;
+ executionStatus(): Promise<{ readonly state: "running" | "stopped" }>;
+ ensureExecution(options?: { readonly maxWaitMs?: number }): Promise<{ readonly state: "running" | "stopped" }>;
resolvePaths(): Promise<{
readonly packageRoot?: string;
readonly runtimeDataRoot?: string;
@@ -276,11 +251,6 @@ export type NodeRuntimeHost = {
/** Open only Result-writing dependencies; never construct execution Providers. */
openResultControl(): Promise<RuntimeHostResultControl>;
openCredentials(endpoint: string): Promise<RuntimeHostCredentialControl>;
- /** Explicitly prepare upstream packages selected by this Runtime Profile. */
- prepare(options?: {
- readonly onProgress?: (event: import("./packages.js").HostPackageProgress) => void;
- readonly endpoints?: readonly string[];
- }): Promise<readonly import("./packages.js").HostPackageReport[]>;
/**
* Read-only, bounded deployment validation for one demanded Build slice.
* It may inspect local files, credentials and loopback program state, but it
@@ -315,133 +285,6 @@ export type NodeRuntimeHost = {
/** Progress stays with the selected Provider; immediate calls need no synthetic Build. */
export type RuntimeInvocationObservation = {
- readonly reportProgress?: (progress: import("@hypit/runtime").OperationProgress) => Promise<void>;
- readonly reportDiagnostic?: (diagnostic: import("@hypit/runtime").ExecutionDiagnostic) => Promise<void>;
+ readonly reportProgress?: (progress: import("@hypit/hypit/runtime").OperationProgress) => Promise<void>;
+ readonly reportDiagnostic?: (diagnostic: import("@hypit/hypit/runtime").ExecutionDiagnostic) => Promise<void>;
};
-
-/**
- * Persistent state owned by the installed Hypit Host, never by an author project
- * or a replaceable source checkout.
- */
-export function hypitHostStateRoot(options: {
- readonly env?: NodeJS.ProcessEnv;
- readonly platform?: NodeJS.Platform;
- readonly home?: string;
-} = {}): string {
- const env = options.env ?? process.env;
- const override = env.HYPIT_STATE_HOME;
- if (override !== undefined && override.trim().length > 0) return resolve(override);
- const platform = options.platform ?? process.platform;
- const home = options.home ?? homedir();
- if (platform === "darwin") return join(home, "Library", "Application Support", "Hypit");
- if (platform === "win32") {
- const local = env.LOCALAPPDATA;
- return join(local === undefined || local.trim().length === 0
- ? join(home, "AppData", "Local")
- : local, "Hypit");
- }
- const state = env.XDG_STATE_HOME;
- return join(state === undefined || state.trim().length === 0
- ? join(home, ".local", "state")
- : state, "hypit");
-}
-
-/** Home of version-isolated upstream npm installations shared across projects. */
-export function hypitHostPackageRoot(hostStateRoot = hypitHostStateRoot()): string {
- return join(resolve(hostStateRoot), "packages");
-}
-
-function pathLike(value: string): boolean {
- return isAbsolute(value) || value.includes("/") || value.includes("\\");
-}
-
-/** Bare command names remain PATH-resolved; configured relative paths are rooted at the Runtime Profile root. */
-export function resolveRuntimeExecutable(root: string, value: string): string {
- return pathLike(value) && !isAbsolute(value) ? resolve(root, value) : value;
-}
-
-async function executableExists(value: string): Promise<boolean> {
- const unavailable = (error: unknown) => error instanceof Error && "code" in error
- && ["ENOENT", "ENOTDIR", "EACCES"].includes(String(error.code));
- const extensions = process.platform === "win32" && !/\.[^\\/]+$/u.test(value)
- ? (process.env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean)
- : [];
- // A configured path names one file, and on Windows this asks only whether that file is there, so
- // it is tried as written before any PATHEXT extension. A bare command name is resolved the way a
- // shell would resolve it, where an extensionless entry is not something Windows can run.
- const candidates = (base: string, suffixes: readonly string[]) =>
- (suffixes.length === 0 ? [""] : suffixes).map((suffix) => `${base}${suffix}`);
- const available = async (candidate: string): Promise<boolean> => {
- try {
- await access(candidate, process.platform === "win32" ? constants.F_OK : constants.X_OK);
- return true;
- } catch (error) {
- if (unavailable(error)) return false;
- throw error;
- }
- };
- if (pathLike(value)) {
- for (const candidate of candidates(value, ["", ...extensions])) if (await available(candidate)) return true;
- return false;
- }
- for (const directory of (process.env.PATH ?? "").split(delimiter).filter(Boolean)) {
- for (const candidate of candidates(resolve(directory, value), extensions)) {
- if (await available(candidate)) return true;
- }
- }
- return false;
-}
-
-export async function diagnoseRuntimeExecutable(options: {
- readonly root: string;
- readonly configured: string | undefined;
- readonly fallback: string;
- readonly subject: string;
-}): Promise<readonly RuntimeDoctorDiagnostic[]> {
- const value = resolveRuntimeExecutable(options.root, options.configured ?? options.fallback);
- return await executableExists(value) ? [] : [{
- severity: "error",
- code: "RUNTIME_EXECUTABLE_MISSING",
- message: `${options.subject} executable ${value} is unavailable`,
- subject: value,
- }];
-}
-
-export function diagnoseRuntimeEnvironmentCredential(
- variable: string,
- subject: string,
-): readonly RuntimeDoctorDiagnostic[] {
- return process.env[variable]?.trim()
- ? []
- : [{
- severity: "error",
- code: "RUNTIME_CREDENTIAL_MISSING",
- message: `${subject} requires environment variable ${variable}`,
- subject: variable,
- }];
-}
-
-/** Executables inside a Python virtual environment have one platform-defined layout. */
-export function pythonEnvironmentExecutable(environment: string): string {
- return process.platform === "win32"
- ? resolve(environment, "Scripts", "python.exe")
- : resolve(environment, "bin", "python");
-}
-
-/** Console scripts installed by Python use an executable shim on Windows. */
-export function pythonEnvironmentCommand(environment: string, name: string): string {
- return process.platform === "win32"
- ? resolve(environment, "Scripts", `${name}.exe`)
- : resolve(environment, "bin", name);
-}
-
-export {
- inspectHostPackage,
- parseRegistryPackageSpec,
- prepareHostPackages,
-} from "./packages.js";
-export type {
- HostPackageProgress,
- HostPackageReport,
- RegistryPackageSpec,
-} from "./packages.js";
diff --git a/packages/runtime-local/src/host.ts b/packages/runtime-local/src/host.ts
index c731ed4d..a882b68c 100644
--- a/packages/runtime-local/src/host.ts
+++ b/packages/runtime-local/src/host.ts
@@ -1,9 +1,9 @@
import type {
- NodeRuntimeHost,
+ LocalRuntimeHost,
RuntimeController,
RuntimeWorkerLaunch,
-} from "@hypit/runtime-host-node";
-import { hypitHostStateRoot } from "@hypit/runtime-host-node";
+} from "./host-api.js";
+import { hypitHostStateRoot } from "@hypit/hypit/cli";
import { resolve } from "node:path";
import { superviseBuilds } from "./supervisor.js";
@@ -16,7 +16,6 @@ import {
doctorRuntimeConfig,
invokeRuntimeConfigNeed,
openTransientRuntimeConfigExecution,
- prepareRuntimeConfigPackages,
preflightRuntimeConfig,
readRuntimeConfigPricing,
resolveRuntimeConfigPaths,
@@ -43,7 +42,7 @@ export async function openLocalRuntimeHost(
readonly hostStateRoot?: string;
readonly workerLaunch: RuntimeWorkerLaunch;
},
-): Promise<NodeRuntimeHost> {
+): Promise<LocalRuntimeHost> {
const profile = resolve(path);
const basePackageRoot = resolve(hostOptions.packageRoot);
const distribution = {
@@ -92,6 +91,14 @@ export async function openLocalRuntimeHost(
};
return {
profile,
+ executionStatus: async () => {
+ const selected = await controller();
+ return await selected.worker.status();
+ },
+ ensureExecution: async (options) => {
+ const selected = await controller();
+ return await selected.worker.up(options);
+ },
resolvePaths: async () => {
const selection = await resolveRuntimeConfigPaths(profile, {
packageRoot: basePackageRoot,
@@ -120,12 +127,6 @@ export async function openLocalRuntimeHost(
endpoint,
{ packageRoot: basePackageRoot, ...distribution },
),
- prepare: async (options) => await prepareRuntimeConfigPackages(profile, {
- packageRoot: basePackageRoot,
- ...distribution,
- ...(options?.onProgress === undefined ? {} : { onProgress: options.onProgress }),
- ...(options?.endpoints === undefined ? {} : { endpoints: options.endpoints }),
- }),
preflight: async (options) => await preflightRuntimeConfig(profile, {
packageRoot: basePackageRoot,
...distribution,
@@ -177,7 +178,11 @@ export async function openLocalRuntimeHost(
const paths = await resolveRuntimeConfigPaths(profile, { packageRoot: basePackageRoot, ...distribution });
await superviseBuilds({
profile, dataRoot: paths.dataRoot, readyFile, owner,
- launch: hostOptions.workerLaunch, signal: abort.signal,
+ launch: {
+ ...hostOptions.workerLaunch,
+ workerArgs: ["--package-root", basePackageRoot],
+ },
+ signal: abort.signal,
ready: async () => await markRuntimeProcessReady(readyFile, owner),
});
}
diff --git a/packages/runtime-local/src/index.ts b/packages/runtime-local/src/index.ts
index e4273a98..da06ded4 100644
--- a/packages/runtime-local/src/index.ts
+++ b/packages/runtime-local/src/index.ts
@@ -7,6 +7,10 @@ export {
createLocalRuntime,
} from "./runtime.js";
export { openLocalRuntimeHost } from "./host.js";
+export { clearRuntimeProfile, findRuntimeProfile, selectRuntimeProfile } from "./profile-selection.js";
+export type { RuntimeProfileSelection } from "./profile-selection.js";
+export * from "./host-api.js";
+export { FileResourceStore } from "./resource-store.js";
export {
createRuntimeFromConfig,
createRuntimeControlFromConfig,
@@ -20,7 +24,6 @@ export {
doctorRuntimeConfig,
invokeRuntimeConfigNeed,
openTransientRuntimeConfigExecution,
- prepareRuntimeConfigPackages,
preflightRuntimeConfig,
readRuntimeConfigPricing,
parseLocalRuntimeProfile,
@@ -35,3 +38,7 @@ export {
export type * from "./types.js";
export type * from "./config.js";
export type * from "./programs.js";
+export type * from "./catalog.js";
+export type * from "./submission.js";
+export { buildExecutionActivity } from "./execution.js";
+export type * from "./execution.js";
diff --git a/packages/runtime-local/src/log.ts b/packages/runtime-local/src/log.ts
index fd185da9..81bd04a3 100644
--- a/packages/runtime-local/src/log.ts
+++ b/packages/runtime-local/src/log.ts
@@ -1,8 +1,8 @@
import { createReadStream } from "node:fs";
import { appendFile, mkdir, stat } from "node:fs/promises";
import { join } from "node:path";
-import { readExecutionLog } from "@hypit/runtime";
-import type { ExecutionLogEvent, ExecutionLogRecord, ExecutionLogView } from "@hypit/runtime";
+import { readExecutionLog } from "@hypit/hypit/runtime";
+import type { ExecutionLogEvent, ExecutionLogRecord, ExecutionLogView } from "@hypit/hypit/runtime";
export type LocalExecutionLogs = {
record(build: string, command: string, event: ExecutionLogEvent): Promise<void>;
diff --git a/packages/runtime-local/src/node.ts b/packages/runtime-local/src/node.ts
new file mode 100644
index 00000000..14f24de9
--- /dev/null
+++ b/packages/runtime-local/src/node.ts
@@ -0,0 +1,86 @@
+import { constants } from "node:fs";
+import { access } from "node:fs/promises";
+import { delimiter, isAbsolute, resolve } from "node:path";
+
+import type { RuntimeDoctorDiagnostic } from "./extension.js";
+
+function pathLike(value: string): boolean {
+ return isAbsolute(value) || value.includes("/") || value.includes("\\");
+}
+
+/** Bare command names remain PATH-resolved; configured relative paths are rooted at the Runtime Profile root. */
+export function resolveRuntimeExecutable(root: string, value: string): string {
+ return pathLike(value) && !isAbsolute(value) ? resolve(root, value) : value;
+}
+
+async function executableExists(value: string): Promise<boolean> {
+ const unavailable = (error: unknown) => error instanceof Error && "code" in error
+ && ["ENOENT", "ENOTDIR", "EACCES"].includes(String(error.code));
+ const extensions = process.platform === "win32" && !/\.[^\\/]+$/u.test(value)
+ ? (process.env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean)
+ : [];
+ const candidates = (base: string, suffixes: readonly string[]) =>
+ (suffixes.length === 0 ? [""] : suffixes).map((suffix) => `${base}${suffix}`);
+ const available = async (candidate: string): Promise<boolean> => {
+ try {
+ await access(candidate, process.platform === "win32" ? constants.F_OK : constants.X_OK);
+ return true;
+ } catch (error) {
+ if (unavailable(error)) return false;
+ throw error;
+ }
+ };
+ if (pathLike(value)) {
+ for (const candidate of candidates(value, ["", ...extensions])) if (await available(candidate)) return true;
+ return false;
+ }
+ for (const directory of (process.env.PATH ?? "").split(delimiter).filter(Boolean)) {
+ for (const candidate of candidates(resolve(directory, value), extensions)) {
+ if (await available(candidate)) return true;
+ }
+ }
+ return false;
+}
+
+export async function diagnoseRuntimeExecutable(options: {
+ readonly root: string;
+ readonly configured: string | undefined;
+ readonly fallback: string;
+ readonly subject: string;
+}): Promise<readonly RuntimeDoctorDiagnostic[]> {
+ const value = resolveRuntimeExecutable(options.root, options.configured ?? options.fallback);
+ return await executableExists(value) ? [] : [{
+ severity: "error",
+ code: "RUNTIME_EXECUTABLE_MISSING",
+ message: `${options.subject} executable ${value} is unavailable`,
+ subject: value,
+ }];
+}
+
+export function diagnoseRuntimeEnvironmentCredential(
+ variable: string,
+ subject: string,
+): readonly RuntimeDoctorDiagnostic[] {
+ return process.env[variable]?.trim()
+ ? []
+ : [{
+ severity: "error",
+ code: "RUNTIME_CREDENTIAL_MISSING",
+ message: `${subject} requires environment variable ${variable}`,
+ subject: variable,
+ }];
+}
+
+/** Executables inside a Python virtual environment have one platform-defined layout. */
+export function pythonEnvironmentExecutable(environment: string): string {
+ return process.platform === "win32"
+ ? resolve(environment, "Scripts", "python.exe")
+ : resolve(environment, "bin", "python");
+}
+
+/** Console scripts installed by Python use an executable shim on Windows. */
+export function pythonEnvironmentCommand(environment: string, name: string): string {
+ return process.platform === "win32"
+ ? resolve(environment, "Scripts", `${name}.exe`)
+ : resolve(environment, "bin", name);
+}
diff --git a/packages/runtime-local/src/profile-selection.ts b/packages/runtime-local/src/profile-selection.ts
new file mode 100644
index 00000000..73b0fa60
--- /dev/null
+++ b/packages/runtime-local/src/profile-selection.ts
@@ -0,0 +1,84 @@
+import { mkdir, readFile, realpath, stat, unlink, writeFile } from "node:fs/promises";
+import { relative, resolve } from "node:path";
+
+const stateDirectoryName = ".hypit";
+const selectionFileName = "runtime";
+
+export type RuntimeProfileSelection = {
+ readonly profile: string;
+ readonly projectRoot: string;
+ readonly selectionFile: string;
+};
+
+function errorCode(error: unknown): string | undefined {
+ return error !== null && typeof error === "object" && "code" in error
+ ? String((error as { readonly code?: unknown }).code)
+ : undefined;
+}
+
+async function readSelectionFile(projectRoot: string): Promise<{
+ readonly projectRoot: string;
+ readonly selectionFile: string;
+ readonly value: string;
+} | undefined> {
+ const root = resolve(projectRoot);
+ const selectionFile = resolve(root, stateDirectoryName, selectionFileName);
+ try {
+ if (!(await stat(selectionFile)).isFile()) {
+ throw new Error(`Runtime selection must be a file: ${selectionFile}; this path is occupied by a directory. `
+ + "Move that directory and update its configuration before running hypit runtime use <profile>.");
+ }
+ return { projectRoot: root, selectionFile, value: (await readFile(selectionFile, "utf8")).trim() };
+ } catch (error) {
+ if (errorCode(error) === "ENOENT") return undefined;
+ throw error;
+ }
+}
+
+/** Remember one Local Runtime Profile for a project without changing project Sources. */
+export async function selectRuntimeProfile(projectRoot: string, profile: string): Promise<RuntimeProfileSelection> {
+ const root = await realpath(resolve(projectRoot));
+ const selectedProfile = await realpath(resolve(profile));
+ const stateDirectory = resolve(root, stateDirectoryName);
+ const selectionFile = resolve(stateDirectory, selectionFileName);
+ await mkdir(stateDirectory, { recursive: true });
+ try {
+ await writeFile(resolve(stateDirectory, ".gitignore"), "*\n", { encoding: "utf8", flag: "wx" });
+ } catch (error) {
+ if (errorCode(error) !== "EEXIST") throw error;
+ }
+ await readSelectionFile(root);
+ await writeFile(selectionFile, `${relative(root, selectedProfile) || "."}\n`, "utf8");
+ return { profile: selectedProfile, projectRoot: root, selectionFile };
+}
+
+/** Read only the explicitly resolved project's Local Runtime selection. */
+export async function findRuntimeProfile(projectRoot: string): Promise<RuntimeProfileSelection | undefined> {
+ const selected = await readSelectionFile(projectRoot);
+ if (selected === undefined) return undefined;
+ if (selected.value.length === 0) {
+ throw new Error(`Runtime selection is empty: ${selected.selectionFile}; run hypit runtime use <profile>`);
+ }
+ const candidate = resolve(selected.projectRoot, selected.value);
+ try {
+ return {
+ profile: await realpath(candidate),
+ projectRoot: selected.projectRoot,
+ selectionFile: selected.selectionFile,
+ };
+ } catch (error) {
+ if (errorCode(error) === "ENOENT") {
+ throw new Error(`Selected Runtime Profile no longer exists: ${candidate}; run hypit runtime use <profile>`);
+ }
+ throw error;
+ }
+}
+
+/** Remove only the project-local pointer. Runtime state, Programs and Builds are untouched. */
+export async function clearRuntimeProfile(projectRoot: string): Promise<RuntimeProfileSelection | undefined> {
+ const selected = await readSelectionFile(projectRoot);
+ if (selected === undefined) return undefined;
+ const profile = resolve(selected.projectRoot, selected.value);
+ await unlink(selected.selectionFile);
+ return { profile, projectRoot: selected.projectRoot, selectionFile: selected.selectionFile };
+}
diff --git a/packages/runtime-local/src/programs.ts b/packages/runtime-local/src/programs.ts
index e820cf0e..700b5b31 100644
--- a/packages/runtime-local/src/programs.ts
+++ b/packages/runtime-local/src/programs.ts
@@ -3,8 +3,8 @@ import { mkdir, open, readFile, rename, rm, stat, writeFile } from "node:fs/prom
import { basename, join } from "node:path";
import { setTimeout as sleep } from "node:timers/promises";
-import type { CapabilityRef } from "@hypit/protocol";
-import type { ManagedProgram, ManagedProgramCommand, ManagedProgramState } from "@hypit/runtime-kit";
+import type { CapabilityRef } from "@hypit/hypit/protocol";
+import type { ManagedProgram, ManagedProgramCommand, ManagedProgramState } from "@hypit/runtime-local/extension";
import { declaredManagedPrograms } from "./config.js";
import type { LoadRuntimeConfigOptions } from "./config.js";
diff --git a/packages/resource-store-fs/src/store.ts b/packages/runtime-local/src/resource-store.ts
similarity index 96%
rename from packages/resource-store-fs/src/store.ts
rename to packages/runtime-local/src/resource-store.ts
index 4b05fd5c..06202e77 100644
--- a/packages/resource-store-fs/src/store.ts
+++ b/packages/runtime-local/src/resource-store.ts
@@ -9,9 +9,9 @@ import {
} from "node:fs/promises";
import { join, resolve } from "node:path";
-import { isResourceId } from "@hypit/protocol";
-import type { BlobRef, ResourceId } from "@hypit/protocol";
-import type { ResourceIOOptions, ResourceStore } from "@hypit/runtime";
+import { isResourceId } from "@hypit/hypit/protocol";
+import type { BlobRef, ResourceId } from "@hypit/hypit/protocol";
+import type { ResourceIOOptions, ResourceStore } from "@hypit/hypit/runtime";
function resourcePath(root: string, resource: ResourceId): string {
if (!isResourceId(resource)) throw new Error("Resource id is invalid");
diff --git a/packages/runtime-local/src/result-writer.ts b/packages/runtime-local/src/result-writer.ts
index c966811f..44832e83 100644
--- a/packages/runtime-local/src/result-writer.ts
+++ b/packages/runtime-local/src/result-writer.ts
@@ -1,13 +1,13 @@
import { randomUUID } from "node:crypto";
-import { BuildMachine } from "@hypit/core";
-import { isStreamingResourceStore } from "@hypit/runtime";
+import { BuildMachine } from "@hypit/hypit/kernel";
+import { isStreamingResourceStore } from "@hypit/hypit/runtime";
import type {
- BuildExecutionSnapshot,
BuildSnapshot,
OperationSnapshot,
-} from "@hypit/runtime";
-import type { CommandResult } from "@hypit/protocol";
-import type { BuildResultWriter } from "@hypit/build-result";
+} from "@hypit/hypit/runtime";
+import type { BuildExecutionSnapshot } from "./execution.js";
+import type { CommandResult } from "@hypit/hypit/protocol";
+import type { BuildResultWriter } from "@hypit/hypit/result";
import type {
CreateLocalResultWriterOptions,
@@ -55,7 +55,7 @@ export function createLocalResultWriter(
const owner = randomUUID();
const openWriter = async (execution: BuildExecutionSnapshot): Promise<{
readonly writer: BuildResultWriter;
- readonly manifest: import("@hypit/build-result").BuildResultManifest;
+ readonly manifest: import("@hypit/hypit/result").BuildResultManifest;
close(): Promise<void>;
}> => {
const opened = await options.openBuildResultRepository(execution.result);
@@ -102,7 +102,7 @@ export function createLocalResultWriter(
const syncResult = async (
execution: BuildExecutionSnapshot,
- state: import("@hypit/protocol").BuildState,
+ state: import("@hypit/hypit/protocol").BuildState,
): Promise<void> => {
const result = await openWriter(execution);
try {
diff --git a/packages/runtime-local/src/runtime.ts b/packages/runtime-local/src/runtime.ts
index 3a71de4d..b680cfc6 100644
--- a/packages/runtime-local/src/runtime.ts
+++ b/packages/runtime-local/src/runtime.ts
@@ -2,20 +2,20 @@ import { createActionExecutor } from "./actions.js";
import { isAbsolute, relative, resolve, sep } from "node:path";
import {
+ producerPackagesFromFacets,
registerProducerFacets,
- registerTypeValidatorFacets,
-} from "@hypit/component-kit";
+} from "@hypit/hypit/producer";
import {
ProducerRegistry,
- NodeDriver,
+ Executor,
EndpointRegistry,
-} from "@hypit/driver-node";
+} from "@hypit/hypit/executor";
import {
isStreamingResourceStore,
-} from "@hypit/runtime";
-import { assertOrderedBuildId } from "@hypit/protocol";
-import type { BlobRef, BuildDefinition } from "@hypit/protocol";
-import { TypeValidatorRegistry } from "@hypit/validation";
+} from "@hypit/hypit/runtime";
+import { assertOrderedBuildId } from "@hypit/hypit/protocol";
+import type { BlobRef, BuildDefinition } from "@hypit/hypit/protocol";
+import { admissionPackagesFromFacets, registerTypeValidatorFacets, TypeValidatorRegistry } from "@hypit/hypit/admission";
import { createLocalRuntimeControl } from "./control.js";
import { createLocalCredentialControl } from "./credentials.js";
@@ -115,34 +115,31 @@ export async function createLocalRuntime(
const producers = new ProducerRegistry();
const endpoints = new EndpointRegistry();
const validators = new TypeValidatorRegistry();
- for (const component of options.components ?? []) {
- registerTypeValidatorFacets(validators, component.validators ?? []);
- registerProducerFacets(producers, component.producers ?? []);
- }
+ for (const pack of options.producerPackages ?? []) registerProducerFacets(producers, pack.producers ?? []);
+ for (const pack of options.admissionPackages ?? []) registerTypeValidatorFacets(validators, pack.validators ?? []);
for (const endpoint of options.endpoints ?? []) await endpoint.install(endpoints);
applyEndpointBindings(endpoints, options.bindings);
- const loadedComponentPackages = new Set<string>();
+ const loadedProducerPackages = new Set<string>();
let componentInstallation = Promise.resolve();
- const installComponentPackages = async (specifiers: readonly string[]): Promise<void> => {
+ const installProducerPackages = async (specifiers: readonly string[]): Promise<void> => {
const task = componentInstallation.then(async () => {
- const missing = [...new Set(specifiers)].filter((item) => !loadedComponentPackages.has(item));
+ const missing = [...new Set(specifiers)].filter((item) => !loadedProducerPackages.has(item));
if (missing.length === 0) return;
- assert(options.loadComponentPackages !== undefined,
- `Build requires component package ${missing[0]} but this Runtime cannot load installed packages`);
- const loaded = await options.loadComponentPackages(missing);
- const fresh = loaded.filter((item) => !loadedComponentPackages.has(item.specifier));
+ assert(options.loadProducerPackages !== undefined,
+ `Build requires execution package ${missing[0]} but this Runtime cannot load installed packages`);
+ const loaded = await options.loadProducerPackages(missing);
+ const fresh = loaded.filter((item) => !loadedProducerPackages.has(item.specifier));
for (const item of fresh) {
- for (const component of item.components) {
- registerTypeValidatorFacets(validators, component.validators ?? []);
- registerProducerFacets(producers, component.producers ?? []);
- }
+ const facets = item.contribution.facets ?? [];
+ for (const pack of producerPackagesFromFacets(facets)) registerProducerFacets(producers, pack.producers ?? []);
+ for (const pack of admissionPackagesFromFacets(facets)) registerTypeValidatorFacets(validators, pack.validators ?? []);
}
- for (const item of fresh) loadedComponentPackages.add(item.specifier);
+ for (const item of fresh) loadedProducerPackages.add(item.specifier);
});
componentInstallation = task.then(() => undefined, () => undefined);
await task;
};
- const driver = new NodeDriver({
+ const driver = new Executor({
producers,
endpoints,
resources: options.resourceStore,
@@ -177,7 +174,7 @@ export async function createLocalRuntime(
resourceStore: options.resourceStore,
...(options.resourceStoreForBuild === undefined ? {} : { resourceStoreForBuild: options.resourceStoreForBuild }),
openBuildResultRepository,
- installComponentPackages,
+ installProducerPackages,
resultWriter,
});
const credentialControl = createLocalCredentialControl({
@@ -261,7 +258,7 @@ export async function createLocalRuntime(
const executionRequest = {
build: request.id,
...(options.executionContext === undefined ? {} : { context: options.executionContext }),
- componentPackages: [...new Set(request.componentPackages ?? [])].sort(),
+ executionPackages: [...new Set(request.executionPackages ?? [])].sort(),
result: resultRequest.repository,
} as const;
let prepared = false;
@@ -293,9 +290,9 @@ export async function createLocalRuntime(
await opened.repository.create({
id: request.id,
...(resultRequest.title === undefined ? {} : { title: resultRequest.title }),
- source: { path: projectPath(resultRequest.repository.root, request.catalog.source.path) },
+ source: { id: projectPath(resultRequest.repository.root, request.catalog.source.path) },
...(request.catalog.run === undefined ? {} : {
- run: { path: projectPath(resultRequest.repository.root, request.catalog.run.path) },
+ run: { id: projectPath(resultRequest.repository.root, request.catalog.run.path) },
}),
targets,
publishedOutputs,
diff --git a/packages/store-sqlite/src/store.ts b/packages/runtime-local/src/sqlite-state.ts
similarity index 96%
rename from packages/store-sqlite/src/store.ts
rename to packages/runtime-local/src/sqlite-state.ts
index 7e18e277..41277580 100644
--- a/packages/store-sqlite/src/store.ts
+++ b/packages/runtime-local/src/sqlite-state.ts
@@ -2,25 +2,15 @@ import { existsSync, mkdirSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { DatabaseSync } from "node:sqlite";
-import { materializeBuild } from "@hypit/core";
+import { materializeBuild } from "@hypit/hypit/kernel";
import type {
BuildDefinition,
BuildFact,
CommandResult,
-} from "@hypit/protocol";
-import { assertBuildId } from "@hypit/protocol";
-import { capacityUnits } from "@hypit/runtime";
+} from "@hypit/hypit/protocol";
+import { assertBuildId } from "@hypit/hypit/protocol";
+import { capacityUnits } from "@hypit/hypit/runtime";
import type {
- PendingBuildCommit,
- PendingBuildSubmission,
- PendingBuildStore,
- BuildExecutionRequest,
- BuildExecutionSnapshot,
- BuildExecutionStop,
- BuildExecutionStore,
- BuildCatalog,
- BuildCatalogDescriptor,
- BuildCatalogEntry,
BuildSnapshot,
BuildStore,
CapacityAcquire,
@@ -35,7 +25,15 @@ import type {
OperationSnapshot,
OperationStore,
OperationUpdate,
-} from "@hypit/runtime";
+} from "@hypit/hypit/runtime";
+import type { BuildCatalog, BuildCatalogDescriptor, BuildCatalogEntry } from "./catalog.js";
+import type { PendingBuildCommit, PendingBuildSubmission, PendingBuildStore } from "./submission.js";
+import type {
+ BuildExecutionRequest,
+ BuildExecutionSnapshot,
+ BuildExecutionStop,
+ BuildExecutionStore,
+} from "./execution.js";
export type SqliteRuntimeStateOptions = {
readonly busyTimeoutMs?: number;
@@ -213,18 +211,19 @@ class SqliteBuildCatalog implements BuildCatalog {
function parseExecutionRequest(row: Row, subject: string): BuildExecutionRequest {
assert(typeof row.build_id === "string", `SQLite ${subject} row has no Build id`);
- assert(typeof row.component_packages_json === "string", `SQLite ${subject} row has no component packages`);
+ assert(typeof row.execution_packages_json === "string", `SQLite ${subject} row has no execution packages`);
assert(typeof row.result_location_json === "string", `SQLite ${subject} row has no Result location`);
- const componentPackages = JSON.parse(row.component_packages_json) as unknown;
- assert(Array.isArray(componentPackages) && componentPackages.every((item) => typeof item === "string"),
- `SQLite ${subject} component packages are invalid`);
+ const executionPackages = JSON.parse(row.execution_packages_json) as unknown;
+ assert(Array.isArray(executionPackages) && executionPackages.every((item) => typeof item === "string"),
+ `SQLite ${subject} execution packages are invalid`);
const result = JSON.parse(row.result_location_json) as Partial<BuildExecutionRequest["result"]>;
- assert(typeof result.root === "string" && typeof result.selection?.use === "string",
+ assert(typeof result.root === "string" && result.root.length > 0
+ && typeof result.path === "string" && result.path.length > 0,
`SQLite ${subject} Result location is invalid`);
return {
build: row.build_id,
...(typeof row.context_json === "string" ? { context: JSON.parse(row.context_json) as NonNullable<BuildExecutionRequest["context"]> } : {}),
- componentPackages,
+ executionPackages,
result: result as BuildExecutionRequest["result"],
};
}
@@ -263,11 +262,11 @@ class SqlitePendingBuildStore implements PendingBuildStore {
assert(occupied === undefined, `Build ${request.build} already has Runtime state`);
this.#database.prepare(`
INSERT INTO hypit_submissions (
- build_id, component_packages_json, result_location_json, context_json, created_at
+ build_id, execution_packages_json, result_location_json, context_json, created_at
) VALUES (?, ?, ?, ?, ?)
`).run(
request.build,
- JSON.stringify(request.componentPackages),
+ JSON.stringify(request.executionPackages),
JSON.stringify(request.result),
request.context === undefined ? null : JSON.stringify(request.context),
now,
@@ -295,7 +294,7 @@ class SqlitePendingBuildStore implements PendingBuildStore {
const row = this.#database.prepare("SELECT * FROM hypit_submissions WHERE build_id = ?").get(request.build) as Row | undefined;
if (row === undefined) throw new Error(`Build submission ${request.build} was not prepared`);
const submission = parsePendingBuildSubmission(row);
- assert(JSON.stringify(submission.componentPackages) === JSON.stringify(request.componentPackages)
+ assert(JSON.stringify(submission.executionPackages) === JSON.stringify(request.executionPackages)
&& JSON.stringify(submission.result) === JSON.stringify(request.result)
&& JSON.stringify(submission.context) === JSON.stringify(request.context),
`Build submission ${request.build} does not match its prepared state`);
@@ -307,14 +306,14 @@ class SqlitePendingBuildStore implements PendingBuildStore {
`).run(request.build, Date.now(), JSON.stringify(request.catalog));
this.#database.prepare(`
INSERT INTO hypit_executions (
- build_id, component_packages_json, result_location_json, context_json, created_at, wake_at,
+ build_id, execution_packages_json, result_location_json, context_json, created_at, wake_at,
turn_owner, turn_acquired_at, result_writer_owner, result_writer_acquired_at,
stop_cause, stop_reason,
decision_outcome, decision_reason, attention_step, attention_error
) VALUES (?, ?, ?, ?, ?, ?, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
`).run(
request.build,
- JSON.stringify(request.componentPackages),
+ JSON.stringify(request.executionPackages),
JSON.stringify(request.result),
request.context === undefined ? null : JSON.stringify(request.context),
submission.createdAt,
@@ -553,12 +552,12 @@ class SqliteBuildExecutionStore implements BuildExecutionStore {
nonNegativeInteger(now, "Execution creation time");
this.#database.prepare(`
INSERT INTO hypit_executions (
- build_id, component_packages_json, result_location_json, context_json, created_at, wake_at,
+ build_id, execution_packages_json, result_location_json, context_json, created_at, wake_at,
turn_owner, turn_acquired_at, result_writer_owner, result_writer_acquired_at,
stop_cause, stop_reason,
decision_outcome, decision_reason, attention_step, attention_error
) VALUES (?, ?, ?, ?, ?, ?, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
- `).run(request.build, JSON.stringify(request.componentPackages), JSON.stringify(request.result), request.context === undefined ? null : JSON.stringify(request.context), now, now);
+ `).run(request.build, JSON.stringify(request.executionPackages), JSON.stringify(request.result), request.context === undefined ? null : JSON.stringify(request.context), now, now);
return {
...copy(request),
createdAt: now,
@@ -1005,14 +1004,14 @@ export class SqliteRuntimeState {
) STRICT;
CREATE TABLE IF NOT EXISTS hypit_submissions (
build_id TEXT PRIMARY KEY,
- component_packages_json TEXT NOT NULL,
+ execution_packages_json TEXT NOT NULL,
result_location_json TEXT NOT NULL,
context_json TEXT,
created_at INTEGER NOT NULL
) STRICT;
CREATE TABLE IF NOT EXISTS hypit_executions (
build_id TEXT PRIMARY KEY,
- component_packages_json TEXT NOT NULL,
+ execution_packages_json TEXT NOT NULL,
result_location_json TEXT NOT NULL,
context_json TEXT,
created_at INTEGER NOT NULL,
@@ -1078,7 +1077,7 @@ export class SqliteRuntimeState {
}
/** Remove the complete active Runtime aggregate in one transaction, deleting its root last. */
- async removeActiveBuild(build: string): Promise<import("@hypit/runtime").BuildCompletion> {
+ async removeActiveBuild(build: string): Promise<import("./execution.js").BuildCompletion> {
return transaction(this.#database, () => {
const row = this.#database.prepare("SELECT * FROM hypit_executions WHERE build_id = ?").get(build) as Row | undefined;
if (row === undefined) throw new Error(`Execution ${build} does not exist`);
diff --git a/packages/runtime-local/src/submission.ts b/packages/runtime-local/src/submission.ts
new file mode 100644
index 00000000..4553fd8b
--- /dev/null
+++ b/packages/runtime-local/src/submission.ts
@@ -0,0 +1,24 @@
+import type { BuildDefinition } from "@hypit/hypit/protocol";
+import type { BuildCatalogDescriptor } from "./catalog.js";
+import type { BuildExecutionRequest, BuildExecutionSnapshot } from "./execution.js";
+
+export type PendingBuildSubmission = BuildExecutionRequest & {
+ readonly createdAt: number;
+};
+
+export type PendingBuildCommit = BuildExecutionRequest & {
+ readonly definition: BuildDefinition;
+ readonly catalog: BuildCatalogDescriptor;
+};
+
+/**
+ * One exact cross-store submission transaction. A pending submission is not schedulable and can
+ * only become active execution or be explicitly discarded with its Result draft and temporary resources.
+ */
+export type PendingBuildStore = {
+ prepare(request: BuildExecutionRequest, options?: { readonly now?: number }): Promise<PendingBuildSubmission>;
+ read(build: string): Promise<PendingBuildSubmission | undefined>;
+ list(): Promise<readonly PendingBuildSubmission[]>;
+ commit(request: PendingBuildCommit): Promise<BuildExecutionSnapshot>;
+ discard(build: string): Promise<void>;
+};
diff --git a/packages/runtime-local/src/supervisor.ts b/packages/runtime-local/src/supervisor.ts
index 63ca9038..f924083c 100644
--- a/packages/runtime-local/src/supervisor.ts
+++ b/packages/runtime-local/src/supervisor.ts
@@ -1,7 +1,7 @@
import { spawn, type ChildProcess } from "node:child_process";
import { setTimeout as pause } from "node:timers/promises";
-import { SqliteRuntimeState } from "@hypit/store-sqlite";
-import type { RuntimeWorkerLaunch } from "./worker-process.js";
+import { SqliteRuntimeState } from "./sqlite-state.js";
+import type { RuntimeWorkerLaunch } from "./host-api.js";
import { createRuntimeResultWriter, localExecutionContext, readRuntimeWorkerOptions, statePath } from "./config.js";
type Carrier = { readonly child: ChildProcess; readonly builds: Set<string>; readonly ready: Promise<void>;
@@ -47,6 +47,7 @@ export async function superviseBuilds(options: {
...options.launch.args, "_worker", options.profile,
"--ready-file", options.readyFile, "--worker-owner", options.owner,
"--execution-root", options.dataRoot,
+ ...(options.launch.workerArgs ?? []),
], {
stdio: ["ignore", "inherit", "inherit", "ipc"], windowsHide: true,
// Node's CommonJS evaluation callback needs this for scoped dynamic import().
diff --git a/packages/runtime-local/src/types.ts b/packages/runtime-local/src/types.ts
index afb2aa68..10c50fd5 100644
--- a/packages/runtime-local/src/types.ts
+++ b/packages/runtime-local/src/types.ts
@@ -1,40 +1,44 @@
-import type { Awaitable, ComponentPackage } from "@hypit/component-kit";
-import type { EndpointPackage } from "@hypit/endpoint-kit";
-import type { LoadedComponentPackage } from "@hypit/package-loader-node";
-import type { BuildResultRepositoryLocation, BuildResultRepositoryOpened } from "@hypit/build-result-kit";
+import type { AdmissionPackage } from "@hypit/hypit/admission";
+import type { Awaitable, ProducerPackage } from "@hypit/hypit/producer";
+import type { EndpointInstance } from "@hypit/hypit/endpoint";
+import type { LoadedPackage } from "@hypit/hypit/loader";
+import type { BuildResultRepository } from "@hypit/hypit/result";
import type {
ResourceStore,
- BuildCompletion,
- BuildCatalog,
BuildStore,
- BuildExecutionStore,
- BuildExecutionSnapshot,
CredentialStore,
OperationStore,
-} from "@hypit/runtime";
+} from "@hypit/hypit/runtime";
+import type { BuildCatalog } from "./catalog.js";
+import type { BuildCompletion, BuildExecutionStore, BuildExecutionSnapshot, BuildResultRepositoryLocation } from "./execution.js";
import type {
RuntimeHostControl,
RuntimeHostBuildSubmission,
RuntimeHostCredentialControl,
RuntimeHostExecution,
RuntimeHostResultControl,
-} from "@hypit/runtime-host-node";
+} from "./host-api.js";
+
+type BuildResultRepositoryOpened = {
+ readonly repository: BuildResultRepository;
+ readonly close?: () => void | Promise<void>;
+};
export type CreateLocalRuntimeOptions = {
/** Already assigned by the local coordinator. Embeddings omit this and start fresh work. */
readonly executionBuild?: string;
- readonly executionContext?: import("@hypit/protocol").CanonicalValue;
+ readonly executionContext?: import("@hypit/hypit/protocol").CanonicalValue;
readonly executionLogs?: import("./log.js").LocalExecutionLogs;
readonly buildStore: BuildStore;
/** Host presentation metadata only; never part of Core state. */
readonly buildCatalog: BuildCatalog;
readonly operationStore: OperationStore;
/** Durable receipt boundary: one immediate Command is never invoked twice for one Build. */
- readonly commandExecutionStore: import("@hypit/runtime").CommandExecutionStore;
- readonly executionStore: import("@hypit/runtime").BuildExecutionStore;
+ readonly commandExecutionStore: import("@hypit/hypit/runtime").CommandExecutionStore;
+ readonly executionStore: BuildExecutionStore;
readonly removeActiveBuild: (build: string) => Awaitable<BuildCompletion>;
/** Atomic submission boundary: external preparation is never a claimable partial Build. */
- readonly submissionStore: import("@hypit/runtime").PendingBuildStore;
+ readonly submissionStore: import("./submission.js").PendingBuildStore;
readonly resourceStore: ResourceStore;
/** Optional Build-local transient byte area used by Provider execution and Result writing. */
readonly resourceStoreForBuild?: (build: string) => ResourceStore;
@@ -42,10 +46,13 @@ export type CreateLocalRuntimeOptions = {
readonly clearBuildResources?: (build: string) => Awaitable<void>;
readonly openBuildResultRepository: (location: BuildResultRepositoryLocation) => Awaitable<BuildResultRepositoryOpened>;
readonly credentialStore: CredentialStore;
- readonly components?: readonly ComponentPackage[];
+ /** Deterministic implementations injected directly by an embedding. Installed packages arrive as facets. */
+ readonly producerPackages?: readonly ProducerPackage[];
+ /** Type-owner admission rules injected directly by an embedding. */
+ readonly admissionPackages?: readonly AdmissionPackage[];
/** Load the complete physical package closure named by a claimed Build. */
- readonly loadComponentPackages?: (specifiers: readonly string[]) => Awaitable<readonly LoadedComponentPackage[]>;
- readonly endpoints?: readonly EndpointPackage[];
+ readonly loadProducerPackages?: (specifiers: readonly string[]) => Awaitable<readonly LoadedPackage[]>;
+ readonly endpoints?: readonly EndpointInstance[];
/** Which Endpoint instance serves each capability that several selected Endpoints offer. */
readonly bindings?: Readonly<Record<string, string>>;
readonly close?: () => Awaitable<void>;
@@ -54,11 +61,11 @@ export type CreateLocalRuntimeOptions = {
export type CreateLocalRuntimeControlOptions = {
readonly executionLogs?: import("./log.js").LocalExecutionLogs;
readonly buildStore: BuildStore;
- readonly commandExecutionStore: import("@hypit/runtime").CommandExecutionStore;
+ readonly commandExecutionStore: import("@hypit/hypit/runtime").CommandExecutionStore;
readonly buildCatalog?: BuildCatalog;
readonly operationStore: OperationStore;
readonly executionStore: BuildExecutionStore;
- readonly submissionStore: import("@hypit/runtime").PendingBuildStore;
+ readonly submissionStore: import("./submission.js").PendingBuildStore;
/** Optional owner supplied by the Runtime assembly. */
readonly close?: () => Awaitable<void>;
};
@@ -67,10 +74,10 @@ export type CreateLocalResultWriterOptions = {
readonly executionLogs?: import("./log.js").LocalExecutionLogs;
readonly buildStore: BuildStore;
readonly operationStore: OperationStore;
- readonly commandExecutionStore: import("@hypit/runtime").CommandExecutionStore;
+ readonly commandExecutionStore: import("@hypit/hypit/runtime").CommandExecutionStore;
readonly executionStore: BuildExecutionStore;
readonly removeActiveBuild: (build: string) => Awaitable<BuildCompletion>;
- readonly submissionStore: import("@hypit/runtime").PendingBuildStore;
+ readonly submissionStore: import("./submission.js").PendingBuildStore;
readonly resourceStore: ResourceStore;
readonly resourceStoreForBuild?: (build: string) => ResourceStore;
readonly clearBuildResources?: (build: string) => Awaitable<void>;
@@ -80,7 +87,7 @@ export type CreateLocalResultWriterOptions = {
export type CreateLocalCredentialControlOptions = {
readonly credentialStore: CredentialStore;
- readonly endpoints: readonly EndpointPackage[];
+ readonly endpoints: readonly EndpointInstance[];
readonly close?: () => Awaitable<void>;
};
@@ -98,7 +105,7 @@ export type LocalRuntimeControl = RuntimeHostControl;
export type LocalResultWriter = RuntimeHostResultControl & {
/** Incrementally accept public Outputs already completed during execution. */
- sync(execution: BuildExecutionSnapshot, state: import("@hypit/protocol").BuildState): Promise<void>;
+ sync(execution: BuildExecutionSnapshot, state: import("@hypit/hypit/protocol").BuildState): Promise<void>;
/** Persist the outcome just frozen by the execution Worker, then remove active Runtime state. */
completeResult(execution: BuildExecutionSnapshot): Promise<BuildExecutionSnapshot | BuildCompletion>;
};
diff --git a/packages/runtime-local/src/worker-process.ts b/packages/runtime-local/src/worker-process.ts
index 5f13d1c4..32293290 100644
--- a/packages/runtime-local/src/worker-process.ts
+++ b/packages/runtime-local/src/worker-process.ts
@@ -7,12 +7,7 @@ import { dirname, join, resolve } from "node:path";
import { processAlive, stopProcessTree } from "./process-control.js";
import { readProcessLogs } from "./process-logs.js";
import { startWithOwnConsole } from "./programs.js";
-
-export type RuntimeWorkerLaunch = {
- readonly command: string;
- readonly args: readonly string[];
- readonly workerArgs?: readonly string[];
-};
+import type { RuntimeWorkerLaunch } from "./host-api.js";
export type RuntimeProcessState = {
readonly state: "running" | "stopped";
diff --git a/packages/runtime-local/src/worker.ts b/packages/runtime-local/src/worker.ts
index fa15e7c3..15a540c2 100644
--- a/packages/runtime-local/src/worker.ts
+++ b/packages/runtime-local/src/worker.ts
@@ -1,32 +1,31 @@
import { randomUUID } from "node:crypto";
-import type { BuildState } from "@hypit/protocol";
+import type { BuildState } from "@hypit/hypit/protocol";
import type {
ResourceStore,
- BuildCompletion,
- BuildExecutionSnapshot,
RuntimeBuildExecution,
RuntimeCommandExecutor,
RuntimeExecutionResult,
RuntimePreparation,
RuntimeRunnableCommand,
ScheduledBuildResult,
-} from "@hypit/runtime";
-import { LocalBuildScheduler } from "@hypit/runtime";
-import { BuildMachine } from "@hypit/core";
+} from "@hypit/hypit/runtime";
+import type { BuildCompletion, BuildExecutionSnapshot } from "./execution.js";
+import { InProcessBuildScheduler } from "@hypit/hypit/runtime";
+import { BuildMachine } from "@hypit/hypit/kernel";
type LocalWorkerOptions = {
readonly executionBuild?: string;
readonly executionLogs?: import("./log.js").LocalExecutionLogs;
readonly stores: {
- readonly builds: import("@hypit/runtime").BuildStore;
- readonly operations: import("@hypit/runtime").OperationStore;
- readonly executions: import("@hypit/runtime").CommandExecutionStore;
- readonly execution: import("@hypit/runtime").BuildExecutionStore;
+ readonly builds: import("@hypit/hypit/runtime").BuildStore;
+ readonly operations: import("@hypit/hypit/runtime").OperationStore;
+ readonly executions: import("@hypit/hypit/runtime").CommandExecutionStore;
+ readonly execution: import("./execution.js").BuildExecutionStore;
};
readonly resourceStore: ResourceStore;
readonly resourceStoreForBuild?: (build: string) => ResourceStore;
readonly openBuildResultRepository: NonNullable<import("./types.js").CreateLocalRuntimeOptions["openBuildResultRepository"]>;
- readonly installComponentPackages: (specifiers: readonly string[]) => Promise<void>;
+ readonly installProducerPackages: (specifiers: readonly string[]) => Promise<void>;
readonly resultWriter: import("./types.js").LocalResultWriter;
};
@@ -71,10 +70,10 @@ class CapacityExecutor implements RuntimeCommandExecutor {
): Promise<RuntimeExecutionResult> {
const store = this.#options.stores.executions;
const recordExecution = this.#options.executionLogs === undefined ? {} : {
- recordExecution: (event: import("@hypit/runtime").ExecutionLogEvent) =>
+ recordExecution: (event: import("@hypit/hypit/runtime").ExecutionLogEvent) =>
this.#options.executionLogs!.record(context.build, descriptor.command.id, event),
};
- const execute = (executionContext: import("@hypit/runtime").RuntimeExecutionContext) =>
+ const execute = (executionContext: import("@hypit/hypit/runtime").RuntimeExecutionContext) =>
execution !== undefined && this.#delegate.executeExecutionCommand !== undefined
? this.#delegate.executeExecutionCommand(execution, descriptor, executionContext)
: this.#delegate.executeCommand(state, descriptor, executionContext);
@@ -189,7 +188,7 @@ class CapacityExecutor implements RuntimeCommandExecutor {
async cancelOperation(
state: BuildState,
- operation: import("@hypit/runtime").OperationSnapshot,
+ operation: import("@hypit/hypit/runtime").OperationSnapshot,
) {
assert(this.#delegate.cancelOperation !== undefined, "selected executor cannot cancel Operations");
return await this.#delegate.cancelOperation(state, operation);
@@ -211,7 +210,7 @@ class DurableLocalWorker {
this.#executorWithCapacity = new CapacityExecutor(executor, options, this.#owner);
}
- async #readBuild(build: string): Promise<import("@hypit/runtime").BuildSnapshot | undefined> {
+ async #readBuild(build: string): Promise<import("@hypit/hypit/runtime").BuildSnapshot | undefined> {
const previous = this.#buildRead;
let release!: () => void;
this.#buildRead = new Promise<void>((resolve) => { release = resolve; });
@@ -227,7 +226,7 @@ class DurableLocalWorker {
}
}
- async #finishResult(execution: BuildExecutionSnapshot, outcome: import("@hypit/runtime").BuildOutcome, reason?: string): Promise<WorkerTurnResult> {
+ async #finishResult(execution: BuildExecutionSnapshot, outcome: import("./execution.js").BuildOutcome, reason?: string): Promise<WorkerTurnResult> {
await this.#options.stores.execution.releaseBuildCapacity(execution.build);
const decided = await this.#options.stores.execution.decide(execution.build, this.#owner, outcome, reason);
return await this.#options.resultWriter.completeResult(decided);
@@ -242,7 +241,7 @@ class DurableLocalWorker {
assert(snapshot !== undefined, `Build ${execution.build} has no execution state`);
const machine = BuildMachine.fromMaterialized(snapshot.definition, snapshot.state);
for (const operation of received) {
- let event: import("@hypit/protocol").CommandResult | undefined;
+ let event: import("@hypit/hypit/protocol").CommandResult | undefined;
try {
event = await this.#executor.acceptOperation?.(machine.view(), operation);
} catch (error) {
@@ -327,7 +326,7 @@ class DurableLocalWorker {
hydrated?: () => void,
): Promise<readonly WorkerTurnResult[]> {
const finished: WorkerTurnResult[] = [];
- const runnable: { readonly execution: BuildExecutionSnapshot; readonly snapshot: import("@hypit/runtime").BuildSnapshot }[] = [];
+ const runnable: { readonly execution: BuildExecutionSnapshot; readonly snapshot: import("@hypit/hypit/runtime").BuildSnapshot }[] = [];
for (const execution of executions) {
assert(execution.turn?.owner === this.#owner && execution.decision === undefined,
`Execution ${execution.build} was not claimed by this Worker turn`);
@@ -345,7 +344,7 @@ class DurableLocalWorker {
const result = await this.#executor.advanceOperation!(operation, {
build: operation.build,
...(this.#options.executionLogs === undefined ? {} : {
- recordExecution: (event: import("@hypit/runtime").ExecutionLogEvent) =>
+ recordExecution: (event: import("@hypit/hypit/runtime").ExecutionLogEvent) =>
this.#options.executionLogs!.record(operation.build, operation.command, event),
}),
});
@@ -370,7 +369,7 @@ class DurableLocalWorker {
continue;
}
}
- await this.#options.installComponentPackages(execution.componentPackages);
+ await this.#options.installProducerPackages(execution.executionPackages);
const snapshot = await this.#readBuild(execution.build);
assert(snapshot !== undefined, `Execution ${execution.build} has no Build Definition`);
runnable.push({ execution, snapshot });
@@ -381,7 +380,7 @@ class DurableLocalWorker {
}
}
if (runnable.length === 0) return finished;
- const scheduler = new LocalBuildScheduler(this.#executorWithCapacity, {
+ const scheduler = new InProcessBuildScheduler(this.#executorWithCapacity, {
buildStore: this.#options.stores.builds,
onStateChange: async (build, state) => {
const item = runnable.find((candidate) => candidate.execution.build === build);
diff --git a/packages/runtime-local/test/concurrency-process.test.ts b/packages/runtime-local/test/concurrency-process.test.ts
index 9b39a6f8..976ccfac 100644
--- a/packages/runtime-local/test/concurrency-process.test.ts
+++ b/packages/runtime-local/test/concurrency-process.test.ts
@@ -6,10 +6,10 @@ import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { setTimeout as pause } from "node:timers/promises";
import test from "node:test";
-import { defineBuild } from "@hypit/core";
-import { FileBuildResultRepository } from "@hypit/build-result";
-import { SqliteRuntimeState } from "@hypit/store-sqlite";
-import { createGreetingBuild, manifest, capabilities, producers, types } from "../../core/test/greeting-fixture.js";
+import { defineBuild } from "@hypit/kernel";
+import { FileBuildResultRepository } from "@hypit/result/node";
+import { SqliteRuntimeState } from "../src/sqlite-state.js";
+import { createGreetingBuild, manifest, capabilities, producers, types } from "../../kernel/test/greeting-fixture.js";
import { statePath } from "../src/config.js";
import { superviseBuilds } from "../src/supervisor.js";
@@ -64,20 +64,20 @@ for (const scenario of scenarios) {
await mkdir(pkg, { recursive: true });
await writeFile(join(pkg, "package.json"), JSON.stringify({ name: "fixture-concurrency", version: "1.0.0", type: "module", hypit: { activation: "./activation.mjs" } }));
await writeFile(join(pkg, "activation.mjs"), `
- import {createRuntimeEndpointAdapterFacet} from '@hypit/runtime-kit';
- import {defineEndpointPackage} from '@hypit/endpoint-kit';
+ import {createRuntimeEndpointAdapterFacet} from '@hypit/runtime-local/extension';
+ import {defineEndpoint} from '@hypit/endpoint';
const server=${JSON.stringify(endpoint)};
async function call(path,name){const response=await fetch(server+path,{method:'POST',body:JSON.stringify({name,pid:process.pid,rss:process.memoryUsage().rss})});return response.json();}
let localCount=0;
- export default {format:'hypit.node-package@1',modules:[{manifest:${JSON.stringify(manifest)}}],components:[{producers:[
+ export default {format:'hypit.package@1',modules:[{manifest:${JSON.stringify(manifest)}}],facets:[{abi:'hypit.producer-package@1',implementation:{producers:[
{producer:${JSON.stringify(producers.makePrompt)},handler:async({inputs})=>{
if(++localCount!==1)throw Error('Component state leaked between Builds');
const name=inputs.intent.value.value.name;await call('/a',name);
return {outputs:{prompt:{kind:'inline',value:name}},needs:{}};
}},
{producer:${JSON.stringify(producers.requestText)},handler:({inputs})=>({outputs:{},needs:{generation:{prompt:inputs.prompt.value.value}}})}
- ]}],hostFacets:[createRuntimeEndpointAdapterFacet({use:'fixture-concurrency',activate(context){
- return {endpoint:defineEndpointPackage({module:{name:'fixture.provider',version:'1'},facet:'generation',instance:context.instance,pool:context.pool,
+ ]}},createRuntimeEndpointAdapterFacet({use:'fixture-concurrency',activate(context){
+ return {endpoint:defineEndpoint({instance:context.instance,pool:context.pool,
defaultConcurrency:${scenario.capacity},actionLimits:{submit:{concurrency:${scenario.capacity}}},capabilities:[{lifecycle:'asynchronous',capability:${JSON.stringify(capabilities.generation)},returns:${JSON.stringify(types.generated)},endpoint:{
async start({need,operation}){const name=need.constraints.prompt;await call('/submit',name);return {status:'pending',handle:{name},receipt:{id:operation},wakeAt:Date.now()+250};},
async poll({handle}){const result=await call('/poll',handle.name);return result.complete?{status:'completed',result:{value:{kind:'inline',value:handle.name}}}:{status:'pending',handle,wakeAt:Date.now()+1000};}
@@ -94,12 +94,12 @@ for (const scenario of scenarios) {
for (let index = 0; index < scenario.count; index++) {
const id = `bld_20260914T120000000Z_${String(index).padStart(10,"0")}`;
ids.push(id);
- const request = { build: id, componentPackages: ["fixture-concurrency"],
- result: { root, selection: { use: "@hypit/build-result-fs", config: { path: "results" } } },
+ const request = { build: id, executionPackages: ["fixture-concurrency"],
+ result: { root, path: "results" },
context: { format: "hypit.local-execution@1", packageRoot: root, hostStateRoot: join(root,"host"), distributionPackageRoot: distribution, profile: profileValue },
};
await state.submissions.prepare(request);
- await repository.create({ id, source: { path: "main.svml" }, targets: ["generated"], publishedOutputs: [{name:"generated",output:"generated"}] });
+ await repository.create({ id, source: { id: "main.svml" }, targets: ["generated"], publishedOutputs: [{name:"generated",output:"generated"}] });
await state.submissions.commit({ ...request,
definition: { ...base, program: { ...base.program, records: base.program.records.map((record) => record.id === "intent:root"
? { ...record, value: { kind: "inline", value: { name: String(index) } } } : record) } },
diff --git a/packages/runtime-local/test/config.test.ts b/packages/runtime-local/test/config.test.ts
index 485120bb..776bb69b 100644
--- a/packages/runtime-local/test/config.test.ts
+++ b/packages/runtime-local/test/config.test.ts
@@ -8,25 +8,21 @@ import {
createRuntimeCredentialStoreAdapterFacet,
createRuntimeEndpointAdapterFacet,
RuntimeAdapterRegistry,
-} from "@hypit/runtime-kit";
-import {
- BuildResultRepositoryRegistry,
- createBuildResultRepositoryHostFacet,
-} from "@hypit/build-result-kit";
-import { FileBuildResultRepository } from "@hypit/build-result";
-import { MemoryResourceStore, ProducerRegistry } from "@hypit/driver-node";
-import { defineEndpointPackage } from "@hypit/endpoint-kit";
+} from "@hypit/runtime-local/extension";
+import { FileBuildResultRepository } from "@hypit/result/node";
+import { MemoryResourceStore, ProducerRegistry } from "@hypit/executor";
+import { defineEndpoint } from "@hypit/endpoint";
import { credentialRef } from "@hypit/runtime";
import type { CanonicalValue, CapabilityRef, TypeRef } from "@hypit/protocol";
-import type { RuntimeHostProviderQuery } from "@hypit/runtime-host-node";
-import { SqliteRuntimeState } from "@hypit/store-sqlite";
-import { TypeValidatorRegistry } from "@hypit/validation";
+import type { RuntimeHostProviderQuery } from "@hypit/runtime-local";
+import { SqliteRuntimeState } from "../src/sqlite-state.js";
+import { TypeValidatorRegistry } from "@hypit/admission";
import {
capabilities as greetingCapabilities,
createGreetingBuild,
producers as greetingProducerRefs,
types as greetingTypes,
-} from "../../core/test/greeting-fixture.js";
+} from "../../kernel/test/greeting-fixture.js";
import {
createRuntimeControlFromConfig,
createRuntimeFromConfig,
@@ -116,76 +112,17 @@ test("execution memory policy belongs to the local Worker, with an explicit MiB
assert.throws(() => parseLocalRuntimeProfile({ ...profile(), worker: { executionMemoryMb: 768, maxBuilds: 8 } }), /maxBuilds/u);
});
-test("Build Result repositories default to the project path and can be selected explicitly", async () => {
+test("Build Results belong to the project filesystem without a second selection plane", async () => {
const root = await mkdtemp(join(tmpdir(), "hypit-runtime-results-"));
- const defaultProject = join(root, "default-project");
- const selectedProject = join(root, "selected-project");
- await Promise.all([
- mkdir(defaultProject, { recursive: true }),
- mkdir(selectedProject, { recursive: true }),
- ]);
- await writeFile(
- join(selectedProject, "hypit.results.json"),
- JSON.stringify({
- format: "hypit.build-results@1",
- use: "example.results",
- config: { name: "episode-12" },
- }),
- );
- const registry = new BuildResultRepositoryRegistry();
- let openedContext: unknown;
- let diagnosedContext: unknown;
- registry.registerFacet(
- createBuildResultRepositoryHostFacet({
- use: "example.results",
- validate(context) {
- assert.deepEqual(context.config, { name: "episode-12" });
- },
- open(context) {
- openedContext = context;
- return {
- repository: new FileBuildResultRepository(join(root, "remote-fixture")),
- };
- },
- doctor(context) {
- diagnosedContext = context;
- return [];
- },
- }),
- );
+ const project = join(root, "project");
+ await mkdir(project, { recursive: true });
try {
- const local = await openProjectBuildResultRepository(defaultProject, {
- packageRoot: process.cwd(),
- defaultSelection: { use: "@hypit/build-result-fs", config: { path: ".hypit/results" } },
- });
+ const local = await openProjectBuildResultRepository(project);
assert.ok(local.repository instanceof FileBuildResultRepository);
- assert.equal(local.location.root, defaultProject);
- assert.deepEqual(local.location.selection, {
- use: "@hypit/build-result-fs",
- config: { path: ".hypit/results" },
- });
-
- const selected = await openProjectBuildResultRepository(selectedProject, {
- resultRegistry: registry,
- defaultSelection: { use: "unused.default" },
- });
- assert.deepEqual(openedContext, {
- root: selectedProject,
- config: { name: "episode-12" },
- });
- assert.deepEqual(selected.location, {
- root: selectedProject,
- selection: { use: "example.results", config: { name: "episode-12" } },
- });
- const diagnosed = await doctorProjectBuildResultRepository(selectedProject, {
- resultRegistry: registry,
- defaultSelection: { use: "unused.default" },
- });
+ assert.deepEqual(local.location, { root: project, path: ".hypit/results" });
+ const diagnosed = await doctorProjectBuildResultRepository(project);
assert.deepEqual(diagnosed.diagnostics, []);
- assert.deepEqual(diagnosedContext, {
- root: selectedProject,
- config: { name: "episode-12" },
- });
+ assert.deepEqual(diagnosed.location, local.location);
} finally {
await rm(root, { recursive: true, force: true });
}
@@ -344,9 +281,7 @@ test("Runtime providers name the selected Endpoint and its declared price source
registry.registerFacet(createRuntimeEndpointAdapterFacet({
use: "example.paid",
activate: (context) => ({
- endpoint: defineEndpointPackage({
- module: { name: "example.provider", version: "1" },
- facet: "paid",
+ endpoint: defineEndpoint({
instance: context.instance,
pool: context.pool ?? context.instance,
pricing: { kind: "page", url: "https://prices.example/models" },
@@ -357,9 +292,7 @@ test("Runtime providers name the selected Endpoint and its declared price source
registry.registerFacet(createRuntimeEndpointAdapterFacet({
use: "example.local",
activate: (context) => ({
- endpoint: defineEndpointPackage({
- module: { name: "example.local-provider", version: "1" },
- facet: "local",
+ endpoint: defineEndpoint({
instance: context.instance,
pool: context.pool ?? context.instance,
pricing: { kind: "local" },
@@ -413,8 +346,7 @@ test("Runtime pricing reads Provider-owned material with only the selected Endpo
}));
registry.registerFacet(createRuntimeEndpointAdapterFacet({
use: "example.paid",
- activate: (context) => ({ endpoint: defineEndpointPackage({
- module: { name: "example.provider", version: "1" }, facet: "paid",
+ activate: (context) => ({ endpoint: defineEndpoint({
instance: context.instance, pool: context.pool ?? context.instance,
credentials: { apiKey: credentialRef("secrets", "paid.key") },
pricing: { kind: "page", url: "https://prices.example/models" },
@@ -429,8 +361,7 @@ test("Runtime pricing reads Provider-owned material with only the selected Endpo
}));
registry.registerFacet(createRuntimeEndpointAdapterFacet({
use: "example.local",
- activate: (context) => ({ endpoint: defineEndpointPackage({
- module: { name: "example.local", version: "1" }, facet: "local",
+ activate: (context) => ({ endpoint: defineEndpoint({
instance: context.instance, pool: context.pool ?? context.instance, pricing: { kind: "local" },
capabilities: [{ capability: render, returns, lifecycle: "immediate", handler }],
}) }),
@@ -484,9 +415,7 @@ test("transient execution follows capability opt-in rather than pricing and keep
registry.registerFacet(createRuntimeEndpointAdapterFacet({
use: "example.remote",
activate: (context) => ({
- endpoint: defineEndpointPackage({
- module: { name: "example.provider", version: "1" },
- facet: "remote",
+ endpoint: defineEndpoint({
instance: context.instance,
pool: context.pool ?? context.instance,
credentials: { apiKey: credentialRef("secrets", "remote.key") },
@@ -512,9 +441,7 @@ test("transient execution follows capability opt-in rather than pricing and keep
registry.registerFacet(createRuntimeEndpointAdapterFacet({
use: "example.local",
activate: (context) => ({
- endpoint: defineEndpointPackage({
- module: { name: "example.local-provider", version: "1" },
- facet: "local",
+ endpoint: defineEndpoint({
instance: context.instance,
pool: context.pool ?? context.instance,
pricing: { kind: "local" },
@@ -601,9 +528,7 @@ test("Runtime provider inspection applies Endpoint supports when the complete re
registry.registerFacet(createRuntimeEndpointAdapterFacet({
use: "example.narrow",
activate: (context) => ({
- endpoint: defineEndpointPackage({
- module: { name: "example.narrow-provider", version: "1" },
- facet: "narrow",
+ endpoint: defineEndpoint({
instance: context.instance,
pool: context.pool ?? context.instance,
pricing: { kind: "local" },
@@ -682,9 +607,7 @@ test("Runtime invoke executes one immediate Need through the selected Endpoint a
registry.registerFacet(createRuntimeEndpointAdapterFacet({
use: "example.paid",
activate: (context) => ({
- endpoint: defineEndpointPackage({
- module: { name: "example.provider", version: "1" },
- facet: "paid",
+ endpoint: defineEndpoint({
instance: context.instance,
pool: context.pool ?? context.instance,
credentials: { apiKey: credentialRef("secrets", "paid.key") },
@@ -704,9 +627,7 @@ test("Runtime invoke executes one immediate Need through the selected Endpoint a
registry.registerFacet(createRuntimeEndpointAdapterFacet({
use: "example.slow",
activate: (context) => ({
- endpoint: defineEndpointPackage({
- module: { name: "example.slow-provider", version: "1" },
- facet: "slow",
+ endpoint: defineEndpoint({
instance: context.instance,
pool: context.pool ?? context.instance,
capabilities: [{
@@ -774,9 +695,7 @@ test("providers, doctor and invoke share one resolver: a contested capability is
registry.registerFacet(createRuntimeEndpointAdapterFacet({
use,
activate: (context) => ({
- endpoint: defineEndpointPackage({
- module: { name: `example.provider.${instanceLabel}`, version: "1" },
- facet: instanceLabel,
+ endpoint: defineEndpoint({
instance: context.instance,
pool: context.pool ?? context.instance,
pricing: { kind: "local" },
@@ -847,9 +766,7 @@ test("doctor reports inconsistent limits for shared pools and capacity resources
registry.registerFacet(createRuntimeEndpointAdapterFacet({
use,
activate: (context) => ({
- endpoint: defineEndpointPackage({
- module: { name: `example.provider.${name}`, version: "1" },
- facet: name,
+ endpoint: defineEndpoint({
instance: context.instance,
pool: context.pool ?? context.instance,
pricing: { kind: "local" },
@@ -893,8 +810,7 @@ test("demanded readiness and Programs follow the chosen Endpoint, including befo
for (const name of ["local", "hosted"]) registry.registerFacet(createRuntimeEndpointAdapterFacet({
use: `example.${name}`,
activate: (context) => ({
- endpoint: defineEndpointPackage({
- module: { name: `example.${name}`, version: "1" }, facet: name,
+ endpoint: defineEndpoint({
instance: context.instance, pool: context.instance, pricing: { kind: "local" },
...(name === "hosted" ? { credentials: { key: credentialRef("keys", "account") } } : {}),
capabilities: [{ capability, returns, lifecycle: "immediate", handler: () => ({ value: { kind: "inline", value: "ok" } }) }],
diff --git a/packages/runtime-local/test/execution-process.test.ts b/packages/runtime-local/test/execution-process.test.ts
index f0bd20bb..77756ea8 100644
--- a/packages/runtime-local/test/execution-process.test.ts
+++ b/packages/runtime-local/test/execution-process.test.ts
@@ -5,11 +5,11 @@ import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { setTimeout as pause } from "node:timers/promises";
import test from "node:test";
-import { defineBuild } from "@hypit/core";
-import { FileBuildResultRepository } from "@hypit/build-result";
-import { installDistributionPackageResolution } from "@hypit/package-loader-node";
-import { SqliteRuntimeState } from "@hypit/store-sqlite";
-import { createGreetingBuild, manifest, capabilities, producers, types } from "../../core/test/greeting-fixture.js";
+import { defineBuild } from "@hypit/kernel";
+import { FileBuildResultRepository } from "@hypit/result/node";
+import { installDistributionPackageResolution } from "@hypit/loader/node";
+import { SqliteRuntimeState } from "../src/sqlite-state.js";
+import { createGreetingBuild, manifest, capabilities, producers, types } from "../../kernel/test/greeting-fixture.js";
import { createRuntimeFromConfig, statePath } from "../src/config.js";
import { superviseBuilds } from "../src/supervisor.js";
@@ -41,27 +41,25 @@ test("isolated Builds load fresh transitive code and Profile choices, share capa
async function packageAt(directory: string, revision: string) {
const pkg = join(directory, "node_modules", "fixture-components");
await mkdir(pkg, { recursive: true });
- await writeFile(join(directory, "package.json"), JSON.stringify({ private: true }));
+ await writeFile(join(directory, "package.json"), JSON.stringify({ private: true, hypit: { project: true } }));
await writeFile(join(pkg, "package.json"), JSON.stringify({ name: "fixture-components", version: "1.0.0", type: "module", hypit: { activation: "./activation.ts" } }));
await writeFile(join(pkg, "revision.ts"), `export const revision: string = ${JSON.stringify(revision)};`);
await writeFile(join(pkg, "activation.ts"), `
import { revision } from './revision.js';
import { access, writeFile, appendFile } from 'node:fs/promises';
import { setTimeout as pause } from 'node:timers/promises';
- import { createRuntimeEndpointAdapterFacet } from '@hypit/runtime-kit';
- import { defineEndpointPackage } from '@hypit/endpoint-kit';
+ import { createRuntimeEndpointAdapterFacet } from '@hypit/runtime-local/extension';
+ import { defineEndpoint } from '@hypit/endpoint';
const producers = ${JSON.stringify(producers)};
export default {
- format: 'hypit.node-package@1', modules: [{ manifest: ${JSON.stringify(manifest)} }],
- components: [{ producers: [
+ format: 'hypit.package@1', modules: [{ manifest: ${JSON.stringify(manifest)} }],
+ facets: [{ abi: 'hypit.producer-package@1', implementation: { producers: [
{ producer: producers.makePrompt, handler: () => ({ outputs: { prompt: { kind: 'inline', value: revision } }, needs: {} }) },
{ producer: producers.requestText, handler: ({ inputs }) => ({ outputs: {}, needs: { generation: { prompt: inputs.prompt.value.value } } }) },
{ producer: producers.assemble, handler: ({ inputs }) => ({ outputs: { document: { kind: 'inline', value: { text: inputs.generated.value.value, revision } } }, needs: {} }) },
- ] }],
- hostFacets: [createRuntimeEndpointAdapterFacet({ use: 'fixture-components', activate(context) {
+ ] } }, createRuntimeEndpointAdapterFacet({ use: 'fixture-components', activate(context) {
const config = context.config;
- return { endpoint: defineEndpointPackage({
- module: { name: 'fixture.provider', version: '1' }, facet: 'generation',
+ return { endpoint: defineEndpoint({
instance: context.instance, pool: context.pool, defaultConcurrency: 1,
capabilities: [config.remote ? {
lifecycle: 'asynchronous', capability: ${JSON.stringify(capabilities.generation)}, returns: ${JSON.stringify(types.generated)},
@@ -105,9 +103,9 @@ test("isolated Builds load fresh transitive code and Profile choices, share capa
const authored = new Set(initial.program.records.map((record) => record.id));
await runtime.build({ id,
definition: defineBuild({ program: initial.program, initialRecords: initial.records.filter((record) => !authored.has(record.id)), plan: initial.plan, targets: initial.targets }),
- componentPackages: ["fixture-components"],
+ executionPackages: ["fixture-components"],
catalog: { source: { path: join(directory, "main.svml") }, publishedOutputs: [{ name: "document", ref: { kind: "logical-output", id: "document" } }] },
- result: { repository: { root: directory, selection: { use: "@hypit/build-result-fs", config: { path: "results" } } } },
+ result: { repository: { root: directory, path: "results" } },
});
return id;
}
diff --git a/packages/runtime-local/test/extension.test.ts b/packages/runtime-local/test/extension.test.ts
new file mode 100644
index 00000000..e2cd12aa
--- /dev/null
+++ b/packages/runtime-local/test/extension.test.ts
@@ -0,0 +1,111 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import {
+ createRuntimeCredentialStoreAdapterFacet,
+ createRuntimeEndpointAdapterFacet,
+ isRuntimeAdapterFacet,
+ runtimeConfigBoolean,
+ runtimeConfigExact,
+ runtimeConfigObject,
+ runtimeConfigPositiveInteger,
+ runtimeConfigString,
+ RuntimeAdapterRegistry,
+} from "@hypit/runtime-local/extension";
+import type { RuntimeAdapterFactoryContext } from "@hypit/runtime-local/extension";
+
+const context = { hostStateRoot: "/host", dataRoot: "/tmp", instance: "one", config: {} };
+const endpointInstance = (instance: string) => ({
+ name: instance,
+ manifest: { facets: [] },
+ instance: { id: instance },
+ offers: [],
+ credentials: [],
+ install() {},
+}) as never;
+const endpoint = (use: string, extra: Record<string, unknown> = {}) =>
+ createRuntimeEndpointAdapterFacet({
+ use,
+ activate: (value: RuntimeAdapterFactoryContext) => ({ endpoint: endpointInstance(value.instance), ...extra }),
+ } as never);
+
+test("Endpoint and Credential Store adapters may share one package address", () => {
+ const registry = new RuntimeAdapterRegistry();
+ registry.registerFacet(endpoint("example.shared"));
+ registry.registerFacet(createRuntimeCredentialStoreAdapterFacet({
+ use: "example.shared",
+ validate() {},
+ open: () => ({ value: {} as never }),
+ }));
+ assert.ok(registry.has("example.shared", "endpoint"));
+ assert.ok(registry.has("example.shared", "credential-store"));
+});
+
+test("one kind and logical name has one adapter, so a second registration is an error", () => {
+ const registry = new RuntimeAdapterRegistry();
+ registry.registerFacet(endpoint("example.endpoint"));
+ assert.throws(() => registry.registerFacet(endpoint("example.endpoint")), /already registered/u);
+});
+
+test("an Endpoint facet without activate() is not a facet", () => {
+ assert.throws(
+ () => createRuntimeEndpointAdapterFacet({ use: "x" } as never),
+ /does not implement activate\(\)/u,
+ );
+ assert.throws(
+ () => createRuntimeEndpointAdapterFacet({ use: "x", activate: 1 } as never),
+ /does not implement activate\(\)/u,
+ );
+ assert.throws(
+ () => createRuntimeEndpointAdapterFacet({ use: " ", activate: () => ({}) } as never),
+ /use name is empty/u,
+ );
+});
+
+test("one activation validates and declares the selected Endpoint", async () => {
+ let activated = 0;
+ const registry = new RuntimeAdapterRegistry();
+ registry.registerFacet(createRuntimeEndpointAdapterFacet({
+ use: "example.validated",
+ activate(value) {
+ activated += 1;
+ if (value.config !== null && typeof value.config === "object" && "bad" in value.config) {
+ throw new Error("bad config");
+ }
+ return { endpoint: endpointInstance(value.instance) };
+ },
+ }));
+
+ await assert.rejects(
+ async () => await registry.activateEndpoint("example.validated", { ...context, config: { bad: true } }),
+ /bad config/u,
+ );
+ const activation = await registry.activateEndpoint("example.validated", context);
+ assert.equal(activation.endpoint.instance.id, "one");
+ assert.equal(activated, 2);
+});
+
+test("a produced facet is recognisable as a Runtime Adapter facet", () => {
+ assert.ok(isRuntimeAdapterFacet(endpoint("example.endpoint")));
+ assert.equal(isRuntimeAdapterFacet({ abi: "something-else" } as never), false);
+});
+
+test("Runtime config readers accept a value or refuse it; they never guess one", () => {
+ const config = runtimeConfigObject({ a: "x", n: 2, b: true }, "subject");
+ assert.equal(runtimeConfigString(config.a, "a"), "x");
+ assert.equal(runtimeConfigPositiveInteger(config.n, "n"), 2);
+ assert.equal(runtimeConfigBoolean(config.b, "b"), true);
+ // Absence is absence, not a default.
+ assert.equal(runtimeConfigString(undefined, "a"), undefined);
+ assert.equal(runtimeConfigPositiveInteger(undefined, "n"), undefined);
+ assert.equal(runtimeConfigBoolean(undefined, "b"), undefined);
+
+ assert.throws(() => runtimeConfigObject([] as never, "subject"), /must be an object/u);
+ assert.throws(() => runtimeConfigString(1 as never, "a"), /a/u);
+ assert.throws(() => runtimeConfigPositiveInteger(0 as never, "n"), /n/u);
+ assert.throws(() => runtimeConfigPositiveInteger(1.5 as never, "n"), /n/u);
+ assert.throws(() => runtimeConfigBoolean("true" as never, "b"), /b/u);
+ // An unknown key is a misconfiguration, not something to ignore.
+ assert.throws(() => runtimeConfigExact(config, ["a", "n"], "subject"), /does not accept b/u);
+ assert.doesNotThrow(() => runtimeConfigExact(config, ["a", "n", "b"], "subject"));
+});
diff --git a/packages/runtime-local/test/file-credentials-cli.test.ts b/packages/runtime-local/test/file-credentials-cli.test.ts
new file mode 100644
index 00000000..4f8b1eb7
--- /dev/null
+++ b/packages/runtime-local/test/file-credentials-cli.test.ts
@@ -0,0 +1,54 @@
+import assert from "node:assert/strict";
+import { execFile } from "node:child_process";
+import { mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { fileURLToPath } from "node:url";
+import { promisify } from "node:util";
+import test from "node:test";
+
+const exec = promisify(execFile);
+const launcher = fileURLToPath(new URL("../../../bin/hypit.mjs", import.meta.url));
+
+test("an explicitly selected file Store supports CLI login, repair and logout without starting execution", async (t) => {
+ const root = await mkdtemp(join(tmpdir(), "hypit-cli-file-credentials-"));
+ t.after(() => rm(root, { recursive: true, force: true }));
+ const state = join(root, "host");
+ const run = (...args: string[]) => exec(process.execPath, [launcher, ...args, "--json"], {
+ cwd: root, env: { ...process.env, HYPIT_STATE_HOME: state }, timeout: 30_000, windowsHide: true,
+ });
+ await writeFile(join(root, "package.json"), JSON.stringify({ private: true, hypit: { project: true } }));
+ await run("runtime", "init", "--project", root);
+ const profilePath = join(root, "hypit.runtime.json");
+ const profile = JSON.parse(await readFile(profilePath, "utf8"));
+ assert.equal(profile.credentials.local.use, "@hypit/credential-store-local", "initialization preserves the existing starter choice");
+ const directory = join(root, "chosen-credentials");
+ profile.credentials = { local: { use: "@hypit/credential-store-local", config: { backend: "file", path: directory } } };
+ profile.endpoints = { "hypihub.default": { ...profile.endpoints["hypihub.default"], config: {
+ ...profile.endpoints["hypihub.default"].config,
+ apiKey: { store: "local", key: "test.oauth" },
+ } } };
+ await writeFile(profilePath, JSON.stringify(profile));
+ const auth = (action: string, ...args: string[]) => run("auth", action, "hypihub.default", "--runtime", profilePath, ...args);
+ assert.equal(JSON.parse((await auth("status")).stdout).credentials[0].configured, false);
+ const input = join(root, "input.txt");
+ await writeFile(input, "test-secret-never-display");
+ await auth("login", "--from", input);
+ const status = (await auth("status")).stdout;
+ assert.equal(JSON.parse(status).credentials[0].configured, true);
+ assert.doesNotMatch(status, /test-secret-never-display/u);
+ const path = join(directory, (await readdir(directory))[0]!);
+ await writeFile(path, "corrupt-secret-never-display");
+ await assert.rejects(auth("status"), error => {
+ const output = String((error as { stdout?: string }).stdout);
+ assert.match(JSON.parse(output).error.message, /Cannot decode credential file/u);
+ assert.doesNotMatch(output, /corrupt-secret-never-display/u);
+ return true;
+ });
+ await auth("login", "--from", input);
+ assert.equal(JSON.parse((await auth("status")).stdout).credentials[0].configured, true);
+ await writeFile(path, "corrupt-again");
+ await auth("logout");
+ assert.equal(JSON.parse((await auth("status")).stdout).credentials[0].configured, false);
+ assert.deepEqual(await readdir(directory), []);
+});
diff --git a/packages/runtime-local/test/host-api.test.ts b/packages/runtime-local/test/host-api.test.ts
new file mode 100644
index 00000000..6751d183
--- /dev/null
+++ b/packages/runtime-local/test/host-api.test.ts
@@ -0,0 +1,29 @@
+import assert from "node:assert/strict";
+import { chmod, mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import test from "node:test";
+
+import {
+ diagnoseRuntimeExecutable,
+ resolveRuntimeExecutable,
+} from "@hypit/runtime-local/node";
+
+test("configured executable paths are rooted at the Runtime Profile project", async () => {
+ const root = await mkdtemp(join(tmpdir(), "hypit-runtime-host-node-"));
+ try {
+ const path = join(root, "tools", "fixture");
+ await mkdir(join(root, "tools"), { recursive: true });
+ await writeFile(path, "#!/bin/sh\n", "utf8");
+ await chmod(path, 0o755);
+ assert.equal(resolveRuntimeExecutable(root, "./tools/fixture"), path);
+ assert.deepEqual(await diagnoseRuntimeExecutable({
+ root,
+ configured: "./tools/fixture",
+ fallback: "unused",
+ subject: "fixture",
+ }), []);
+ } finally {
+ await rm(root, { recursive: true, force: true });
+ }
+});
diff --git a/packages/runtime-local/test/local.test.ts b/packages/runtime-local/test/local.test.ts
index 5111e6f1..461ce9f4 100644
--- a/packages/runtime-local/test/local.test.ts
+++ b/packages/runtime-local/test/local.test.ts
@@ -17,24 +17,26 @@ import { join } from "node:path";
import { pathToFileURL } from "node:url";
import test from "node:test";
-import { FileResourceStore } from "@hypit/resource-store-fs";
-import { FileBuildResultRepository } from "@hypit/build-result";
-import type { BuildResultRepository } from "@hypit/build-result";
+import { FileResourceStore } from "../src/resource-store.js";
+import { FileBuildResultRepository } from "@hypit/result/node";
+import type { BuildResultRepository } from "@hypit/result";
import { EnvironmentCredentialStore } from "@hypit/credential-store-env";
-import { defineEndpointPackage } from "@hypit/endpoint-kit";
-import type { AsyncEndpoint, EndpointPackage } from "@hypit/endpoint-kit";
-import type { ComponentPackage } from "@hypit/component-kit";
+import { defineEndpoint } from "@hypit/endpoint";
+import type { AsyncEndpoint, EndpointInstance } from "@hypit/endpoint";
+import { createProducerPackageFacet } from "@hypit/producer";
+import type { ProducerPackage } from "@hypit/producer";
+import { createAdmissionPackageFacet } from "@hypit/admission";
+import type { AdmissionPackage } from "@hypit/admission";
import { createLocalRuntime } from "@hypit/runtime-local";
-import { resolveProjectRoot } from "@hypit/project-context-node";
-import { NodeFilesystemWorkspace } from "../../workspace-fs-node/src/index.js";
-import { defineBuild } from "@hypit/core";
-import {
- collectLoadedNodePackageComponents,
- loadNodePackageSelection,
-} from "@hypit/package-loader-node";
-import { buildExecutionActivity, credentialRef } from "@hypit/runtime";
-import type { BuildCompletion, CredentialValue, WritableCredentialStore } from "@hypit/runtime";
-import { SqliteRuntimeState } from "@hypit/store-sqlite";
+import { resolveProjectRoot } from "@hypit/project";
+import { NodeFilesystemWorkspace } from "@hypit/workspace/node";
+import { defineBuild } from "@hypit/kernel";
+import { loadNodePackageSelection } from "@hypit/loader/node";
+import { credentialRef } from "@hypit/runtime";
+import { buildExecutionActivity } from "@hypit/runtime-local";
+import type { BuildCompletion } from "@hypit/runtime-local";
+import type { CredentialValue, WritableCredentialStore } from "@hypit/runtime";
+import { SqliteRuntimeState } from "../src/sqlite-state.js";
import {
capabilities,
@@ -43,7 +45,7 @@ import {
manifest as greetingManifest,
producers,
types,
-} from "../../core/test/greeting-fixture.js";
+} from "../../kernel/test/greeting-fixture.js";
const providerModule = { name: "example.local-endpoint", version: "1" } as const;
@@ -74,11 +76,8 @@ function projectRuntimeFixture(directory: string) {
clearBuildResources: async (build: string) => {
await rm(join(work, build), { recursive: true, force: true });
},
- openBuildResultRepository: async (location: import("@hypit/build-result-kit").BuildResultRepositoryLocation) => {
- assert.equal(location.selection.use, "@hypit/build-result-fs");
- const config = location.selection.config as { readonly path?: string } | undefined;
- return { repository: new FileBuildResultRepository(join(location.root, config?.path ?? ".hypit/results")) };
- },
+ openBuildResultRepository: async (location: import("@hypit/runtime-local").BuildResultRepositoryLocation) =>
+ ({ repository: new FileBuildResultRepository(join(location.root, location.path)) }),
credentialStore: new EnvironmentCredentialStore(),
close: () => state.close(),
} as const;
@@ -86,10 +85,7 @@ function projectRuntimeFixture(directory: string) {
function resultDestination(directory: string) {
return {
- repository: {
- root: directory,
- selection: { use: "@hypit/build-result-fs", config: { path: "results" } },
- },
+ repository: { root: directory, path: "results" },
} as const;
}
@@ -122,16 +118,19 @@ test("a project directory alias admits its Source and stores a project-relative
await writeFile(join(parent, "outside.svs"), "outside");
await symlink(directory, alias, "junction");
await symlink(parent, join(directory, "escape"), "junction");
- const root = await resolveProjectRoot({ workspaceRoot: alias });
- const session = await new NodeFilesystemWorkspace({ root }).open(join(alias, "main.svml"));
- await assert.rejects(async () => await session.resolveSource(session.entry, { from: "./escape/outside.svs", alias: "outside" }),
+ const root = await resolveProjectRoot({ projectRoot: alias });
+ const session = await new NodeFilesystemWorkspace({
+ root,
+ sourceAdapter: (unit) => ({ unit, frontend: "test.frontend@1" }),
+ }).open(join(alias, "main.svml"));
+ await assert.rejects(async () => await session.resolveSource(session.entry.unit, { from: "./escape/outside.svs", alias: "outside" }),
{ code: "SOURCE_OUTSIDE_ROOT" });
const runtime = await createLocalRuntime(projectRuntimeFixture(directory));
try {
const request = durableBuildRequest(root, "bld_20260916T150000000Z_0000000001", createGreetingBuild());
- await runtime.build({ ...request, catalog: { ...request.catalog, source: { path: session.entry.id } } });
+ await runtime.build({ ...request, catalog: { ...request.catalog, source: { path: session.entry.unit.id } } });
const result = await new FileBuildResultRepository(join(directory, "results")).read(request.id);
- assert.equal(result?.source.path, "main.svml");
+ assert.equal(result?.source.id, "main.svml");
} finally { await runtime.close(); }
} finally { await rm(parent, { recursive: true, force: true }); }
});
@@ -145,7 +144,7 @@ test("a forward-only Build completes with no Core records or Producer work", asy
const repository = new FileBuildResultRepository(join(directory, "results"));
const prior = await repository.create({
id: priorId,
- source: { path: "main.svml" },
+ source: { id: "main.svml" },
targets: ["document"],
publishedOutputs: [{ name: "document", output: "document" }],
});
@@ -217,7 +216,7 @@ async function finishClaimedBuild(
// An embedding test supplies implementations explicitly and advances their owned turns.
// Production process lifecycle is exercised through superviseBuilds in the process tests.
async function runFixture(runtime: Awaited<ReturnType<typeof createLocalRuntime>>,
- store: import("@hypit/runtime").BuildExecutionStore,
+ store: import("@hypit/runtime-local").BuildExecutionStore,
options: {idlePollMs:number,signal:AbortSignal}): Promise<void> {
const active = new Map<string,Promise<void>>();
let failure: unknown;
@@ -244,9 +243,7 @@ test("Endpoint-declared credentials use the selected writable Store without a Pr
async put(ref, value) { values.set(ref.key, value); },
async delete(ref) { return values.delete(ref.key); },
};
- const endpoint = defineEndpointPackage({
- module: providerModule,
- facet: "generation",
+ const endpoint = defineEndpoint({
instance: "generation.auth-test",
pool: "generation.auth-test",
credentials: { apiKey: credentialRef("memory", "generation.api-key") },
@@ -303,7 +300,7 @@ test("project local Runtime advances, polls and cancels work with replaceable pa
let starts = 0;
let polls = 0;
let cancels = 0;
- const components: ComponentPackage = {
+ const components: ProducerPackage & AdmissionPackage = {
producers: [
{
producer: producers.makePrompt,
@@ -364,9 +361,7 @@ test("project local Runtime advances, polls and cancels work with replaceable pa
return { status: "confirmed" };
},
};
- const endpointPackage: EndpointPackage = defineEndpointPackage({
- module: providerModule,
- facet: "generation",
+ const endpointInstance: EndpointInstance = defineEndpoint({
instance: "generation.personal",
pool: "generation.personal",
capabilities: [{
@@ -381,8 +376,8 @@ test("project local Runtime advances, polls and cancels work with replaceable pa
try {
firstRuntime = await createLocalRuntime({
...projectRuntimeFixture(directory),
- components: [components],
- endpoints: [endpointPackage],
+ producerPackages: [components], admissionPackages: [components],
+ endpoints: [endpointInstance],
});
const first = await firstRuntime.build({
id: "bld_20260902T120000001Z_0000000001",
@@ -398,7 +393,7 @@ test("project local Runtime advances, polls and cancels work with replaceable pa
assert.equal(starts, 1);
assert.equal(polls, 0);
assert.equal("work" in firstRuntime, false, "execution lifecycle belongs to the Runtime Host");
- const otherRuntime = await createLocalRuntime({ ...projectRuntimeFixture(directory), components:[components], endpoints:[endpointPackage] });
+ const otherRuntime = await createLocalRuntime({ ...projectRuntimeFixture(directory), producerPackages: [components], admissionPackages: [components], endpoints:[endpointInstance] });
try {
assert.equal(await otherRuntime.workOnce(), undefined);
await assert.rejects(otherRuntime.workOnce({build:"bld_20260902T120000001Z_0000000001"}), /another execution context/u);
@@ -455,7 +450,7 @@ test("a completed public file moves into its Build Result and leaves no Runtime
const workStore = new FileResourceStore(join(directory, ".hypit", "work", id));
const initial = createGreetingBuild({ generationRealization: "placeholder", targetOutputs: ["generated"] });
const buildDefinition = definition(initial);
- const components: ComponentPackage = {
+ const components: ProducerPackage & AdmissionPackage = {
producers: [{
producer: producers.makePrompt,
handler: () => ({ outputs: { prompt: { kind: "inline", value: "make a clip" } }, needs: {} }),
@@ -470,7 +465,7 @@ test("a completed public file moves into its Build Result and leaves no Runtime
try {
const runtime = await createLocalRuntime({
...projectRuntimeFixture(directory),
- components: [components],
+ producerPackages: [components], admissionPackages: [components],
});
await runtime.build({
id,
@@ -503,7 +498,7 @@ test("a completed public file moves into its Build Result and leaves no Runtime
test("a failed Build keeps public Outputs completed before removing active Runtime state", async () => {
const directory = await mkdtemp(join(tmpdir(), "hypit-local-bld_20260902T120000005Z_0000000001-"));
const initial = createGreetingBuild();
- const components: ComponentPackage = {
+ const components: ProducerPackage & AdmissionPackage = {
producers: [{
producer: producers.makePrompt,
handler: () => ({ outputs: { prompt: { kind: "inline", value: "Greet Ada" } }, needs: {} }),
@@ -515,9 +510,7 @@ test("a failed Build keeps public Outputs completed before removing active Runti
},
}],
};
- const endpoint = defineEndpointPackage({
- module: providerModule,
- facet: "generation",
+ const endpoint = defineEndpoint({
instance: "generation.failure",
pool: "generation.failure",
capabilities: [{
@@ -533,7 +526,7 @@ test("a failed Build keeps public Outputs completed before removing active Runti
try {
const runtime = await createLocalRuntime({
...projectRuntimeFixture(directory),
- components: [components],
+ producerPackages: [components], admissionPackages: [components],
endpoints: [endpoint],
});
await runtime.build({
@@ -570,7 +563,7 @@ for (const phase of ["submit", "poll"] as const) {
const initial = createParallelGreetingBuild();
let starts = 0;
let polls = 0;
- const components: ComponentPackage = { producers: [
+ const components: ProducerPackage & AdmissionPackage = { producers: [
{ producer: producers.makePrompt, handler: () => ({ outputs: { prompt: { kind: "inline", value: "hello" } }, needs: {} }) },
{ producer: producers.requestText, handler: () => ({ outputs: {}, needs: { generation: {} } }) },
] };
@@ -579,8 +572,8 @@ for (const phase of ["submit", "poll"] as const) {
await new Promise<void>((resolve) => setTimeout(resolve, 10));
return { status: "completed" as const, result: { value: { kind: "inline" as const, value: "retained sibling output" } } };
};
- const endpoint = defineEndpointPackage({
- module: providerModule, facet: "generation", instance: "generation.siblings", pool: "generation.siblings", defaultConcurrency: 2,
+ const endpoint = defineEndpoint({
+ instance: "generation.siblings", pool: "generation.siblings", defaultConcurrency: 2,
capabilities: [{ lifecycle: "asynchronous", capability: capabilities.generation, returns: types.generated, endpoint: {
start() {
const id = ++starts;
@@ -589,7 +582,7 @@ for (const phase of ["submit", "poll"] as const) {
poll({ handle }) { polls++; return finish((handle as { id: number }).id); },
} }],
});
- const runtime = await createLocalRuntime({ ...projectRuntimeFixture(directory), components: [components], endpoints: [endpoint] });
+ const runtime = await createLocalRuntime({ ...projectRuntimeFixture(directory), producerPackages: [components], admissionPackages: [components], endpoints: [endpoint] });
try {
const id = "bld_20260906T110000000Z_0000000001";
await runtime.build(durableBuildRequest(directory, id, initial));
@@ -612,7 +605,7 @@ test("an interrupted Result write finishes explicitly without rerunning the Buil
const initial = createGreetingBuild({ generationRealization: "placeholder" });
let generationCalls = 0;
let rejectSync = true;
- const components: ComponentPackage = {
+ const components: ProducerPackage & AdmissionPackage = {
producers: [{
producer: producers.makePrompt,
handler: () => ({ outputs: { prompt: { kind: "inline", value: "Greet Ada" } }, needs: {} }),
@@ -636,10 +629,9 @@ test("an interrupted Result write finishes explicitly without rerunning the Buil
};
const fixture = projectRuntimeFixture(directory);
const openRepository = async (
- location: import("@hypit/build-result-kit").BuildResultRepositoryLocation,
+ location: import("@hypit/runtime-local").BuildResultRepositoryLocation,
) => {
- const path = (location.selection.config as { readonly path?: string } | undefined)?.path ?? ".hypit/results";
- const base = new FileBuildResultRepository(join(location.root, path));
+ const base = new FileBuildResultRepository(join(location.root, location.path));
const repository: BuildResultRepository = {
create: async (seed) => await base.create(seed),
async openWriter(build) {
@@ -669,7 +661,7 @@ test("an interrupted Result write finishes explicitly without rerunning the Buil
const runtime = await createLocalRuntime({
...fixture,
openBuildResultRepository: openRepository,
- components: [components],
+ producerPackages: [components], admissionPackages: [components],
});
await runtime.build({
id: "bld_20260902T120000006Z_0000000001",
@@ -740,7 +732,7 @@ test("an immediate Command left in started state fails its Build without invokin
const directory = await mkdtemp(join(tmpdir(), "hypit-local-command-receipt-"));
const initial = createGreetingBuild({ generationRealization: "placeholder" });
let calls = 0;
- const components: ComponentPackage = {
+ const components: ProducerPackage & AdmissionPackage = {
producers: [{
producer: producers.makePrompt,
handler: () => {
@@ -753,7 +745,7 @@ test("an immediate Command left in started state fails its Build without invokin
try {
runtime = await createLocalRuntime({
...projectRuntimeFixture(directory),
- components: [components],
+ producerPackages: [components], admissionPackages: [components],
});
const submitted = await runtime.build(durableBuildRequest(directory, "bld_20260902T120000008Z_0000000001", initial));
const command = submitted.state.outstanding[0];
@@ -798,7 +790,7 @@ test("a selected file is staged once and remains referenced in the produced Comp
});
let attachmentOpens = 0;
let endpointCalls = 0;
- const components: ComponentPackage = {
+ const components: ProducerPackage & AdmissionPackage = {
producers: [{
producer: producers.makePrompt,
handler: ({ inputs }) => ({ outputs: { prompt: inputs.intent!.value }, needs: {} }),
@@ -813,9 +805,7 @@ test("a selected file is staged once and remains referenced in the produced Comp
}),
}],
};
- const endpoint = defineEndpointPackage({
- module: providerModule,
- facet: "generation",
+ const endpoint = defineEndpoint({
instance: "generation.bld_20260902T120000009Z_0000000001",
pool: "generation.bld_20260902T120000009Z_0000000001",
capabilities: [{
@@ -836,7 +826,7 @@ test("a selected file is staged once and remains referenced in the produced Comp
await writeFile(inputPath, bytes);
const runtime = await createLocalRuntime({
...projectRuntimeFixture(directory),
- components: [components],
+ producerPackages: [components], admissionPackages: [components],
endpoints: [endpoint],
});
await runtime.build({
@@ -901,7 +891,7 @@ test("one local Worker admits later Builds while preserving shared Endpoint capa
let markSecondStarted: (() => void) | undefined;
const secondStarted = new Promise<void>((resolve) => { markSecondStarted = resolve; });
let unrestrictedStarts = 0;
- const components: ComponentPackage = {
+ const components: ProducerPackage & AdmissionPackage = {
producers: [
{
producer: producers.makePrompt,
@@ -951,9 +941,7 @@ test("one local Worker admits later Builds while preserving shared Endpoint capa
},
],
};
- const endpoint = defineEndpointPackage({
- module: providerModule,
- facet: "generation",
+ const endpoint = defineEndpoint({
instance: "generation.serial",
pool: "generation.serial",
defaultConcurrency: 1,
@@ -990,7 +978,7 @@ test("one local Worker admits later Builds while preserving shared Endpoint capa
},
remove: (...args) => fixture.buildStore.remove!(...args),
},
- components: [components],
+ producerPackages: [components], admissionPackages: [components],
endpoints: [endpoint],
});
await runtime.build(durableBuildRequest(directory, "bld_20260902T120000010Z_0000000001", createGreetingBuild()));
@@ -1071,10 +1059,12 @@ test("project local runtime accepts components loaded from an installed package"
const module = { name: manifest.name, version: manifest.version };
const producer = (name) => ({ module, name });
export default {
- format: "hypit.node-package@1",
+ format: "hypit.package@1",
modules: [{ manifest }],
- components: [{
- producers: [
+ facets: [{
+ abi: "hypit.producer-package@1",
+ implementation: {
+ producers: [
{
producer: producer("make-prompt"),
handler({ inputs }) {
@@ -1094,7 +1084,8 @@ test("project local runtime accepts components loaded from an installed package"
return { outputs: { document: { kind: "inline", value: { text: inputs.generated.value.value } } }, needs: {} };
},
},
- ],
+ ],
+ },
}],
};
`, "utf8");
@@ -1102,15 +1093,14 @@ test("project local runtime accepts components loaded from an installed package"
try {
const runtime = await createLocalRuntime({
...projectRuntimeFixture(runtimeRoot),
- loadComponentPackages: async (specifiers) => {
- const loaded = await loadNodePackageSelection(specifiers, installedRoot);
- return collectLoadedNodePackageComponents(loaded);
+ loadProducerPackages: async (specifiers) => {
+ return await loadNodePackageSelection(specifiers, installedRoot);
},
});
const selected = createGreetingBuild({ generationRealization: "placeholder" });
const result = await runtime.build({
...durableBuildRequest(runtimeRoot, "bld_20260902T120000012Z_0000000001", selected),
- componentPackages: ["example-greeting-components"],
+ executionPackages: ["example-greeting-components"],
});
assert("view" in result);
assert.equal(result.view.activity, "ready");
@@ -1127,7 +1117,7 @@ test("project local runtime accepts components loaded from an installed package"
test("project local runtime remembers the complete package closure across incremental Builds", async () => {
const directory = await mkdtemp(join(tmpdir(), "hypit-local-component-closure-"));
const loadedSelections: string[][] = [];
- const sharedComponents: ComponentPackage = {
+ const sharedComponents: ProducerPackage & AdmissionPackage = {
validators: [{ type: types.intent, handler() {} }],
producers: [
{
@@ -1157,11 +1147,14 @@ test("project local runtime remembers the complete package closure across increm
};
const runtime = await createLocalRuntime({
...projectRuntimeFixture(directory),
- loadComponentPackages(specifiers) {
+ loadProducerPackages(specifiers) {
loadedSelections.push([...specifiers]);
return [
- ...specifiers.map((specifier) => ({ specifier, components: [] })),
- { specifier: "example-shared-components", components: [sharedComponents] },
+ ...specifiers.map((specifier) => ({ specifier, contribution: { format: "hypit.package@1" as const } })),
+ { specifier: "example-shared-components", contribution: {
+ format: "hypit.package@1" as const,
+ facets: [createProducerPackageFacet(sharedComponents), createAdmissionPackageFacet(sharedComponents)],
+ } },
];
},
});
@@ -1174,7 +1167,7 @@ test("project local runtime remembers the complete package closure across increm
const initial = createGreetingBuild({ generationRealization: "placeholder" });
await runtime.build({
...durableBuildRequest(directory, id, initial),
- componentPackages: [specifier],
+ executionPackages: [specifier],
});
const completed = await finishClaimedBuild(runtime);
assert.equal(completed.outcome, "complete");
@@ -1195,7 +1188,7 @@ for (const cancellation of ["accepted", "unsupported", "failed-build", "host-fai
let fixture = projectRuntimeFixture(directory);
let failRead = false;
let remoteActive = 0, starts = 0, cancels = 0, polls = 0;
- const provider = defineEndpointPackage({ module: providerModule, facet: "generation", instance: "settlement",
+ const provider = defineEndpoint({ instance: "settlement",
pool: "shared", defaultConcurrency: 1, capabilities: [{ capability: capabilities.generation, returns: types.generated,
lifecycle: "asynchronous", endpoint: {
start() { starts++; remoteActive++; return { status: "pending", handle: { job: starts }, receipt: { id: `job-${starts}` }, wakeAt: Date.now() + 60_000 }; },
@@ -1210,7 +1203,7 @@ for (const cancellation of ["accepted", "unsupported", "failed-build", "host-fai
if (failRead) { failRead = false; throw new Error("Runtime read interrupted"); }
return await fixture.buildStore.read(build);
},
- }, components: [{ producers: [
+ }, producerPackages: [{ producers: [
{ producer: producers.makePrompt, handler: () => ({ outputs: { prompt: { kind: "inline", value: "hello" } }, needs: {} }) },
{ producer: producers.requestText, handler: () => ({ outputs: {}, needs: { generation: { prompt: "hello" } } }) },
] }] });
@@ -1224,7 +1217,7 @@ for (const cancellation of ["accepted", "unsupported", "failed-build", "host-fai
if (cancellation === "failed-build" || cancellation === "host-failure") {
if (cancellation === "failed-build") {
const snapshot = (await fixture.buildStore.read(first))!;
- const { BuildMachine } = await import("@hypit/core");
+ const { BuildMachine } = await import("@hypit/kernel");
const machine = new BuildMachine(snapshot.definition, snapshot.facts);
const operation = (await fixture.operationStore.list({ build: first }))[0]!;
const fact = machine.evaluate({ kind: "command-failed", command: operation.command, code: "EXAMPLE_FAILURE", message: "a sibling failed" });
@@ -1258,8 +1251,8 @@ test("concurrent durable Builds preserve action capacity and outcomes across fai
const fixture = projectRuntimeFixture(directory);
let starts = 0, activeTasks = 0, peakTasks = 0, downloads = 0, peakDownloads = 0;
const checks = new Map<number, number>();
- const provider = defineEndpointPackage({
- module: providerModule, facet: "generation", instance: "concurrent", pool: "shared-account",
+ const provider = defineEndpoint({
+ instance: "concurrent", pool: "shared-account",
defaultConcurrency: 8,
actionLimits: { submit: { concurrency: 2 }, collect: { concurrency: 2 } },
capabilities: [{ capability: capabilities.generation, returns: types.generated, lifecycle: "asynchronous", endpoint: {
@@ -1301,7 +1294,7 @@ test("concurrent durable Builds preserve action capacity and outcomes across fai
const runtime = await createLocalRuntime({
...fixture,
endpoints: [provider],
- components: [{ producers: [
+ producerPackages: [{ producers: [
{ producer: producers.makePrompt, handler: () => ({ outputs: { prompt: { kind: "inline", value: "hello" } }, needs: {} }) },
{ producer: producers.requestText, handler: () => ({ outputs: {}, needs: { generation: { prompt: "hello" } } }) },
] }],
@@ -1350,7 +1343,7 @@ test("local call logs survive cleanup and remain attributed across concurrent su
const fixture = projectRuntimeFixture(directory);
const runtime = await createLocalRuntime({
...fixture,
- endpoints: [defineEndpointPackage({ module: providerModule, facet: "generation", instance: "local-logs", pool: "local-logs", defaultConcurrency: 2,
+ endpoints: [defineEndpoint({ instance: "local-logs", pool: "local-logs", defaultConcurrency: 2,
capabilities: [{ capability: capabilities.generation, returns: types.generated, lifecycle: "immediate", async handler(context) {
const call = ++calls;
for (let completed = 0; completed < 4; completed++) await context.reportProgress?.({ phase: "rendering", completed, total: 4 });
@@ -1360,7 +1353,7 @@ test("local call logs survive cleanup and remain attributed across concurrent su
await context.reportProgress?.({ phase: "storing" });
return { value: { kind: "inline", value: `call ${call}` } };
} }] })],
- components: [{ producers: [
+ producerPackages: [{ producers: [
{ producer: producers.makePrompt, handler: () => ({ outputs: { prompt: { kind: "inline", value: "hello" } }, needs: {} }) },
{ producer: producers.requestText, handler: () => ({ outputs: {}, needs: { generation: { prompt: "hello" } } }) },
] }],
diff --git a/packages/runtime-local/test/platform-credentials-cli.test.ts b/packages/runtime-local/test/platform-credentials-cli.test.ts
new file mode 100644
index 00000000..23dfd68e
--- /dev/null
+++ b/packages/runtime-local/test/platform-credentials-cli.test.ts
@@ -0,0 +1,79 @@
+import assert from "node:assert/strict";
+import { execFile } from "node:child_process";
+import { mkdir, mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { fileURLToPath } from "node:url";
+import { promisify } from "node:util";
+import test from "node:test";
+
+const exec = promisify(execFile);
+const launcher = fileURLToPath(new URL("../../../bin/hypit.mjs", import.meta.url));
+
+/**
+ * The examples select the `platform` Store so one committed Profile works on Linux, macOS and Windows.
+ * On macOS and Windows it would use the real keychain or Credential Locker of whoever runs the
+ * suite, so this test covers Linux and skips other platforms.
+ */
+const isLinux = process.platform === "linux";
+
+test("the interview example authenticates on Linux, without editing its Profile",
+ { skip: !isLinux, timeout: 120_000 }, async (t) => {
+ const root = await mkdtemp(join(tmpdir(), "hypit-platform-example-"));
+ t.after(() => rm(root, { recursive: true, force: true }));
+ const project = join(root, "project");
+ const state = join(root, "host");
+ await mkdir(project, { recursive: true });
+ const profile = fileURLToPath(new URL("../../../examples/interview/hypit.runtime.json", import.meta.url));
+ const run = (...args: string[]) => exec(process.execPath, [launcher, ...args, "--json"], {
+ cwd: project, env: { ...process.env, HYPIT_STATE_HOME: state }, timeout: 60_000, windowsHide: true,
+ });
+ const auth = (action: string, ...args: string[]) =>
+ run("auth", action, "hypihub.default", "--runtime", profile, ...args);
+
+ const before = JSON.parse((await auth("status")).stdout).credentials[0];
+ assert.equal(before.configured, false, "the committed Profile opens, so nothing here rewrites it");
+ assert.equal(before.writable, true, "the Linux policy accepts a credential");
+ const input = join(root, "secret.txt");
+ await writeFile(input, "example-secret-never-displayed");
+ const login = await auth("login", "--from", input);
+ assert.doesNotMatch(login.stdout, /example-secret-never-displayed/u);
+ assert.equal(JSON.parse((await auth("status")).stdout).credentials[0].configured, true);
+
+ // Linux uses the file Store's own directory, so switching Stores there finds it.
+ assert.equal((await readdir(join(state, "credentials"))).length, 1);
+
+ await auth("logout");
+ assert.equal(JSON.parse((await auth("status")).stdout).credentials[0].configured, false);
+ assert.deepEqual(await readdir(join(state, "credentials")), []);
+ });
+
+test("the Profile runtime init writes authenticates on Linux, without editing it",
+ { skip: !isLinux, timeout: 120_000 }, async (t) => {
+ const root = await mkdtemp(join(tmpdir(), "hypit-platform-init-"));
+ t.after(() => rm(root, { recursive: true, force: true }));
+ const project = join(root, "project");
+ const state = join(root, "host");
+ await mkdir(project, { recursive: true });
+ const run = (...args: string[]) => exec(process.execPath, [launcher, ...args, "--json"], {
+ cwd: project, env: { ...process.env, HYPIT_STATE_HOME: state }, timeout: 60_000, windowsHide: true,
+ });
+ await run("runtime", "init");
+ const starter = JSON.parse(await readFile(join(project, "hypit.runtime.json"), "utf8"));
+ assert.deepEqual(starter.credentials, { local: { use: "@hypit/credential-store-local" } },
+ "a starter that selects a Store Linux cannot open fails every command that follows");
+
+ // Everything below resolves the Profile the starter just wrote and selected, with no flags.
+ const status = async () => JSON.parse((await run("auth", "status", "hypihub.default")).stdout).credentials[0];
+ assert.equal((await status()).configured, false);
+ assert.equal((await status()).writable, true);
+ const input = join(root, "secret.txt");
+ await writeFile(input, "starter-secret-never-displayed");
+ const login = await run("auth", "login", "hypihub.default", "--from", input);
+ assert.doesNotMatch(login.stdout, /starter-secret-never-displayed/u);
+ assert.equal((await status()).configured, true);
+ assert.equal((await readdir(join(state, "credentials"))).length, 1);
+ await run("auth", "logout", "hypihub.default");
+ assert.equal((await status()).configured, false);
+ assert.deepEqual(await readdir(join(state, "credentials")), []);
+ });
diff --git a/packages/runtime-local/test/programs.test.ts b/packages/runtime-local/test/programs.test.ts
index 3b3aab02..71bbfc94 100644
--- a/packages/runtime-local/test/programs.test.ts
+++ b/packages/runtime-local/test/programs.test.ts
@@ -5,8 +5,8 @@ import { join } from "node:path";
import test from "node:test";
import { setTimeout as sleep } from "node:timers/promises";
-import { createRuntimeEndpointAdapterFacet, RuntimeAdapterRegistry } from "@hypit/runtime-kit";
-import type { ManagedProgram, ManagedProgramCommand } from "@hypit/runtime-kit";
+import { createRuntimeEndpointAdapterFacet, RuntimeAdapterRegistry } from "@hypit/runtime-local/extension";
+import type { ManagedProgram, ManagedProgramCommand } from "@hypit/runtime-local/extension";
import type { CapabilityRef } from "@hypit/protocol";
import {
diff --git a/packages/resource-store-fs/test/store.test.ts b/packages/runtime-local/test/resource-store.test.ts
similarity index 97%
rename from packages/resource-store-fs/test/store.test.ts
rename to packages/runtime-local/test/resource-store.test.ts
index 408bd3db..85607cce 100644
--- a/packages/resource-store-fs/test/store.test.ts
+++ b/packages/runtime-local/test/resource-store.test.ts
@@ -5,7 +5,7 @@ import { join } from "node:path";
import test from "node:test";
import { setTimeout as delay } from "node:timers/promises";
-import { FileResourceStore } from "@hypit/resource-store-fs";
+import { FileResourceStore } from "../src/resource-store.js";
test("cancelled stream writes remove only their unfinished file", async () => {
const directory = await mkdtemp(join(tmpdir(), "hypit-resources-abort-"));
diff --git a/packages/runtime-local/test/rotation-process.test.ts b/packages/runtime-local/test/rotation-process.test.ts
index d2ccdef2..65aae522 100644
--- a/packages/runtime-local/test/rotation-process.test.ts
+++ b/packages/runtime-local/test/rotation-process.test.ts
@@ -7,10 +7,10 @@ import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { setTimeout as pause } from "node:timers/promises";
import test from "node:test";
-import { defineBuild } from "@hypit/core";
-import { FileBuildResultRepository } from "@hypit/build-result";
-import { SqliteRuntimeState } from "@hypit/store-sqlite";
-import { createGreetingBuild, manifest, capabilities, producers, types } from "../../core/test/greeting-fixture.js";
+import { defineBuild } from "@hypit/kernel";
+import { FileBuildResultRepository } from "@hypit/result/node";
+import { SqliteRuntimeState } from "../src/sqlite-state.js";
+import { createGreetingBuild, manifest, capabilities, producers, types } from "../../kernel/test/greeting-fixture.js";
import { statePath } from "../src/config.js";
const distribution = fileURLToPath(new URL("../../../", import.meta.url));
@@ -42,22 +42,22 @@ test("a draining carrier finishes its existing Build while a new carrier shares
const endpoint=`http://127.0.0.1:${address.port}`;
try {
const pkg=join(root,'node_modules','fixture-rotation'); await mkdir(pkg,{recursive:true});
- await writeFile(join(root,'package.json'),'{"private":true}');
+ await writeFile(join(root,'package.json'),'{"private":true,"hypit":{"project":true}}');
await writeFile(join(pkg,'package.json'),JSON.stringify({name:'fixture-rotation',version:'1.0.0',type:'module',hypit:{activation:'./activation.mjs'}}));
await writeFile(join(pkg,'activation.mjs'),`
- import {createRuntimeEndpointAdapterFacet} from '@hypit/runtime-kit';
- import {defineEndpointPackage} from '@hypit/endpoint-kit';
+ import {createRuntimeEndpointAdapterFacet} from '@hypit/runtime-local/extension';
+ import {defineEndpoint} from '@hypit/endpoint';
const server=${JSON.stringify(endpoint)};
async function call(path,name){return (await fetch(server+path,{method:'POST',body:JSON.stringify({name,pid:process.pid})})).json();}
let calls=0;
- export default {format:'hypit.node-package@1',modules:[{manifest:${JSON.stringify(manifest)}}],components:[{producers:[
+ export default {format:'hypit.package@1',modules:[{manifest:${JSON.stringify(manifest)}}],facets:[{abi:'hypit.producer-package@1',implementation:{producers:[
{producer:${JSON.stringify(producers.makePrompt)},handler:async({inputs})=>{
if(++calls!==1)throw Error('Build module state leaked');
const name=inputs.intent.value.value.name;await call('/local',name);return {outputs:{prompt:{kind:'inline',value:name}},needs:{}};
}},
{producer:${JSON.stringify(producers.requestText)},handler:({inputs})=>({outputs:{},needs:{generation:{prompt:inputs.prompt.value.value}}})}
- ]}],hostFacets:[createRuntimeEndpointAdapterFacet({use:'fixture-rotation',activate(context){return {endpoint:defineEndpointPackage({
- module:{name:'fixture.provider',version:'1'},facet:'generation',instance:context.instance,pool:context.pool,defaultConcurrency:1,
+ ]}},createRuntimeEndpointAdapterFacet({use:'fixture-rotation',activate(context){return {endpoint:defineEndpoint({
+ instance:context.instance,pool:context.pool,defaultConcurrency:1,
capabilities:[{lifecycle:'asynchronous',capability:${JSON.stringify(capabilities.generation)},returns:${JSON.stringify(types.generated)},endpoint:{
async start({need,operation}){const name=need.constraints.prompt;await call('/start',name);return {status:'pending',handle:{name},receipt:{id:operation},wakeAt:Date.now()+50};},
async poll({handle}){const result=await call('/poll',handle.name);return result.complete?{status:'completed',result:{value:{kind:'inline',value:handle.name}}}:{status:'pending',handle,wakeAt:Date.now()+50};}
@@ -71,10 +71,10 @@ test("a draining carrier finishes its existing Build while a new carrier shares
const id=`bld_20260914T120000000Z_${String(ids.size).padStart(10,'0')}`;ids.set(name,id);
const initial=createGreetingBuild({targetOutputs:[target]});const authored=new Set(initial.program.records.map(r=>r.id));
const base=defineBuild({program:initial.program,initialRecords:initial.records.filter(r=>!authored.has(r.id)),plan:initial.plan,targets:initial.targets});
- const request={build:id,componentPackages:['fixture-rotation'],result:{root,selection:{use:'@hypit/build-result-fs',config:{path:'results'}}},
+ const request={build:id,executionPackages:['fixture-rotation'],result:{root,path:'results'},
context:{format:'hypit.local-execution@1',packageRoot:root,hostStateRoot:join(root,'host'),distributionPackageRoot:distribution,profile:profileValue}};
await state.submissions.prepare(request);
- await repository.create({id,source:{path:'main.svml'},targets:[target],publishedOutputs:[{name:target,output:target}]});
+ await repository.create({id,source:{id:'main.svml'},targets:[target],publishedOutputs:[{name:target,output:target}]});
await state.submissions.commit({...request,definition:{...base,program:{...base.program,records:base.program.records.map(r=>r.id==='intent:root'?{...r,value:{kind:'inline',value:{name}}}:r)}},
catalog:{source:{path:join(root,'main.svml')},publishedOutputs:[{name:target,ref:{kind:'logical-output',id:target}}]}});
return id;
diff --git a/packages/store-sqlite/test/store.test.ts b/packages/runtime-local/test/sqlite-state.test.ts
similarity index 93%
rename from packages/store-sqlite/test/store.test.ts
rename to packages/runtime-local/test/sqlite-state.test.ts
index 558b29a6..ad216f5a 100644
--- a/packages/store-sqlite/test/store.test.ts
+++ b/packages/runtime-local/test/sqlite-state.test.ts
@@ -3,14 +3,14 @@ import { mkdtemp, rm, stat } from "node:fs/promises";
import { join } from "node:path";
import { tmpdir } from "node:os";
import test from "node:test";
-import { BuildMachine, defineBuild } from "@hypit/core";
-import { SqliteRuntimeState } from "@hypit/store-sqlite";
+import { BuildMachine, defineBuild } from "@hypit/kernel";
+import { SqliteRuntimeState } from "../src/sqlite-state.js";
-import { createGreetingBuild } from "../../core/test/greeting-fixture.js";
+import { createGreetingBuild } from "../../kernel/test/greeting-fixture.js";
const resultLocation = {
root: "/project",
- selection: { use: "@hypit/build-result-fs", config: { path: ".hypit/results" } },
+ path: ".hypit/results",
} as const;
test("local command progress is visible across connections and ends with the command", async () => {
@@ -121,7 +121,7 @@ test("SQLite Operation updates preserve a terminal completion", async () => {
id: "operation:render",
build: "video",
command: "command:render",
- endpoint: "hyperframes.lambda",
+ endpoint: "html.remote",
};
const completed = await state.operations.create({ ...identity,
status: "completed",
@@ -149,7 +149,7 @@ test("Submission is separate from execution and only commit or exact discard rem
await state.builds.create("existing-build", definition(initial));
await assert.rejects(
- state.submissions.prepare({ build: "existing-build", componentPackages: [], result: resultLocation }),
+ state.submissions.prepare({ build: "existing-build", executionPackages: [], result: resultLocation }),
/already has Runtime state/u,
);
await state.submissions.discard("existing-build");
@@ -157,7 +157,7 @@ test("Submission is separate from execution and only commit or exact discard rem
const submission = await state.submissions.prepare({
build: "new-build",
- componentPackages: ["example.component@1"],
+ executionPackages: ["example.component@1"],
result: resultLocation,
}, { now: 100 });
assert.equal(submission.createdAt, 100);
@@ -174,16 +174,10 @@ test("Execution stores scheduling facts, one decision and independent operator a
const directory = await mkdtemp(join(tmpdir(), "hypit-sqlite-result-location-"));
try {
const state = new SqliteRuntimeState(join(directory, "runtime.sqlite"));
- const result = {
- root: "/profiles/team",
- selection: {
- use: "@hypit/build-result-s3",
- config: { bucket: "video-results", prefix: "projects/episode-12" },
- },
- } as const;
+ const result = { root: "/projects/episode-12", path: ".hypit/results" } as const;
const initial = createGreetingBuild();
const buildDefinition = definition(initial);
- const request = { build: "queued-build", componentPackages: ["example.component@1"], result } as const;
+ const request = { build: "queued-build", executionPackages: ["example.component@1"], result } as const;
await state.submissions.prepare(request, { now: 100 });
await state.submissions.commit({
...request,
@@ -226,8 +220,8 @@ test("each execution retains its own context and can be claimed without touching
const directory = await mkdtemp(join(tmpdir(), "hypit-sqlite-context-"));
try {
const state = new SqliteRuntimeState(join(directory, "runtime.sqlite"));
- await state.execution.create({ build: "a", componentPackages: [], result: resultLocation, context: { provider: "old" } }, { now: 100 });
- await state.execution.create({ build: "b", componentPackages: [], result: resultLocation, context: { provider: "new" } }, { now: 100 });
+ await state.execution.create({ build: "a", executionPackages: [], result: resultLocation, context: { provider: "old" } }, { now: 100 });
+ await state.execution.create({ build: "b", executionPackages: [], result: resultLocation, context: { provider: "new" } }, { now: 100 });
await state.execution.start("a", 101);
await assert.rejects(state.execution.start("a", 102), /already started/u);
assert.equal((await state.execution.claim("b-owner", 102, "b"))?.build, "b");
@@ -244,7 +238,7 @@ test("a lost executor ends its attempt while Result-writer leases can be reclaim
const directory = await mkdtemp(join(tmpdir(), "hypit-sqlite-turn-reclaim-"));
try {
const state = new SqliteRuntimeState(join(directory, "runtime.sqlite"));
- await state.execution.create({ build: "interrupted", componentPackages: [], result: resultLocation }, { now: 100 });
+ await state.execution.create({ build: "interrupted", executionPackages: [], result: resultLocation }, { now: 100 });
assert.equal((await state.execution.claim("old-worker", 100))?.turn?.owner, "old-worker");
await state.execution.interrupt("interrupted", "executor lost");
assert.equal((await state.execution.read("interrupted"))?.turn, undefined);
@@ -355,8 +349,8 @@ test("an execution already holding capacity is claimed before fresh work", async
const directory = await mkdtemp(join(tmpdir(), "hypit-capacity-claim-order-"));
const state = new SqliteRuntimeState(join(directory, "runtime.sqlite"));
try {
- await state.execution.create({ build: "fresh", componentPackages: [], result: resultLocation }, { now: 100 });
- await state.execution.create({ build: "in-flight", componentPackages: [], result: resultLocation }, { now: 101 });
+ await state.execution.create({ build: "fresh", executionPackages: [], result: resultLocation }, { now: 100 });
+ await state.execution.create({ build: "in-flight", executionPackages: [], result: resultLocation }, { now: 101 });
assert.equal((await state.execution.acquireCapacity({
build: "in-flight",
command: "remote",
@@ -375,7 +369,7 @@ test("stop requests preserve their first cause and promptly wake the final execu
const directory = await mkdtemp(join(tmpdir(), "hypit-stop-request-"));
const state = new SqliteRuntimeState(join(directory, "runtime.sqlite"));
try {
- await state.execution.create({ build: "stopping", componentPackages: [], result: resultLocation });
+ await state.execution.create({ build: "stopping", executionPackages: [], result: resultLocation });
await state.execution.claim("worker");
const stop = { cause: "execution-failed" as const, reason: "original failure" };
await state.execution.requestStop("stopping", stop);
@@ -414,10 +408,10 @@ test("a resource release before parking is observed and later releases wake a fi
const directory = await mkdtemp(join(tmpdir(), "hypit-capacity-wakeup-"));
const state = new SqliteRuntimeState(join(directory, "runtime.sqlite"));
const resource = { id: "browsers", limit: 2 };
- const destination = { root: directory, selection: { use: "@hypit/build-result-fs" } };
+ const destination = { root: directory, path: "results" };
try {
for (const [now, build] of ["holder", "waiter", "later"].entries()) {
- await state.execution.create({ build, componentPackages: [], result: destination }, { now });
+ await state.execution.create({ build, executionPackages: [], result: destination }, { now });
}
await state.execution.acquireCapacity({ build: "holder", command: "render", resources: [{ ...resource, units: 2 }], now: Date.now() });
assert.equal((await state.execution.claim("owner"))?.build, "holder");
diff --git a/packages/runtime-local/test/startup-failure.test.ts b/packages/runtime-local/test/startup-failure.test.ts
index 305f2d41..5b39331b 100644
--- a/packages/runtime-local/test/startup-failure.test.ts
+++ b/packages/runtime-local/test/startup-failure.test.ts
@@ -5,10 +5,10 @@ import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { setTimeout as pause } from "node:timers/promises";
import test from "node:test";
-import { defineBuild } from "@hypit/core";
-import { FileBuildResultRepository } from "@hypit/build-result";
-import { SqliteRuntimeState } from "@hypit/store-sqlite";
-import { createGreetingBuild } from "../../core/test/greeting-fixture.js";
+import { defineBuild } from "@hypit/kernel";
+import { FileBuildResultRepository } from "@hypit/result/node";
+import { SqliteRuntimeState } from "../src/sqlite-state.js";
+import { createGreetingBuild } from "../../kernel/test/greeting-fixture.js";
import { statePath } from "../src/config.js";
import { superviseBuilds } from "../src/supervisor.js";
@@ -30,13 +30,13 @@ test("an executor that fails before ready records a failed Build and leaves supe
const submit = async (build: string): Promise<void> => {
const request = {
build,
- componentPackages: [],
- result: { root, selection: { use: "@hypit/build-result-fs", config: { path: "results" } } },
+ executionPackages: [],
+ result: { root, path: "results" },
context: { format: "hypit.local-execution@1", packageRoot: root, hostStateRoot: join(root, "host"),
distributionPackageRoot: distribution, profile: profileValue },
};
await state.submissions.prepare(request);
- await result.create({ id: build, source: { path: "main.svml" }, targets: ["document"],
+ await result.create({ id: build, source: { id: "main.svml" }, targets: ["document"],
publishedOutputs: [{ name: "document", output: "document" }] });
await state.submissions.commit({ ...request,
definition: defineBuild({ program: initial.program,
diff --git a/packages/store-sqlite/README.md b/packages/store-sqlite/README.md
deleted file mode 100644
index cb5b0de3..00000000
--- a/packages/store-sqlite/README.md
+++ /dev/null
@@ -1,21 +0,0 @@
-# `@hypit/store-sqlite`
-
-Private durable state used by `@hypit/runtime-local`.
-
-One SQLite file stores Build facts, external Operations, the active Build work set, capacity reservations
-a small output catalog, resource waiters and action rate budgets. No ready-command queue is stored: Core derives ready work from the saved
-Build facts whenever the Worker advances it.
-
-Operation receipts retain task IDs, original Need identity and credential references until the Result
-has recorded them. Unknown remote outcomes do not keep a failed Build active.
-
-Artifact bytes and secret credential values never enter this database. Components and Endpoint packages do not import
-SQLite. `SqliteRuntimeState` exposes the narrow stores needed by the local Runtime and owns their shared
-connection.
-
-Execution choices live in `context_json` on the existing submission/execution records. The store treats
-that value as opaque Host data. `started_at` distinguishes queued work from an executor that was lost.
-`listUnstarted` and `listReady` return only IDs for dispatch, without parsing every Profile or graph.
-Scoped claims and shared capacity updates remain atomic across execution contexts and processes. No global Profile
-pin prevents a new Build from using new selections. An interrupted executor is concluded only after
-its supervisor knows the process has exited; stored Operation receipts are retained for Result writing.
diff --git a/packages/store-sqlite/package.json b/packages/store-sqlite/package.json
deleted file mode 100644
index 88a3377d..00000000
--- a/packages/store-sqlite/package.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "name": "@hypit/store-sqlite",
- "version": "0.0.0-dev",
- "license": "SEE LICENSE IN LICENSE",
- "private": true,
- "type": "module",
- "engines": {
- "node": ">=22.5"
- },
- "exports": {
- ".": "./src/index.ts"
- },
- "dependencies": {
- "@hypit/core": "workspace:*",
- "@hypit/protocol": "workspace:*",
- "@hypit/runtime": "workspace:*"
- }
-}
diff --git a/packages/store-sqlite/src/index.ts b/packages/store-sqlite/src/index.ts
deleted file mode 100644
index b8bf49a2..00000000
--- a/packages/store-sqlite/src/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export { SqliteRuntimeState } from "./store.js";
-export type * from "./store.js";
diff --git a/services/whisperx/package.json b/services/whisperx/package.json
deleted file mode 100644
index 978ba097..00000000
--- a/services/whisperx/package.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "name": "@hypit/whisperx-service-runtime",
- "version": "0.1.0",
- "license": "SEE LICENSE IN LICENSE",
- "type": "module",
- "exports": {
- "./pyproject.toml": "./pyproject.toml"
- },
- "files": [
- "pyproject.toml",
- "uv.lock",
- "src/**/*.py",
- "README.md"
- ]
-}