@jini-ai/node-adapters 0.0.0-stage → 0.7.3-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +30 -2
- package/dist/agent-plugins.d.ts +16 -0
- package/dist/agent-plugins.js +43 -0
- package/dist/fs.d.ts +12 -0
- package/dist/fs.js +6 -0
- package/dist/process.d.ts +71 -0
- package/dist/process.js +54 -0
- package/package.json +78 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Open Design contributors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@jini-ai/node-adapters`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Node bindings of the engine's runtime ports over [`@jini-ai/platform`](../platform) functions
|
|
4
|
+
(owner decision OD-3, package kind `runtime-adapter`). Exports bindings only and assembles nothing:
|
|
5
|
+
a host, or a host preset such as `@jini-ai/server`, imports a binding and hands it to the domain that
|
|
6
|
+
declares the port.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm install @jini-ai/node-adapters
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
There is no root entry. Import the binding family you need:
|
|
13
|
+
|
|
14
|
+
| Entry | Exports | Binds |
|
|
15
|
+
| --- | --- | --- |
|
|
16
|
+
| `@jini-ai/node-adapters/fs` | `nodeFileLock`, `nodeAtomicWriter` | core's `FileLockPort` and `AtomicFileWriterPort` |
|
|
17
|
+
| `@jini-ai/node-adapters/process` | `nodeProcessControl`, `createProcessControlPort` (and the `ProcessFunctions` type) | core's `ProcessControlPort` |
|
|
18
|
+
|
|
19
|
+
`createProcessControlPort({ functions })` takes the three platform process functions as arguments so a
|
|
20
|
+
test can pass recording fakes: two port members take their arguments in a different shape from the
|
|
21
|
+
function they wrap (`{ pids }` vs a positional array, `{ pid }` vs a positional pid).
|
|
22
|
+
|
|
23
|
+
## Rules this package obeys (enforced by `pnpm guard`)
|
|
24
|
+
|
|
25
|
+
- Imports only `@jini-ai/core`, `@jini-ai/protocol` and `@jini-ai/platform`; it may name a domain's port
|
|
26
|
+
types (type-only, declared as a peer) but never runs a domain's code.
|
|
27
|
+
- Only a host or a host preset imports it; it never imports a host preset.
|
|
28
|
+
- No root barrel; each later binding family (agent plugins, http, agent runtime) adds its own entry,
|
|
29
|
+
source file and test in its own commit.
|
|
30
|
+
- The vendor binding `node-pty` stays in `@jini-ai/server`: moving it here would give every importer a
|
|
31
|
+
native build.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AtomicFileWriterPort, FileLockPort } from '@jini-ai/core/contracts/runtime';
|
|
2
|
+
import type { AgentPluginClockPort, AgentPluginIdsPort, AgentPluginProcessPort, FilesystemPort } from '@jini-ai/agent-plugins/lifecycle';
|
|
3
|
+
/** Opt-in native effects. Layout, fetch, guard, namespace and provisioning remain host-owned.
|
|
4
|
+
* `fileLock` and `atomicWriter` are platform's own functions, which accept the lifecycle's
|
|
5
|
+
* `filesystem` option (the `FileLockPort<never>` of `@jini-ai/node-adapters/fs` would refuse it). */
|
|
6
|
+
export declare function createNodeAgentPluginEffects(_required: Record<string, never>, optional?: {
|
|
7
|
+
readonly filesystem?: FilesystemPort;
|
|
8
|
+
}): {
|
|
9
|
+
filesystem: FilesystemPort;
|
|
10
|
+
fileLock: FileLockPort<FilesystemPort>;
|
|
11
|
+
atomicWriter: Pick<AtomicFileWriterPort<FilesystemPort>, 'writeJson'>;
|
|
12
|
+
clock: AgentPluginClockPort;
|
|
13
|
+
ids: AgentPluginIdsPort;
|
|
14
|
+
process: AgentPluginProcessPort;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=agent-plugins.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as nativeFilesystem from 'node:fs/promises';
|
|
2
|
+
import { randomInt, randomUUID } from 'node:crypto';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import { performance } from 'node:perf_hooks';
|
|
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
|
+
/** Granularity of the uniform [0, 1) value: crypto.randomInt's largest exclusive bound (2^48 - 1). */
|
|
9
|
+
const RANDOM_RESOLUTION = 2 ** 48 - 1;
|
|
10
|
+
/** Opt-in native effects. Layout, fetch, guard, namespace and provisioning remain host-owned.
|
|
11
|
+
* `fileLock` and `atomicWriter` are platform's own functions, which accept the lifecycle's
|
|
12
|
+
* `filesystem` option (the `FileLockPort<never>` of `@jini-ai/node-adapters/fs` would refuse it). */
|
|
13
|
+
export function createNodeAgentPluginEffects(_required, optional = {}) {
|
|
14
|
+
return {
|
|
15
|
+
filesystem: optional.filesystem ?? nativeFilesystem,
|
|
16
|
+
fileLock: { withFileLock },
|
|
17
|
+
atomicWriter: { writeJson: writeJsonFileAtomicAsync },
|
|
18
|
+
clock: {
|
|
19
|
+
nowMs: () => Date.now(),
|
|
20
|
+
monotonicMs: () => performance.now(),
|
|
21
|
+
sleep: ({ ms }) => setTimeout(ms),
|
|
22
|
+
},
|
|
23
|
+
ids: { newId: () => randomUUID(), random: () => randomInt(RANDOM_RESOLUTION) / RANDOM_RESOLUTION },
|
|
24
|
+
process: {
|
|
25
|
+
pid: process.pid,
|
|
26
|
+
platform: process.platform,
|
|
27
|
+
hostname: () => os.hostname(),
|
|
28
|
+
bootIdentity: () => readBootIdentity({}),
|
|
29
|
+
isAlive: ({ pid }) => {
|
|
30
|
+
if (!Number.isSafeInteger(pid) || pid <= 0)
|
|
31
|
+
return false;
|
|
32
|
+
try {
|
|
33
|
+
process.kill(pid, 0);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
return !(typeof error === 'object' && error !== null && 'code' in error && error.code === 'ESRCH');
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=agent-plugins.js.map
|
package/dist/fs.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { backupOriginalOnce, writeFileAtomicAsync, writeJsonFileAtomicAsync, withFileLock } from "@jini-ai/platform/fs";
|
|
2
|
+
/** The Node implementation of the lock port. */
|
|
3
|
+
export declare const nodeFileLock: {
|
|
4
|
+
withFileLock: typeof withFileLock;
|
|
5
|
+
};
|
|
6
|
+
/** The Node implementation of the atomic-writer port. */
|
|
7
|
+
export declare const nodeAtomicWriter: {
|
|
8
|
+
writeText: typeof writeFileAtomicAsync;
|
|
9
|
+
writeJson: typeof writeJsonFileAtomicAsync;
|
|
10
|
+
backupOriginalOnce: typeof backupOriginalOnce;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=fs.d.ts.map
|
package/dist/fs.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { backupOriginalOnce, writeFileAtomicAsync, writeJsonFileAtomicAsync, withFileLock } from "@jini-ai/platform/fs";
|
|
2
|
+
/** The Node implementation of the lock port. */
|
|
3
|
+
export const nodeFileLock = { withFileLock };
|
|
4
|
+
/** The Node implementation of the atomic-writer port. */
|
|
5
|
+
export const nodeAtomicWriter = { writeText: writeFileAtomicAsync, writeJson: writeJsonFileAtomicAsync, backupOriginalOnce };
|
|
6
|
+
//# sourceMappingURL=fs.js.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module process
|
|
3
|
+
*
|
|
4
|
+
* Node binding of core's `ProcessControlPort` over `@jini-ai/platform`'s process functions. Hosts import
|
|
5
|
+
* {@link nodeProcessControl} instead of hand-copying the adapter: two of the port members take their
|
|
6
|
+
* arguments in a different shape from the function they wrap (`{ pids }` vs a positional array,
|
|
7
|
+
* `{ pid }` vs a positional pid), so a binding that merely typechecks can silently reshape an
|
|
8
|
+
* argument. The builder takes the wrapped functions as arguments so a test can hand it recording
|
|
9
|
+
* fakes and assert exactly what each receives. The file lock and atomic writer bind in
|
|
10
|
+
* `@jini-ai/node-adapters/fs` (a separate entry: subpath isolation keeps the `os` and `fs` domains apart).
|
|
11
|
+
* `command` has no binding on purpose: core's pure `planCommandInvocation` is the planner, and
|
|
12
|
+
* `createCommandInvocation` reads its arguments from the other object. The planner's two host inputs
|
|
13
|
+
* come from {@link nodeCommandShell}; process start comes from {@link nodeSpawnPort}.
|
|
14
|
+
*/
|
|
15
|
+
import { type ChildProcess, type SpawnOptions } from "node:child_process";
|
|
16
|
+
import type { ProcessControlPort, RuntimePlatform } from "@jini-ai/core/contracts/runtime";
|
|
17
|
+
import { listProcessSnapshots, stopProcesses, waitForProcessExit } from "@jini-ai/platform/process";
|
|
18
|
+
/** The three platform process functions the process-control port wraps. */
|
|
19
|
+
export interface ProcessFunctions {
|
|
20
|
+
readonly listProcessSnapshots: (required: Record<string, never>, optional: {
|
|
21
|
+
timeoutMs?: number;
|
|
22
|
+
commandLines?: boolean;
|
|
23
|
+
}) => ReturnType<typeof listProcessSnapshots>;
|
|
24
|
+
readonly stopProcesses: (pids: Array<number | null | undefined>) => ReturnType<typeof stopProcesses>;
|
|
25
|
+
readonly waitForProcessExit: (pid: number | null | undefined, timeoutMs?: number) => ReturnType<typeof waitForProcessExit>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Adapts positional platform process functions to {@link ProcessControlPort}.
|
|
29
|
+
* `stopProcesses` receives a new mutable copy of the port's readonly array; an absent
|
|
30
|
+
* `timeoutMs` reaches `waitForProcessExit` as `undefined` so its own default applies.
|
|
31
|
+
* @complexity O(1) construction; each member costs what the wrapped function costs.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createProcessControlPort(required: {
|
|
34
|
+
readonly functions: ProcessFunctions;
|
|
35
|
+
}, _optional?: Record<string, never>): ProcessControlPort;
|
|
36
|
+
/** The Node implementation, ready for a host to hand to daemon. */
|
|
37
|
+
export declare const nodeProcessControl: ProcessControlPort;
|
|
38
|
+
/** The one `node:child_process` function the spawn port wraps. */
|
|
39
|
+
export type SpawnFunction = (command: string, args: string[], options: SpawnOptions) => ChildProcess;
|
|
40
|
+
/**
|
|
41
|
+
* Adapts Node's positional `spawn(command, args, options)` to the object-argument spawn port. Returns the
|
|
42
|
+
* child in the same synchronous turn it was spawned: the caller attaches its `'error'` listeners before
|
|
43
|
+
* yielding, and an `async` adapter here would let the child's first event fire with nobody listening.
|
|
44
|
+
* The args reach `spawn` as a new mutable array (the port's array is readonly); an absent `options` is `{}`.
|
|
45
|
+
* @complexity O(a) in the argument count for the copy; otherwise what `spawn` costs.
|
|
46
|
+
*/
|
|
47
|
+
export declare function createSpawnPort(required: {
|
|
48
|
+
readonly spawn: SpawnFunction;
|
|
49
|
+
}, _optional?: Record<string, never>): ({ command, args }: {
|
|
50
|
+
readonly command: string;
|
|
51
|
+
readonly args: readonly string[];
|
|
52
|
+
}, options?: SpawnOptions) => ChildProcess;
|
|
53
|
+
/** The Node implementation of the spawn port, ready for a host to hand to daemon. */
|
|
54
|
+
export declare const nodeSpawnPort: ({ command, args }: {
|
|
55
|
+
readonly command: string;
|
|
56
|
+
readonly args: readonly string[];
|
|
57
|
+
}, options?: SpawnOptions) => ChildProcess;
|
|
58
|
+
/**
|
|
59
|
+
* The two host inputs of core's pure `planCommandInvocation`: the platform and the `ComSpec` a Windows
|
|
60
|
+
* `.cmd` shim falls back to when the child's own env has none. The host passes the env it already owns
|
|
61
|
+
* (this module never reads the ambient process env); the platform defaults to the running one.
|
|
62
|
+
*/
|
|
63
|
+
export declare function nodeCommandShell({ env }: {
|
|
64
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
65
|
+
}, { platform }?: {
|
|
66
|
+
readonly platform?: RuntimePlatform;
|
|
67
|
+
}): {
|
|
68
|
+
readonly platform: RuntimePlatform;
|
|
69
|
+
readonly fallbackComSpec: string | undefined;
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=process.d.ts.map
|
package/dist/process.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module process
|
|
3
|
+
*
|
|
4
|
+
* Node binding of core's `ProcessControlPort` over `@jini-ai/platform`'s process functions. Hosts import
|
|
5
|
+
* {@link nodeProcessControl} instead of hand-copying the adapter: two of the port members take their
|
|
6
|
+
* arguments in a different shape from the function they wrap (`{ pids }` vs a positional array,
|
|
7
|
+
* `{ pid }` vs a positional pid), so a binding that merely typechecks can silently reshape an
|
|
8
|
+
* argument. The builder takes the wrapped functions as arguments so a test can hand it recording
|
|
9
|
+
* fakes and assert exactly what each receives. The file lock and atomic writer bind in
|
|
10
|
+
* `@jini-ai/node-adapters/fs` (a separate entry: subpath isolation keeps the `os` and `fs` domains apart).
|
|
11
|
+
* `command` has no binding on purpose: core's pure `planCommandInvocation` is the planner, and
|
|
12
|
+
* `createCommandInvocation` reads its arguments from the other object. The planner's two host inputs
|
|
13
|
+
* come from {@link nodeCommandShell}; process start comes from {@link nodeSpawnPort}.
|
|
14
|
+
*/
|
|
15
|
+
import { spawn } from "node:child_process";
|
|
16
|
+
import { listProcessSnapshots, stopProcesses, waitForProcessExit } from "@jini-ai/platform/process";
|
|
17
|
+
/**
|
|
18
|
+
* Adapts positional platform process functions to {@link ProcessControlPort}.
|
|
19
|
+
* `stopProcesses` receives a new mutable copy of the port's readonly array; an absent
|
|
20
|
+
* `timeoutMs` reaches `waitForProcessExit` as `undefined` so its own default applies.
|
|
21
|
+
* @complexity O(1) construction; each member costs what the wrapped function costs.
|
|
22
|
+
*/
|
|
23
|
+
export function createProcessControlPort(required, _optional = {}) {
|
|
24
|
+
const { functions } = required;
|
|
25
|
+
return {
|
|
26
|
+
listProcessSnapshots: (_required = {}, optional = {}) => functions.listProcessSnapshots({}, optional),
|
|
27
|
+
stopProcesses: ({ pids }) => functions.stopProcesses([...pids]),
|
|
28
|
+
waitForProcessExit: ({ pid }, { timeoutMs } = {}) => functions.waitForProcessExit(pid, timeoutMs),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** The Node implementation, ready for a host to hand to daemon. */
|
|
32
|
+
export const nodeProcessControl = createProcessControlPort({ functions: { listProcessSnapshots, stopProcesses, waitForProcessExit } });
|
|
33
|
+
/**
|
|
34
|
+
* Adapts Node's positional `spawn(command, args, options)` to the object-argument spawn port. Returns the
|
|
35
|
+
* child in the same synchronous turn it was spawned: the caller attaches its `'error'` listeners before
|
|
36
|
+
* yielding, and an `async` adapter here would let the child's first event fire with nobody listening.
|
|
37
|
+
* The args reach `spawn` as a new mutable array (the port's array is readonly); an absent `options` is `{}`.
|
|
38
|
+
* @complexity O(a) in the argument count for the copy; otherwise what `spawn` costs.
|
|
39
|
+
*/
|
|
40
|
+
export function createSpawnPort(required, _optional = {}) {
|
|
41
|
+
const { spawn: spawnFunction } = required;
|
|
42
|
+
return ({ command, args }, options = {}) => spawnFunction(command, [...args], options);
|
|
43
|
+
}
|
|
44
|
+
/** The Node implementation of the spawn port, ready for a host to hand to daemon. */
|
|
45
|
+
export const nodeSpawnPort = createSpawnPort({ spawn });
|
|
46
|
+
/**
|
|
47
|
+
* The two host inputs of core's pure `planCommandInvocation`: the platform and the `ComSpec` a Windows
|
|
48
|
+
* `.cmd` shim falls back to when the child's own env has none. The host passes the env it already owns
|
|
49
|
+
* (this module never reads the ambient process env); the platform defaults to the running one.
|
|
50
|
+
*/
|
|
51
|
+
export function nodeCommandShell({ env }, { platform = process.platform } = {}) {
|
|
52
|
+
return { platform, fallbackComSpec: env.ComSpec };
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=process.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,81 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/node-adapters",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.7.3-next.1",
|
|
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
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/AINSEP/Jini.git",
|
|
9
|
+
"directory": "packages/node-adapters"
|
|
10
|
+
},
|
|
11
|
+
"jini": {
|
|
12
|
+
"domain": "platform",
|
|
13
|
+
"kind": "runtime-adapter",
|
|
14
|
+
"runtime": "node",
|
|
15
|
+
"entries": {
|
|
16
|
+
"./fs": "node",
|
|
17
|
+
"./process": "node",
|
|
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
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"type": "module",
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"exports": {
|
|
27
|
+
"./agent-plugins": {
|
|
28
|
+
"types": "./dist/agent-plugins.d.ts",
|
|
29
|
+
"import": "./dist/agent-plugins.js",
|
|
30
|
+
"default": "./dist/agent-plugins.js"
|
|
31
|
+
},
|
|
32
|
+
"./fs": {
|
|
33
|
+
"types": "./dist/fs.d.ts",
|
|
34
|
+
"import": "./dist/fs.js",
|
|
35
|
+
"default": "./dist/fs.js"
|
|
36
|
+
},
|
|
37
|
+
"./process": {
|
|
38
|
+
"types": "./dist/process.d.ts",
|
|
39
|
+
"import": "./dist/process.js",
|
|
40
|
+
"default": "./dist/process.js"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"dist",
|
|
45
|
+
"README.md",
|
|
46
|
+
"CHANGELOG.md",
|
|
47
|
+
"LICENSE",
|
|
48
|
+
"!dist/**/*.test.js",
|
|
49
|
+
"!dist/**/*.test.d.ts",
|
|
50
|
+
"!dist/**/*.test.js.map",
|
|
51
|
+
"!dist/**/*.test.d.ts.map",
|
|
52
|
+
"!dist/**/__tests__/**",
|
|
53
|
+
"!dist/**/*.map"
|
|
54
|
+
],
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@jini-ai/platform": "^0.7.3-next.1",
|
|
57
|
+
"@jini-ai/core": "^0.7.3-next.1"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"@jini-ai/agent-plugins": "^0.7.3-next.1"
|
|
61
|
+
},
|
|
62
|
+
"peerDependenciesMeta": {
|
|
63
|
+
"@jini-ai/agent-plugins": {
|
|
64
|
+
"optional": true
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"publishConfig": {
|
|
68
|
+
"access": "public",
|
|
69
|
+
"registry": "https://registry.npmjs.org"
|
|
70
|
+
},
|
|
71
|
+
"devDependencies": {
|
|
72
|
+
"@vitest/coverage-v8": "^2.1.9",
|
|
73
|
+
"@jini-ai/agent-plugins": "^0.7.3-next.1"
|
|
74
|
+
},
|
|
75
|
+
"scripts": {
|
|
76
|
+
"build": "tsc -p tsconfig.json",
|
|
77
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
78
|
+
"test": "vitest run",
|
|
79
|
+
"test:coverage": "vitest run --coverage"
|
|
80
|
+
}
|
|
6
81
|
}
|