@jini-ai/node-adapters 0.7.3-next.2 → 0.7.3-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -6
- package/dist/agent-plugins.d.ts +34 -4
- package/dist/agent-plugins.js +5 -4
- package/dist/fs.d.ts +35 -9
- package/dist/fs.js +15 -5
- package/dist/process.d.ts +8 -9
- package/dist/process.js +3 -5
- package/package.json +4 -15
package/README.md
CHANGED
|
@@ -13,19 +13,33 @@ There is no root entry. Import the binding family you need:
|
|
|
13
13
|
|
|
14
14
|
| Entry | Exports | Binds |
|
|
15
15
|
| --- | --- | --- |
|
|
16
|
-
| `@jini-ai/node-adapters/fs` | `
|
|
17
|
-
| `@jini-ai/node-adapters/process` | `
|
|
16
|
+
| `@jini-ai/node-adapters/fs` | `createFileLockPort`, `createAtomicWriterPort` (and the `AtomicWriterFunctions` type) | core's `FileLockPort` and `AtomicFileWriterPort` |
|
|
17
|
+
| `@jini-ai/node-adapters/process` | `createProcessControlPort` (and the `ProcessFunctions` type), `createSpawnPort`, `nodeSpawnPort`, `nodeCommandShell` | core's `ProcessControlPort`, the spawn port, the command planner's inputs |
|
|
18
|
+
| `@jini-ai/node-adapters/agent-plugins` | `createNodeAgentPluginEffects` (and the `AgentPluginPlatformFunctions` type) | the agent-plugin lifecycle's native effects |
|
|
18
19
|
|
|
19
|
-
`createProcessControlPort({ functions })` takes the three platform process functions
|
|
20
|
-
|
|
20
|
+
`createProcessControlPort({ functions })` takes the three platform process functions injected (the host
|
|
21
|
+
passes `@jini-ai/platform/process`'s; this package imports no other package's implementation), and a
|
|
22
|
+
test passes recording fakes: two port members take their arguments in a different shape from the
|
|
21
23
|
function they wrap (`{ pids }` vs a positional array, `{ pid }` vs a positional pid).
|
|
22
24
|
|
|
23
25
|
## Rules this package obeys (enforced by `pnpm guard`)
|
|
24
26
|
|
|
25
|
-
- Imports only `@jini-ai/core
|
|
26
|
-
types (type-only, declared as a peer) but
|
|
27
|
+
- Imports only `@jini-ai/core` (contracts) and Node built-ins; every platform function it binds arrives
|
|
28
|
+
injected from the host (K5). It may name a domain's port types (type-only, declared as a peer) but
|
|
29
|
+
never runs a domain's code.
|
|
27
30
|
- Only a host or a host preset imports it; it never imports a host preset.
|
|
28
31
|
- No root barrel; each later binding family (agent plugins, http, agent runtime) adds its own entry,
|
|
29
32
|
source file and test in its own commit.
|
|
30
33
|
- The vendor binding `node-pty` stays in `@jini-ai/server`: moving it here would give every importer a
|
|
31
34
|
native build.
|
|
35
|
+
|
|
36
|
+
## Wiring
|
|
37
|
+
|
|
38
|
+
- `@jini-ai/node-adapters/process`: a host building its own agent-executor runtime passes
|
|
39
|
+
`@jini-ai/platform/process`'s three functions to `createProcessControlPort({ functions })`.
|
|
40
|
+
- `@jini-ai/node-adapters/fs`: the host passes `@jini-ai/platform/fs`'s `withFileLock` to
|
|
41
|
+
`createFileLockPort` and `writeFileAtomicAsync`, `writeJsonFileAtomicAsync`, `backupOriginalOnce` to
|
|
42
|
+
`createAtomicWriterPort`; each builder returns the injected functions under the port's names.
|
|
43
|
+
- No ready-made constant binds a platform implementation here: `@jini-ai/server`'s presets take the
|
|
44
|
+
three bound ports as the required `osPorts` (see that package's Wiring).
|
|
45
|
+
- `@jini-ai/node-adapters/agent-plugins`: the host passes `{ withFileLock, writeJsonFileAtomicAsync, readBootIdentity }`.
|
package/dist/agent-plugins.d.ts
CHANGED
|
@@ -1,9 +1,39 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
1
|
+
import * as nativeFilesystem from 'node:fs/promises';
|
|
2
|
+
import type { AtomicFileWriterPort, BootIdentity, FileLockPort } from '@jini-ai/core/contracts/runtime';
|
|
3
|
+
import type { Clock, IdGenerator } from '@jini-ai/core/primitives';
|
|
4
|
+
export type FilesystemPort = Pick<typeof nativeFilesystem, 'chmod' | 'mkdir' | 'mkdtemp' | 'open' | 'readdir' | 'readFile' | 'rename' | 'rm' | 'rmdir' | 'stat' | 'lstat' | 'realpath' | 'unlink'>;
|
|
5
|
+
export type AgentPluginClockPort = Clock & {
|
|
6
|
+
monotonicMs(): number;
|
|
7
|
+
sleep(required: {
|
|
8
|
+
readonly ms: number;
|
|
9
|
+
}): Promise<void>;
|
|
10
|
+
sleepInBackground?(required: {
|
|
11
|
+
readonly ms: number;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
};
|
|
14
|
+
export type AgentPluginIdsPort = IdGenerator & {
|
|
15
|
+
random(): number;
|
|
16
|
+
};
|
|
17
|
+
export interface AgentPluginProcessPort {
|
|
18
|
+
readonly pid: number;
|
|
19
|
+
readonly platform: NodeJS.Platform;
|
|
20
|
+
hostname(required: Record<string, never>): string;
|
|
21
|
+
isAlive(required: {
|
|
22
|
+
readonly pid: number;
|
|
23
|
+
}): boolean;
|
|
24
|
+
bootIdentity?(): BootIdentity | undefined;
|
|
25
|
+
}
|
|
26
|
+
/** The platform functions the effects bind; a Node host passes `@jini-ai/platform/fs`'s
|
|
27
|
+
* `withFileLock`, `writeJsonFileAtomicAsync` and `readBootIdentity`. */
|
|
28
|
+
export interface AgentPluginPlatformFunctions {
|
|
29
|
+
readonly withFileLock: FileLockPort<FilesystemPort>['withFileLock'];
|
|
30
|
+
readonly writeJsonFileAtomicAsync: AtomicFileWriterPort<FilesystemPort>['writeJson'];
|
|
31
|
+
readonly readBootIdentity: (required: Record<string, never>) => BootIdentity | undefined;
|
|
32
|
+
}
|
|
3
33
|
/** Opt-in native effects. Layout, fetch, guard, namespace and provisioning remain host-owned.
|
|
4
|
-
* `fileLock` and `atomicWriter` are platform
|
|
34
|
+
* `fileLock` and `atomicWriter` are the injected platform functions, which accept the lifecycle's
|
|
5
35
|
* `filesystem` option (the `FileLockPort<never>` of `@jini-ai/node-adapters/fs` would refuse it). */
|
|
6
|
-
export declare function createNodeAgentPluginEffects(
|
|
36
|
+
export declare function createNodeAgentPluginEffects(required: AgentPluginPlatformFunctions, optional?: {
|
|
7
37
|
readonly filesystem?: FilesystemPort;
|
|
8
38
|
}): {
|
|
9
39
|
filesystem: FilesystemPort;
|
package/dist/agent-plugins.js
CHANGED
|
@@ -3,14 +3,13 @@ import { randomInt, randomUUID } from 'node:crypto';
|
|
|
3
3
|
import os from 'node:os';
|
|
4
4
|
import { performance } from 'node:perf_hooks';
|
|
5
5
|
import { setTimeout } from 'node:timers/promises';
|
|
6
|
-
import { writeJsonFileAtomicAsync } from '@jini-ai/platform/fs';
|
|
7
|
-
import { readBootIdentity, withFileLock } from '@jini-ai/platform/fs/file-lock';
|
|
8
6
|
/** Granularity of the uniform [0, 1) value: crypto.randomInt's largest exclusive bound (2^48 - 1). */
|
|
9
7
|
const RANDOM_RESOLUTION = 2 ** 48 - 1;
|
|
10
8
|
/** Opt-in native effects. Layout, fetch, guard, namespace and provisioning remain host-owned.
|
|
11
|
-
* `fileLock` and `atomicWriter` are platform
|
|
9
|
+
* `fileLock` and `atomicWriter` are the injected platform functions, which accept the lifecycle's
|
|
12
10
|
* `filesystem` option (the `FileLockPort<never>` of `@jini-ai/node-adapters/fs` would refuse it). */
|
|
13
|
-
export function createNodeAgentPluginEffects(
|
|
11
|
+
export function createNodeAgentPluginEffects(required, optional = {}) {
|
|
12
|
+
const { withFileLock, writeJsonFileAtomicAsync, readBootIdentity } = required;
|
|
14
13
|
return {
|
|
15
14
|
filesystem: optional.filesystem ?? nativeFilesystem,
|
|
16
15
|
fileLock: { withFileLock },
|
|
@@ -19,6 +18,8 @@ export function createNodeAgentPluginEffects(_required, optional = {}) {
|
|
|
19
18
|
nowMs: () => Date.now(),
|
|
20
19
|
monotonicMs: () => performance.now(),
|
|
21
20
|
sleep: ({ ms }) => setTimeout(ms),
|
|
21
|
+
// Background recovery retries must not keep the process alive (a referenced timer would hold exit for up to 10 minutes).
|
|
22
|
+
sleepInBackground: ({ ms }) => setTimeout(ms, undefined, { ref: false }),
|
|
22
23
|
},
|
|
23
24
|
ids: { newId: () => randomUUID(), random: () => randomInt(RANDOM_RESOLUTION) / RANDOM_RESOLUTION },
|
|
24
25
|
process: {
|
package/dist/fs.d.ts
CHANGED
|
@@ -1,12 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module fs
|
|
3
|
+
*
|
|
4
|
+
* Node bindings of core's `FileLockPort` and `AtomicFileWriterPort` over `@jini-ai/platform`'s own
|
|
5
|
+
* functions, which the host passes in (this package imports no other package's implementation). Every
|
|
6
|
+
* member has the port's shape already (`writeText` is `writeFileAtomicAsync` under the port's name), so
|
|
7
|
+
* this is a naming map, not an adapter; the `extends` bounds are what fail when either side changes,
|
|
8
|
+
* and each builder returns the functions it was handed with their own (wider) types intact. The process
|
|
9
|
+
* binding lives in `@jini-ai/node-adapters/process` (separate entry: subpath isolation keeps the `fs`
|
|
10
|
+
* and `os` domains apart).
|
|
11
|
+
*/
|
|
12
|
+
import type { AtomicFileWriterPort, FileLockPort } from "@jini-ai/core/contracts/runtime";
|
|
13
|
+
/**
|
|
14
|
+
* The Node lock port over the host's `withFileLock` (a Node host passes `@jini-ai/platform/fs`'s).
|
|
15
|
+
* @complexity O(1).
|
|
16
|
+
*/
|
|
17
|
+
export declare function createFileLockPort<Lock extends FileLockPort["withFileLock"]>(required: {
|
|
18
|
+
readonly withFileLock: Lock;
|
|
19
|
+
}, _optional?: Record<string, never>): {
|
|
20
|
+
readonly withFileLock: Lock;
|
|
5
21
|
};
|
|
6
|
-
/** The
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
backupOriginalOnce:
|
|
22
|
+
/** The platform file functions the atomic-writer port renames; a Node host passes `@jini-ai/platform/fs`'s. */
|
|
23
|
+
export interface AtomicWriterFunctions<Text extends AtomicFileWriterPort["writeText"], Json extends AtomicFileWriterPort["writeJson"]> {
|
|
24
|
+
readonly writeFileAtomicAsync: Text;
|
|
25
|
+
readonly writeJsonFileAtomicAsync: Json;
|
|
26
|
+
readonly backupOriginalOnce: AtomicFileWriterPort["backupOriginalOnce"];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The Node atomic-writer port: `writeFileAtomicAsync` under the port's `writeText`, `writeJsonFileAtomicAsync`
|
|
30
|
+
* under `writeJson`, `backupOriginalOnce` as is.
|
|
31
|
+
* @complexity O(1).
|
|
32
|
+
*/
|
|
33
|
+
export declare function createAtomicWriterPort<Text extends AtomicFileWriterPort["writeText"], Json extends AtomicFileWriterPort["writeJson"]>(required: AtomicWriterFunctions<Text, Json>, _optional?: Record<string, never>): {
|
|
34
|
+
readonly writeText: Text;
|
|
35
|
+
readonly writeJson: Json;
|
|
36
|
+
readonly backupOriginalOnce: AtomicFileWriterPort["backupOriginalOnce"];
|
|
11
37
|
};
|
|
12
38
|
//# sourceMappingURL=fs.d.ts.map
|
package/dist/fs.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
1
|
+
/**
|
|
2
|
+
* The Node lock port over the host's `withFileLock` (a Node host passes `@jini-ai/platform/fs`'s).
|
|
3
|
+
* @complexity O(1).
|
|
4
|
+
*/
|
|
5
|
+
export function createFileLockPort(required, _optional = {}) {
|
|
6
|
+
return { withFileLock: required.withFileLock };
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The Node atomic-writer port: `writeFileAtomicAsync` under the port's `writeText`, `writeJsonFileAtomicAsync`
|
|
10
|
+
* under `writeJson`, `backupOriginalOnce` as is.
|
|
11
|
+
* @complexity O(1).
|
|
12
|
+
*/
|
|
13
|
+
export function createAtomicWriterPort(required, _optional = {}) {
|
|
14
|
+
return { writeText: required.writeFileAtomicAsync, writeJson: required.writeJsonFileAtomicAsync, backupOriginalOnce: required.backupOriginalOnce };
|
|
15
|
+
}
|
|
6
16
|
//# sourceMappingURL=fs.js.map
|
package/dist/process.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module process
|
|
3
3
|
*
|
|
4
|
-
* Node binding of core's `ProcessControlPort` over `@jini-ai/platform`'s process functions. Hosts
|
|
5
|
-
* {@link
|
|
4
|
+
* Node binding of core's `ProcessControlPort` over `@jini-ai/platform`'s process functions. Hosts call
|
|
5
|
+
* {@link createProcessControlPort} with those functions (this package imports no other package's
|
|
6
|
+
* implementation) instead of hand-copying the adapter: two of the port members take their
|
|
6
7
|
* arguments in a different shape from the function they wrap (`{ pids }` vs a positional array,
|
|
7
8
|
* `{ pid }` vs a positional pid), so a binding that merely typechecks can silently reshape an
|
|
8
9
|
* argument. The builder takes the wrapped functions as arguments so a test can hand it recording
|
|
@@ -14,15 +15,15 @@
|
|
|
14
15
|
*/
|
|
15
16
|
import { type ChildProcess, type SpawnOptions } from "node:child_process";
|
|
16
17
|
import type { ProcessControlPort, RuntimePlatform } from "@jini-ai/core/contracts/runtime";
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
/** The three platform process functions the process-control port wraps; a Node host passes
|
|
19
|
+
* `@jini-ai/platform/process`'s `listProcessSnapshots`, `stopProcesses` and `waitForProcessExit`. */
|
|
19
20
|
export interface ProcessFunctions {
|
|
20
21
|
readonly listProcessSnapshots: (required: Record<string, never>, optional: {
|
|
21
22
|
timeoutMs?: number;
|
|
22
23
|
commandLines?: boolean;
|
|
23
|
-
}) => ReturnType<
|
|
24
|
-
readonly stopProcesses: (pids: Array<number | null | undefined>) => ReturnType<
|
|
25
|
-
readonly waitForProcessExit: (pid: number | null | undefined, timeoutMs?: number) => ReturnType<
|
|
24
|
+
}) => ReturnType<ProcessControlPort["listProcessSnapshots"]>;
|
|
25
|
+
readonly stopProcesses: (pids: Array<number | null | undefined>) => ReturnType<ProcessControlPort["stopProcesses"]>;
|
|
26
|
+
readonly waitForProcessExit: (pid: number | null | undefined, timeoutMs?: number) => ReturnType<ProcessControlPort["waitForProcessExit"]>;
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
28
29
|
* Adapts positional platform process functions to {@link ProcessControlPort}.
|
|
@@ -33,8 +34,6 @@ export interface ProcessFunctions {
|
|
|
33
34
|
export declare function createProcessControlPort(required: {
|
|
34
35
|
readonly functions: ProcessFunctions;
|
|
35
36
|
}, _optional?: Record<string, never>): ProcessControlPort;
|
|
36
|
-
/** The Node implementation, ready for a host to hand to daemon. */
|
|
37
|
-
export declare const nodeProcessControl: ProcessControlPort;
|
|
38
37
|
/** The one `node:child_process` function the spawn port wraps. */
|
|
39
38
|
export type SpawnFunction = (command: string, args: string[], options: SpawnOptions) => ChildProcess;
|
|
40
39
|
/**
|
package/dist/process.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module process
|
|
3
3
|
*
|
|
4
|
-
* Node binding of core's `ProcessControlPort` over `@jini-ai/platform`'s process functions. Hosts
|
|
5
|
-
* {@link
|
|
4
|
+
* Node binding of core's `ProcessControlPort` over `@jini-ai/platform`'s process functions. Hosts call
|
|
5
|
+
* {@link createProcessControlPort} with those functions (this package imports no other package's
|
|
6
|
+
* implementation) instead of hand-copying the adapter: two of the port members take their
|
|
6
7
|
* arguments in a different shape from the function they wrap (`{ pids }` vs a positional array,
|
|
7
8
|
* `{ pid }` vs a positional pid), so a binding that merely typechecks can silently reshape an
|
|
8
9
|
* argument. The builder takes the wrapped functions as arguments so a test can hand it recording
|
|
@@ -13,7 +14,6 @@
|
|
|
13
14
|
* come from {@link nodeCommandShell}; process start comes from {@link nodeSpawnPort}.
|
|
14
15
|
*/
|
|
15
16
|
import { spawn } from "node:child_process";
|
|
16
|
-
import { listProcessSnapshots, stopProcesses, waitForProcessExit } from "@jini-ai/platform/process";
|
|
17
17
|
/**
|
|
18
18
|
* Adapts positional platform process functions to {@link ProcessControlPort}.
|
|
19
19
|
* `stopProcesses` receives a new mutable copy of the port's readonly array; an absent
|
|
@@ -28,8 +28,6 @@ export function createProcessControlPort(required, _optional = {}) {
|
|
|
28
28
|
waitForProcessExit: ({ pid }, { timeoutMs } = {}) => functions.waitForProcessExit(pid, timeoutMs),
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
-
/** The Node implementation, ready for a host to hand to daemon. */
|
|
32
|
-
export const nodeProcessControl = createProcessControlPort({ functions: { listProcessSnapshots, stopProcesses, waitForProcessExit } });
|
|
33
31
|
/**
|
|
34
32
|
* Adapts Node's positional `spawn(command, args, options)` to the object-argument spawn port. Returns the
|
|
35
33
|
* child in the same synchronous turn it was spawned: the caller attaches its `'error'` listeners before
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/node-adapters",
|
|
3
|
-
"version": "0.7.3-next.
|
|
3
|
+
"version": "0.7.3-next.3",
|
|
4
4
|
"description": "Node bindings of the engine's runtime ports (file lock, atomic file writer, process control) over @jini-ai/platform functions. Bindings only: assembles nothing.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -16,9 +16,6 @@
|
|
|
16
16
|
"./fs": "node",
|
|
17
17
|
"./process": "node",
|
|
18
18
|
"./agent-plugins": "node"
|
|
19
|
-
},
|
|
20
|
-
"optionalPeers": {
|
|
21
|
-
"@jini-ai/agent-plugins": "opt-in: agent plugin lifecycle effects; import @jini-ai/node-adapters/agent-plugins — Agent plugin lifecycle effects name the port types of @jini-ai/agent-plugins. Install @jini-ai/agent-plugins to enable this feature, or check its installed version."
|
|
22
19
|
}
|
|
23
20
|
},
|
|
24
21
|
"type": "module",
|
|
@@ -53,16 +50,8 @@
|
|
|
53
50
|
"!dist/**/*.map"
|
|
54
51
|
],
|
|
55
52
|
"dependencies": {
|
|
56
|
-
"@jini-ai/
|
|
57
|
-
"@jini-ai/
|
|
58
|
-
},
|
|
59
|
-
"peerDependencies": {
|
|
60
|
-
"@jini-ai/agent-plugins": "^0.7.3-next.2"
|
|
61
|
-
},
|
|
62
|
-
"peerDependenciesMeta": {
|
|
63
|
-
"@jini-ai/agent-plugins": {
|
|
64
|
-
"optional": true
|
|
65
|
-
}
|
|
53
|
+
"@jini-ai/platform": "^0.7.3-next.3",
|
|
54
|
+
"@jini-ai/core": "^0.7.3-next.3"
|
|
66
55
|
},
|
|
67
56
|
"publishConfig": {
|
|
68
57
|
"access": "public",
|
|
@@ -70,7 +59,7 @@
|
|
|
70
59
|
},
|
|
71
60
|
"devDependencies": {
|
|
72
61
|
"@vitest/coverage-v8": "^3.2.6",
|
|
73
|
-
"@jini-ai/agent-plugins": "^0.7.3-next.
|
|
62
|
+
"@jini-ai/agent-plugins": "^0.7.3-next.3"
|
|
74
63
|
},
|
|
75
64
|
"scripts": {
|
|
76
65
|
"build": "tsc -p tsconfig.json",
|