@openartifactsai/server-sdk 0.0.0-stage → 0.23.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +5 -2
- package/bin/frame-host.d.ts +2 -0
- package/bin/frame-host.js +47 -0
- package/package.json +124 -4
- package/src/child.d.ts +37 -0
- package/src/child.js +64 -0
- package/src/connectors/connectors.d.ts +101 -0
- package/src/connectors/connectors.js +256 -0
- package/src/connectors/daemon-connectors.d.ts +34 -0
- package/src/connectors/daemon-connectors.js +73 -0
- package/src/connectors/index.d.ts +7 -0
- package/src/connectors/index.js +7 -0
- package/src/connectors/mcp-client.d.ts +157 -0
- package/src/connectors/mcp-client.js +483 -0
- package/src/daemon.d.ts +119 -0
- package/src/daemon.js +301 -0
- package/src/frame/access.d.ts +69 -0
- package/src/frame/access.js +168 -0
- package/src/frame/client/comments.css +1 -0
- package/src/frame/client/comments.js +58 -0
- package/src/frame/client/imports.d.ts +6 -0
- package/src/frame/client/imports.js +112 -0
- package/src/frame/client/mcp-shell.js +345 -0
- package/src/frame/client/mcp.js +253 -0
- package/src/frame/client/runtime.js +1363 -0
- package/src/frame/client/sample.js +762 -0
- package/src/frame/client/shell.css +51 -0
- package/src/frame/client/shell.html +29 -0
- package/src/frame/client/shell.js +1417 -0
- package/src/frame/comments.d.ts +102 -0
- package/src/frame/comments.js +379 -0
- package/src/frame/core.d.ts +313 -0
- package/src/frame/core.js +1757 -0
- package/src/frame/db.d.ts +162 -0
- package/src/frame/db.js +604 -0
- package/src/frame/declaration.d.ts +30 -0
- package/src/frame/declaration.js +60 -0
- package/src/frame/env.d.ts +262 -0
- package/src/frame/env.js +13 -0
- package/src/frame/files.d.ts +130 -0
- package/src/frame/files.js +472 -0
- package/src/frame/index.d.ts +35 -0
- package/src/frame/index.js +33 -0
- package/src/frame/local.d.ts +126 -0
- package/src/frame/local.js +612 -0
- package/src/frame/mcp-relay.d.ts +79 -0
- package/src/frame/mcp-relay.js +191 -0
- package/src/frame/page-api.d.ts +48 -0
- package/src/frame/page-api.js +1 -0
- package/src/frame/page-comments.d.ts +109 -0
- package/src/frame/page-comments.js +1 -0
- package/src/frame/page-db.d.ts +88 -0
- package/src/frame/page-db.js +1 -0
- package/src/frame/page-imports.d.ts +2 -0
- package/src/frame/page-imports.js +2 -0
- package/src/frame/page-services.d.ts +124 -0
- package/src/frame/page-services.js +1 -0
- package/src/frame/page-values.d.ts +90 -0
- package/src/frame/page-values.js +1 -0
- package/src/frame/sample-relay.d.ts +42 -0
- package/src/frame/sample-relay.js +186 -0
- package/src/frame/snapshot-action.d.ts +18 -0
- package/src/frame/snapshot-action.js +82 -0
- package/src/frame/wire.d.ts +198 -0
- package/src/frame/wire.js +21 -0
- package/src/index.d.ts +17 -0
- package/src/index.js +17 -0
- package/src/lan.d.ts +75 -0
- package/src/lan.js +200 -0
- package/src/legacy-env.d.ts +7 -0
- package/src/legacy-env.js +14 -0
- package/src/serve.d.ts +375 -0
- package/src/serve.js +811 -0
- package/src/snapshot.d.ts +41 -0
- package/src/snapshot.js +224 -0
- package/src/type-package.d.ts +48 -0
- package/src/type-package.js +114 -0
- package/src/ws.d.ts +50 -0
- package/src/ws.js +203 -0
- package/src/zip.d.ts +197 -0
- package/src/zip.js +662 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @openartifactsai/server-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared code for Open Artifacts type servers: the server skeleton, the Type API client, LAN sharing and a minimal WebSocket server.
|
|
4
|
+
|
|
5
|
+
Part of [Open Artifacts](https://github.com/openartifactsai/open-artifacts): slide decks, design canvases and whiteboards an agent makes
|
|
6
|
+
and you view, edit and comment on in one local page. Source: [`packages/server-sdk`](https://github.com/openartifactsai/open-artifacts/tree/main/packages/server-sdk).
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* frame-host: the type server of an original hosted artifact type — a
|
|
4
|
+
* folder (`OPEN_ARTIFACTS_TYPE_DIR`) whose index.html declares itself in an inline
|
|
5
|
+
* `// artifact.json` block. The daemon derives this entry for such a type
|
|
6
|
+
* (runtime `frame`); it can also be started by hand with `OPEN_ARTIFACTS_TYPE_DIR` set.
|
|
7
|
+
* A page type (`openArtifacts.style: "page"` in its artifact-type.json) runs in
|
|
8
|
+
* page mode instead: each artifact's own index.html is its page.
|
|
9
|
+
* Every artifact's page runs on its own origin, `<id>.frame.localhost:<port>`.
|
|
10
|
+
* A restricted type (`OPEN_ARTIFACTS_TYPE_RESTRICTED=1`, set by the daemon for a type of
|
|
11
|
+
* an untrusted root: installed, or a project not trusted yet) has its page's origin
|
|
12
|
+
* answer with a Content-Security-Policy (its own origin, inline scripts and styles,
|
|
13
|
+
* `data:`, `blob:` and the manifest's `openArtifacts.network`), and its page framed
|
|
14
|
+
* with a `sandbox` (no popups, no top navigation).
|
|
15
|
+
* Its actions are the frame core's (`info` and the reserved `open-artifacts.*`) and
|
|
16
|
+
* `snapshot`, a PNG of the page drawn by this computer's headless Chrome.
|
|
17
|
+
* Nothing of the type folder is run here: its declaration is read as literal data.
|
|
18
|
+
*
|
|
19
|
+
* Runs from source (`node packages/server-sdk/bin/frame-host.ts`) or as the
|
|
20
|
+
* bundle `scripts/build.mjs --only frame` writes to `dist/daemon/frame-host/`.
|
|
21
|
+
*/
|
|
22
|
+
import { basename, resolve } from 'node:path';
|
|
23
|
+
import { mountFrameSite, readDeclaration } from "../src/frame/index.js";
|
|
24
|
+
import { localFrameActions } from "../src/frame/snapshot-action.js";
|
|
25
|
+
import { installedTypeCsp, networkOrigins } from '@openartifactsai/protocol';
|
|
26
|
+
import { serve, typeManifest } from "../src/serve.js";
|
|
27
|
+
const dir = resolve(process.env.OPEN_ARTIFACTS_TYPE_DIR ?? process.cwd());
|
|
28
|
+
const manifest = typeManifest(dir);
|
|
29
|
+
// A page type (`openArtifacts.style: "page"`) has no index.html of its own: page mode runs each artifact's.
|
|
30
|
+
const page = manifest.openArtifacts?.style === 'page';
|
|
31
|
+
if (!page && !readDeclaration(dir)) {
|
|
32
|
+
process.stderr.write(`${dir}/index.html has no // artifact.json declaration: not an original artifact type.\n`);
|
|
33
|
+
process.exit(2);
|
|
34
|
+
}
|
|
35
|
+
const restricted = process.env.OPEN_ARTIFACTS_TYPE_RESTRICTED === '1';
|
|
36
|
+
const allowedNetworkOrigins = networkOrigins(manifest);
|
|
37
|
+
const contentSecurityPolicy = restricted ? installedTypeCsp(allowedNetworkOrigins) : null;
|
|
38
|
+
await serve({
|
|
39
|
+
mountSite: (root, ctx) => mountFrameSite(root, { ...ctx, typeDir: dir, page, contentSecurityPolicy, allowedNetworkOrigins, restricted }),
|
|
40
|
+
// The core's actions and `snapshot` (this computer's headless Chrome): a hosted site serves `frameActions` alone.
|
|
41
|
+
actions: localFrameActions,
|
|
42
|
+
// The type id: the daemon passes it; by hand, the folder name (as the daemon would derive it).
|
|
43
|
+
type: process.env.OPEN_ARTIFACTS_TYPE ?? basename(dir),
|
|
44
|
+
version: manifest.version ?? '0',
|
|
45
|
+
contentHosts: true,
|
|
46
|
+
archive: true,
|
|
47
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,126 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openartifactsai/server-sdk",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.23.0-rc.0",
|
|
4
|
+
"description": "Shared code for Open Artifacts type servers: the server skeleton, the Type API client, LAN sharing and a minimal WebSocket server.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"open-artifacts-frame-host": "bin/frame-host.js"
|
|
8
|
+
},
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./src/index.d.ts",
|
|
12
|
+
"default": "./src/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./serve": {
|
|
15
|
+
"types": "./src/serve.d.ts",
|
|
16
|
+
"default": "./src/serve.js"
|
|
17
|
+
},
|
|
18
|
+
"./daemon": {
|
|
19
|
+
"types": "./src/daemon.d.ts",
|
|
20
|
+
"default": "./src/daemon.js"
|
|
21
|
+
},
|
|
22
|
+
"./lan": {
|
|
23
|
+
"types": "./src/lan.d.ts",
|
|
24
|
+
"default": "./src/lan.js"
|
|
25
|
+
},
|
|
26
|
+
"./ws": {
|
|
27
|
+
"types": "./src/ws.d.ts",
|
|
28
|
+
"default": "./src/ws.js"
|
|
29
|
+
},
|
|
30
|
+
"./child": {
|
|
31
|
+
"types": "./src/child.d.ts",
|
|
32
|
+
"default": "./src/child.js"
|
|
33
|
+
},
|
|
34
|
+
"./frame": {
|
|
35
|
+
"types": "./src/frame/index.d.ts",
|
|
36
|
+
"default": "./src/frame/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./frame/imports": {
|
|
39
|
+
"types": "./src/frame/page-imports.d.ts",
|
|
40
|
+
"default": "./src/frame/page-imports.js"
|
|
41
|
+
},
|
|
42
|
+
"./frame/page-api": {
|
|
43
|
+
"types": "./src/frame/page-api.d.ts",
|
|
44
|
+
"default": "./src/frame/page-api.js"
|
|
45
|
+
},
|
|
46
|
+
"./frame/core": {
|
|
47
|
+
"types": "./src/frame/core.d.ts",
|
|
48
|
+
"default": "./src/frame/core.js"
|
|
49
|
+
},
|
|
50
|
+
"./frame/env": {
|
|
51
|
+
"types": "./src/frame/env.d.ts",
|
|
52
|
+
"default": "./src/frame/env.js"
|
|
53
|
+
},
|
|
54
|
+
"./frame/sample-relay": {
|
|
55
|
+
"types": "./src/frame/sample-relay.d.ts",
|
|
56
|
+
"default": "./src/frame/sample-relay.js"
|
|
57
|
+
},
|
|
58
|
+
"./connectors": {
|
|
59
|
+
"types": "./src/connectors/index.d.ts",
|
|
60
|
+
"default": "./src/connectors/index.js"
|
|
61
|
+
},
|
|
62
|
+
"./connectors/connectors": {
|
|
63
|
+
"types": "./src/connectors/connectors.d.ts",
|
|
64
|
+
"default": "./src/connectors/connectors.js"
|
|
65
|
+
},
|
|
66
|
+
"./connectors/mcp-client": {
|
|
67
|
+
"types": "./src/connectors/mcp-client.d.ts",
|
|
68
|
+
"default": "./src/connectors/mcp-client.js"
|
|
69
|
+
},
|
|
70
|
+
"./connectors/daemon": {
|
|
71
|
+
"types": "./src/connectors/daemon-connectors.d.ts",
|
|
72
|
+
"default": "./src/connectors/daemon-connectors.js"
|
|
73
|
+
},
|
|
74
|
+
"./db": {
|
|
75
|
+
"types": "./src/frame/db.d.ts",
|
|
76
|
+
"default": "./src/frame/db.js"
|
|
77
|
+
},
|
|
78
|
+
"./comments": {
|
|
79
|
+
"types": "./src/frame/comments.d.ts",
|
|
80
|
+
"default": "./src/frame/comments.js"
|
|
81
|
+
},
|
|
82
|
+
"./zip": {
|
|
83
|
+
"types": "./src/zip.d.ts",
|
|
84
|
+
"default": "./src/zip.js"
|
|
85
|
+
},
|
|
86
|
+
"./type-package": {
|
|
87
|
+
"types": "./src/type-package.d.ts",
|
|
88
|
+
"default": "./src/type-package.js"
|
|
89
|
+
},
|
|
90
|
+
"./snapshot": {
|
|
91
|
+
"types": "./src/snapshot.d.ts",
|
|
92
|
+
"default": "./src/snapshot.js"
|
|
93
|
+
},
|
|
94
|
+
"./package.json": "./package.json"
|
|
95
|
+
},
|
|
96
|
+
"files": [
|
|
97
|
+
"src",
|
|
98
|
+
"bin",
|
|
99
|
+
"LICENSE",
|
|
100
|
+
"NOTICE"
|
|
101
|
+
],
|
|
102
|
+
"dependencies": {
|
|
103
|
+
"@openartifactsai/protocol": "0.23.0-rc.0",
|
|
104
|
+
"@openartifactsai/runtime": "0.23.0-rc.0"
|
|
105
|
+
},
|
|
106
|
+
"engines": {
|
|
107
|
+
"node": ">=22.18"
|
|
108
|
+
},
|
|
109
|
+
"license": "Apache-2.0",
|
|
110
|
+
"author": {
|
|
111
|
+
"name": "Jim Liu 宝玉",
|
|
112
|
+
"url": "https://github.com/JimLiu"
|
|
113
|
+
},
|
|
114
|
+
"homepage": "https://github.com/openartifactsai/open-artifacts#readme",
|
|
115
|
+
"repository": {
|
|
116
|
+
"type": "git",
|
|
117
|
+
"url": "git+https://github.com/openartifactsai/open-artifacts.git",
|
|
118
|
+
"directory": "packages/server-sdk"
|
|
119
|
+
},
|
|
120
|
+
"bugs": {
|
|
121
|
+
"url": "https://github.com/openartifactsai/open-artifacts/issues"
|
|
122
|
+
},
|
|
123
|
+
"publishConfig": {
|
|
124
|
+
"access": "public"
|
|
125
|
+
}
|
|
126
|
+
}
|
package/src/child.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stopping a child process, and ending this one. Node only.
|
|
3
|
+
*
|
|
4
|
+
* - `stopChild`: the stop ladder every spawned child goes through: ask (a signal, or end of input), wait, force with
|
|
5
|
+
* `SIGKILL`, and resolve once it has exited or the wait is given up. A child that has exited is never signalled.
|
|
6
|
+
* - `endProcess`: how a command-line entry point ends with its exit code.
|
|
7
|
+
*/
|
|
8
|
+
import type { ChildProcess } from 'node:child_process';
|
|
9
|
+
/** Whether the child has exited (by itself or by a signal). */
|
|
10
|
+
export declare function hasExited(child: ChildProcess): boolean;
|
|
11
|
+
export interface StopChildOptions {
|
|
12
|
+
/** How long the child has to end after the first signal before it is killed, ms. 0: kill at once. */
|
|
13
|
+
graceMs: number;
|
|
14
|
+
/**
|
|
15
|
+
* The first signal (default `SIGTERM`). `null` sends none: the child was asked to end some other way (a protocol
|
|
16
|
+
* message, end of input) and is only waited for, then killed after `graceMs`.
|
|
17
|
+
*/
|
|
18
|
+
signal?: NodeJS.Signals | null;
|
|
19
|
+
/** Close the child's stdin before signalling (a stdio server ends on end-of-input). */
|
|
20
|
+
endStdin?: boolean;
|
|
21
|
+
/** How long to wait for the exit after the kill before giving up, ms (default 1000). 0: resolve right after it. */
|
|
22
|
+
settleMs?: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Asks a child to stop and resolves once it has exited: `signal` now, `SIGKILL` after `graceMs` if it still runs, and
|
|
26
|
+
* at the latest `settleMs` after that (a child that cannot be killed must not hang its caller). A child that has
|
|
27
|
+
* exited already is not signalled and resolves at once. Its timers do not keep the process alive. Several calls on one
|
|
28
|
+
* child each signal it (unless it has exited) and each resolve.
|
|
29
|
+
* Resolves true when the child has exited, false when the wait was given up.
|
|
30
|
+
*/
|
|
31
|
+
export declare function stopChild(child: ChildProcess, options: StopChildOptions): Promise<boolean>;
|
|
32
|
+
/**
|
|
33
|
+
* Ends this process with `code` once what it opened has closed, instead of `process.exit()` straight away: on Windows,
|
|
34
|
+
* Node before 24.20 aborts the process (exit 0xC0000409, nodejs/node#56645) when it exits while a connection it made
|
|
35
|
+
* (to the daemon, say) is still closing. Anything that still holds the process a moment later is cut off.
|
|
36
|
+
*/
|
|
37
|
+
export declare function endProcess(code: number): void;
|
package/src/child.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** Whether the child has exited (by itself or by a signal). */
|
|
2
|
+
export function hasExited(child) {
|
|
3
|
+
return child.exitCode !== null || child.signalCode !== null;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Asks a child to stop and resolves once it has exited: `signal` now, `SIGKILL` after `graceMs` if it still runs, and
|
|
7
|
+
* at the latest `settleMs` after that (a child that cannot be killed must not hang its caller). A child that has
|
|
8
|
+
* exited already is not signalled and resolves at once. Its timers do not keep the process alive. Several calls on one
|
|
9
|
+
* child each signal it (unless it has exited) and each resolve.
|
|
10
|
+
* Resolves true when the child has exited, false when the wait was given up.
|
|
11
|
+
*/
|
|
12
|
+
export function stopChild(child, options) {
|
|
13
|
+
if (hasExited(child))
|
|
14
|
+
return Promise.resolve(true);
|
|
15
|
+
const { graceMs, endStdin = false, settleMs = 1000 } = options;
|
|
16
|
+
const signal = options.signal === undefined ? 'SIGTERM' : options.signal;
|
|
17
|
+
return new Promise((resolve) => {
|
|
18
|
+
let timer;
|
|
19
|
+
const finish = (exited) => {
|
|
20
|
+
clearTimeout(timer);
|
|
21
|
+
child.off('exit', onExit);
|
|
22
|
+
resolve(exited);
|
|
23
|
+
};
|
|
24
|
+
const onExit = () => finish(true);
|
|
25
|
+
child.once('exit', onExit);
|
|
26
|
+
const later = (ms, then) => {
|
|
27
|
+
timer = setTimeout(then, ms);
|
|
28
|
+
timer.unref();
|
|
29
|
+
};
|
|
30
|
+
const giveUp = () => (hasExited(child) ? finish(true) : finish(false));
|
|
31
|
+
const kill = () => {
|
|
32
|
+
if (hasExited(child))
|
|
33
|
+
return finish(true);
|
|
34
|
+
child.kill('SIGKILL');
|
|
35
|
+
if (settleMs > 0)
|
|
36
|
+
later(settleMs, giveUp);
|
|
37
|
+
else
|
|
38
|
+
giveUp();
|
|
39
|
+
};
|
|
40
|
+
if (endStdin)
|
|
41
|
+
child.stdin?.end();
|
|
42
|
+
if (graceMs <= 0)
|
|
43
|
+
return kill();
|
|
44
|
+
if (signal) {
|
|
45
|
+
try {
|
|
46
|
+
child.kill(signal);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// A signal this platform does not know: nothing was sent, so nothing is forced either.
|
|
50
|
+
return giveUp();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
later(graceMs, kill);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Ends this process with `code` once what it opened has closed, instead of `process.exit()` straight away: on Windows,
|
|
58
|
+
* Node before 24.20 aborts the process (exit 0xC0000409, nodejs/node#56645) when it exits while a connection it made
|
|
59
|
+
* (to the daemon, say) is still closing. Anything that still holds the process a moment later is cut off.
|
|
60
|
+
*/
|
|
61
|
+
export function endProcess(code) {
|
|
62
|
+
process.exitCode = code;
|
|
63
|
+
setTimeout(() => process.exit(code), 1_000).unref();
|
|
64
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connectors: the MCP servers the owner set up on this computer, whose tools
|
|
3
|
+
* the owner's pages call through the `mcp` capability.
|
|
4
|
+
*
|
|
5
|
+
* They are configured in `connectors.json` beside `settings.json`
|
|
6
|
+
* (`$OPEN_ARTIFACTS_CONNECTORS`, else `$OPEN_ARTIFACTS_HOME/connectors.json`,
|
|
7
|
+
* else `~/.agents/open-artifacts/connectors.json`), in the usual
|
|
8
|
+
* `mcpServers` shape:
|
|
9
|
+
*
|
|
10
|
+
* { "mcpServers": {
|
|
11
|
+
* "files": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "~/Data"] },
|
|
12
|
+
* "tracker": { "url": "https://mcp.example.com/mcp", "headers": { "Authorization": "Bearer ${TRACKER_TOKEN}" } }
|
|
13
|
+
* } }
|
|
14
|
+
*
|
|
15
|
+
* `${NAME}` (or `${NAME:-default}`) in a string is read from the
|
|
16
|
+
* environment; `"disabled": true` keeps a server listed but off. The file is
|
|
17
|
+
* read again when it changes. Stdio servers start on first use, are reused,
|
|
18
|
+
* start again after they stop, and are stopped with {@link ConnectorsHost.close}.
|
|
19
|
+
*/
|
|
20
|
+
import type { McpServerEntry, McpToolResult } from '@openartifactsai/runtime/capabilities';
|
|
21
|
+
import { type ConnectorToolInfo, type McpClientInfo, type McpRequestControl } from './mcp-client.js';
|
|
22
|
+
/** One connector as {@link ConnectorsHost.listTools} lists it, its tools with their hints. */
|
|
23
|
+
export interface ConnectorServerEntry extends McpServerEntry {
|
|
24
|
+
tools?: ConnectorToolInfo[];
|
|
25
|
+
}
|
|
26
|
+
/** A server this computer starts. */
|
|
27
|
+
export interface StdioConnectorConfig {
|
|
28
|
+
command: string;
|
|
29
|
+
args?: string[];
|
|
30
|
+
env?: Record<string, string>;
|
|
31
|
+
cwd?: string;
|
|
32
|
+
disabled?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** A server reached over Streamable HTTP. */
|
|
35
|
+
export interface HttpConnectorConfig {
|
|
36
|
+
url: string;
|
|
37
|
+
headers?: Record<string, string>;
|
|
38
|
+
/** `http` or `streamable-http` (the default); `sse` (the older transport) is not supported. */
|
|
39
|
+
type?: string;
|
|
40
|
+
disabled?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export type ConnectorConfig = StdioConnectorConfig | HttpConnectorConfig;
|
|
43
|
+
/** The file's shape. */
|
|
44
|
+
export interface ConnectorsFile {
|
|
45
|
+
mcpServers: Record<string, ConnectorConfig>;
|
|
46
|
+
}
|
|
47
|
+
/** Where the connectors are configured. */
|
|
48
|
+
export declare function connectorsFile(env?: NodeJS.ProcessEnv): string;
|
|
49
|
+
/** Replaces `${NAME}` and `${NAME:-default}` with the environment's values. */
|
|
50
|
+
export declare function expandVariables(text: string, env?: NodeJS.ProcessEnv): string;
|
|
51
|
+
/** Checks and expands one server's entry; throws a readable message when it is unusable. */
|
|
52
|
+
export declare function connectorConfigOf(value: unknown, env?: NodeJS.ProcessEnv): ConnectorConfig;
|
|
53
|
+
/** One configured server: its config, or why it cannot be used. */
|
|
54
|
+
type Entry = {
|
|
55
|
+
config: ConnectorConfig;
|
|
56
|
+
key: string;
|
|
57
|
+
error?: undefined;
|
|
58
|
+
} | {
|
|
59
|
+
config?: undefined;
|
|
60
|
+
key: string;
|
|
61
|
+
error: string;
|
|
62
|
+
};
|
|
63
|
+
/** Reads the file's servers. A missing file has none; a broken one throws. */
|
|
64
|
+
export declare function parseConnectors(text: string, env?: NodeJS.ProcessEnv): Map<string, Entry>;
|
|
65
|
+
/** Options of {@link ConnectorsHost}. */
|
|
66
|
+
export interface ConnectorsHostOptions {
|
|
67
|
+
/** The configuration file (default {@link connectorsFile}). */
|
|
68
|
+
file?: string;
|
|
69
|
+
log?: (line: string) => void;
|
|
70
|
+
clientInfo?: McpClientInfo;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The connectors of this computer: configuration, running clients, and the two calls pages make. The daemon keeps one
|
|
74
|
+
* for every page and type; a type server running without a daemon keeps its own.
|
|
75
|
+
*/
|
|
76
|
+
export declare class ConnectorsHost {
|
|
77
|
+
readonly file: string;
|
|
78
|
+
private readonly log;
|
|
79
|
+
private readonly clientInfo;
|
|
80
|
+
private entries;
|
|
81
|
+
private readonly clients;
|
|
82
|
+
/** `mtime:size` of the file last read (`missing` when absent). */
|
|
83
|
+
private stamp;
|
|
84
|
+
private fileError;
|
|
85
|
+
private readonly onExit;
|
|
86
|
+
constructor(options?: ConnectorsHostOptions);
|
|
87
|
+
/** Reads the file again when it changed, and stops clients whose server changed or went. */
|
|
88
|
+
private refresh;
|
|
89
|
+
/** The client of a usable, enabled server; throws `server_not_connected` otherwise. */
|
|
90
|
+
private clientOf;
|
|
91
|
+
/** The configured server names. */
|
|
92
|
+
names(): string[];
|
|
93
|
+
/** Calls a tool of `server`. */
|
|
94
|
+
callTool(server: string, tool: string, args: Record<string, unknown>, control?: McpRequestControl): Promise<McpToolResult>;
|
|
95
|
+
/** Every server (or only `server`, when it is set up), connected ones with their tools. */
|
|
96
|
+
listTools(server?: string): Promise<ConnectorServerEntry[]>;
|
|
97
|
+
private describe;
|
|
98
|
+
/** Stops every server this host started. */
|
|
99
|
+
close(): Promise<void>;
|
|
100
|
+
}
|
|
101
|
+
export {};
|