@open-artifact/protocol 0.0.0-stage → 0.1.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/package.json +33 -4
- package/src/errors.d.ts +36 -0
- package/src/errors.js +46 -0
- package/src/harness.d.ts +288 -0
- package/src/harness.js +38 -0
- package/src/index.d.ts +28 -0
- package/src/index.js +28 -0
- package/src/library.d.ts +239 -0
- package/src/library.js +30 -0
- package/src/manifest.d.ts +153 -0
- package/src/manifest.js +16 -0
- package/src/prompt.d.ts +40 -0
- package/src/prompt.js +139 -0
- package/src/refs.d.ts +51 -0
- package/src/refs.js +58 -0
- package/src/settings.d.ts +53 -0
- package/src/settings.js +21 -0
- package/src/shell.d.ts +357 -0
- package/src/shell.js +60 -0
- package/src/tools.d.ts +191 -0
- package/src/tools.js +153 -0
- package/src/type-server.d.ts +249 -0
- package/src/type-server.js +60 -0
- package/src/wake.d.ts +149 -0
- package/src/wake.js +135 -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
|
+
# @open-artifact/protocol
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Open Artifact protocol: typed contracts shared by the daemon, harness adapters, type servers, the Shell and pages.
|
|
4
|
+
|
|
5
|
+
Part of [Open Artifact](https://github.com/JimLiu/open-artifact): slide decks, design canvases and whiteboards an agent makes
|
|
6
|
+
and you view, edit and comment on in one local page. Source: [`packages/protocol`](https://github.com/JimLiu/open-artifact/tree/main/packages/protocol).
|
package/package.json
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-artifact/protocol",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The Open Artifact protocol: typed contracts shared by the daemon, harness adapters, type servers, the Shell and pages.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./src/index.d.ts",
|
|
9
|
+
"default": "./src/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./package.json": "./package.json"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"src",
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"NOTICE"
|
|
17
|
+
],
|
|
18
|
+
"license": "Apache-2.0",
|
|
19
|
+
"author": {
|
|
20
|
+
"name": "Jim Liu 宝玉",
|
|
21
|
+
"url": "https://github.com/JimLiu"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/JimLiu/open-artifact#readme",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/JimLiu/open-artifact.git",
|
|
27
|
+
"directory": "packages/protocol"
|
|
28
|
+
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/JimLiu/open-artifact/issues"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
}
|
|
35
|
+
}
|
package/src/errors.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Errors on the wire.
|
|
3
|
+
*
|
|
4
|
+
* Every API answers a failure as `{ code, message, fix? }` (HTTP bodies, tool
|
|
5
|
+
* results under `error`, JSON-RPC errors under `error.data`). A conflict may
|
|
6
|
+
* add `current`: what the thing is now, for the caller to merge with.
|
|
7
|
+
*/
|
|
8
|
+
/** Error codes used across the protocol. Types may add their own. */
|
|
9
|
+
export type OpenArtifactErrorCode = 'invalid_argument' | 'not_found' | 'unauthorized' | 'not_granted' | 'conflict' | 'too_large' | 'bad_path' | 'rate_limited' | 'unsupported' | 'unknown_action' | 'unknown_tool' | 'method_not_found' | 'type_missing' | 'type_not_runnable' | 'server_failed' | 'no_daemon' | 'daemon_failed' | 'connect_failed' | 'disconnected' | 'timeout' | 'error' | (string & {});
|
|
10
|
+
/** A failure as it travels. */
|
|
11
|
+
export interface OpenArtifactErrorBody {
|
|
12
|
+
code: OpenArtifactErrorCode;
|
|
13
|
+
message: string;
|
|
14
|
+
/** What the caller can do about it, for agents. */
|
|
15
|
+
fix?: string;
|
|
16
|
+
/** For a conflict: what the conflicting thing is now. */
|
|
17
|
+
current?: unknown;
|
|
18
|
+
}
|
|
19
|
+
/** A thrown error that carries a protocol code. */
|
|
20
|
+
export declare class OpenArtifactError extends Error {
|
|
21
|
+
readonly code: OpenArtifactErrorCode;
|
|
22
|
+
readonly fix?: string;
|
|
23
|
+
/** HTTP status to answer with, when thrown inside an HTTP handler. */
|
|
24
|
+
readonly status?: number;
|
|
25
|
+
/** For a conflict: what the conflicting thing is now. */
|
|
26
|
+
readonly current?: unknown;
|
|
27
|
+
constructor(code: OpenArtifactErrorCode, message: string, options?: {
|
|
28
|
+
fix?: string;
|
|
29
|
+
status?: number;
|
|
30
|
+
current?: unknown;
|
|
31
|
+
});
|
|
32
|
+
/** The wire form. */
|
|
33
|
+
toJSON(): OpenArtifactErrorBody;
|
|
34
|
+
}
|
|
35
|
+
/** Any thrown value → its wire form. */
|
|
36
|
+
export declare function errorBody(error: unknown): OpenArtifactErrorBody;
|
package/src/errors.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Errors on the wire.
|
|
3
|
+
*
|
|
4
|
+
* Every API answers a failure as `{ code, message, fix? }` (HTTP bodies, tool
|
|
5
|
+
* results under `error`, JSON-RPC errors under `error.data`). A conflict may
|
|
6
|
+
* add `current`: what the thing is now, for the caller to merge with.
|
|
7
|
+
*/
|
|
8
|
+
/** A thrown error that carries a protocol code. */
|
|
9
|
+
export class OpenArtifactError extends Error {
|
|
10
|
+
code;
|
|
11
|
+
fix;
|
|
12
|
+
/** HTTP status to answer with, when thrown inside an HTTP handler. */
|
|
13
|
+
status;
|
|
14
|
+
/** For a conflict: what the conflicting thing is now. */
|
|
15
|
+
current;
|
|
16
|
+
constructor(code, message, options = {}) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = 'OpenArtifactError';
|
|
19
|
+
this.code = code;
|
|
20
|
+
if (options.fix !== undefined)
|
|
21
|
+
this.fix = options.fix;
|
|
22
|
+
if (options.status !== undefined)
|
|
23
|
+
this.status = options.status;
|
|
24
|
+
if (options.current !== undefined)
|
|
25
|
+
this.current = options.current;
|
|
26
|
+
}
|
|
27
|
+
/** The wire form. */
|
|
28
|
+
toJSON() {
|
|
29
|
+
return { code: this.code, message: this.message, ...(this.fix ? { fix: this.fix } : {}), ...(this.current !== undefined ? { current: this.current } : {}) };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Any thrown value → its wire form. */
|
|
33
|
+
export function errorBody(error) {
|
|
34
|
+
if (error instanceof OpenArtifactError)
|
|
35
|
+
return error.toJSON();
|
|
36
|
+
// `extra` is where server-sdk's FrameError keeps its fix and current.
|
|
37
|
+
const e = error;
|
|
38
|
+
const fix = e?.fix ?? e?.extra?.fix;
|
|
39
|
+
const current = e?.current ?? e?.extra?.current;
|
|
40
|
+
return {
|
|
41
|
+
code: typeof e?.code === 'string' ? e.code : 'error',
|
|
42
|
+
message: typeof e?.message === 'string' ? e.message : String(error),
|
|
43
|
+
...(typeof fix === 'string' ? { fix } : {}),
|
|
44
|
+
...(current !== undefined ? { current } : {}),
|
|
45
|
+
};
|
|
46
|
+
}
|
package/src/harness.d.ts
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Harness API: how a harness adapter (a plugin inside an agent harness)
|
|
3
|
+
* talks to the daemon.
|
|
4
|
+
*
|
|
5
|
+
* Transport: JSON-RPC 2.0 over a WebSocket at `<daemon>/__harness`, with the
|
|
6
|
+
* subprotocol {@link HARNESS_SUBPROTOCOL}. Both sides call: the adapter calls
|
|
7
|
+
* the daemon ({@link AdapterToDaemon}) and the daemon calls the adapter
|
|
8
|
+
* ({@link DaemonToAdapter}). The first call must be `hello` with the daemon
|
|
9
|
+
* token from `daemon.json`.
|
|
10
|
+
*
|
|
11
|
+
* Adapters that cannot hold a socket use the HTTP polling API instead
|
|
12
|
+
* ({@link POLL_ROUTES}): the same methods as `POST /api/open-artifact.session.*`, and
|
|
13
|
+
* `session.wait` long-polls for wakes.
|
|
14
|
+
*/
|
|
15
|
+
import type { OpenArtifactErrorBody } from './errors.ts';
|
|
16
|
+
import type { HarnessInfo, LibraryEvent, OwnerStatus } from './library.ts';
|
|
17
|
+
import type { SessionRef } from './refs.ts';
|
|
18
|
+
import type { ToolCallResult, ToolDefinition, ToolName } from './tools.ts';
|
|
19
|
+
import type { WakeDeliverStatus, WakePayload } from './wake.ts';
|
|
20
|
+
/** WebSocket path of the Harness API. */
|
|
21
|
+
export declare const HARNESS_PATH = "/__harness";
|
|
22
|
+
/** WebSocket subprotocol of the Harness API. */
|
|
23
|
+
export declare const HARNESS_SUBPROTOCOL = "open-artifact-harness";
|
|
24
|
+
/** What an adapter can do, said in `hello`. */
|
|
25
|
+
export interface AdapterCaps {
|
|
26
|
+
/** The adapter takes `wake.deliver`. `resume`: it can resume a session with no live agent. */
|
|
27
|
+
wake?: {
|
|
28
|
+
resume?: boolean;
|
|
29
|
+
};
|
|
30
|
+
/** The adapter takes `host.open` (shows an artifact in the harness's own UI). */
|
|
31
|
+
open?: boolean;
|
|
32
|
+
/** What the harness calls its agent, e.g. `Agent`. */
|
|
33
|
+
agentName?: string;
|
|
34
|
+
}
|
|
35
|
+
/** Agent state of an attached session. */
|
|
36
|
+
export type SessionStatus = 'idle' | 'running';
|
|
37
|
+
/** `hello` params. */
|
|
38
|
+
export interface HelloParams {
|
|
39
|
+
harness: string;
|
|
40
|
+
caps?: AdapterCaps;
|
|
41
|
+
token: string;
|
|
42
|
+
}
|
|
43
|
+
/** `hello` result. */
|
|
44
|
+
export interface HelloResult {
|
|
45
|
+
protocol: 1;
|
|
46
|
+
daemon: string;
|
|
47
|
+
connection: string;
|
|
48
|
+
}
|
|
49
|
+
/** Names a session of the calling harness. */
|
|
50
|
+
export interface SessionParams {
|
|
51
|
+
session?: string | null;
|
|
52
|
+
workspace?: string | null;
|
|
53
|
+
}
|
|
54
|
+
/** `session.attach` params. */
|
|
55
|
+
export interface AttachParams extends SessionParams {
|
|
56
|
+
title?: string;
|
|
57
|
+
status?: SessionStatus;
|
|
58
|
+
/** Process id of the agent, so MCP calls from its children map to this session. */
|
|
59
|
+
pid?: number;
|
|
60
|
+
}
|
|
61
|
+
/** One message that waited in a session's inbox. */
|
|
62
|
+
export interface InboxMessage extends Partial<WakePayload> {
|
|
63
|
+
kind: 'wake' | (string & {});
|
|
64
|
+
text: string;
|
|
65
|
+
/** When it was queued (ISO). */
|
|
66
|
+
at: string;
|
|
67
|
+
}
|
|
68
|
+
/** A caller override for `tools.call` and friends. */
|
|
69
|
+
export interface CallerParams {
|
|
70
|
+
caller?: SessionParams;
|
|
71
|
+
}
|
|
72
|
+
/** Methods the adapter calls on the daemon: params and result of each. */
|
|
73
|
+
export interface AdapterToDaemon {
|
|
74
|
+
hello: {
|
|
75
|
+
params: HelloParams;
|
|
76
|
+
result: HelloResult;
|
|
77
|
+
};
|
|
78
|
+
'session.attach': {
|
|
79
|
+
params: AttachParams;
|
|
80
|
+
result: {
|
|
81
|
+
key: string;
|
|
82
|
+
inbox: InboxMessage[];
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
'session.status': {
|
|
86
|
+
params: SessionParams & {
|
|
87
|
+
status: SessionStatus;
|
|
88
|
+
};
|
|
89
|
+
result: {
|
|
90
|
+
ok: true;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
'session.detach': {
|
|
94
|
+
params: SessionParams;
|
|
95
|
+
result: {
|
|
96
|
+
ok: true;
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
'session.rename': {
|
|
100
|
+
params: SessionParams & {
|
|
101
|
+
title: string;
|
|
102
|
+
};
|
|
103
|
+
result: {
|
|
104
|
+
ok: true;
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
'tools.list': {
|
|
108
|
+
params: Record<string, never>;
|
|
109
|
+
result: {
|
|
110
|
+
tools: ToolDefinition[];
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
'tools.call': {
|
|
114
|
+
params: {
|
|
115
|
+
name: ToolName | (string & {});
|
|
116
|
+
arguments: Record<string, unknown>;
|
|
117
|
+
} & CallerParams;
|
|
118
|
+
result: ToolCallResult;
|
|
119
|
+
};
|
|
120
|
+
/** The agent wrote these files (absolute paths) with its own tools. */
|
|
121
|
+
'agent.wrote': {
|
|
122
|
+
params: {
|
|
123
|
+
paths: string[];
|
|
124
|
+
} & CallerParams & SessionParams;
|
|
125
|
+
result: {
|
|
126
|
+
ok: true;
|
|
127
|
+
artifacts?: string[];
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
'artifact.open': {
|
|
131
|
+
params: {
|
|
132
|
+
url: string;
|
|
133
|
+
} & CallerParams & SessionParams;
|
|
134
|
+
result: {
|
|
135
|
+
opened: boolean;
|
|
136
|
+
view_url?: string;
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
'inbox.take': {
|
|
140
|
+
params: SessionParams & CallerParams;
|
|
141
|
+
result: {
|
|
142
|
+
messages: InboxMessage[];
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
'inbox.wait': {
|
|
146
|
+
params: SessionParams & CallerParams & {
|
|
147
|
+
timeoutMs?: number;
|
|
148
|
+
};
|
|
149
|
+
result: {
|
|
150
|
+
messages: InboxMessage[];
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
/** Turns {@link HarnessEvent}s on or off. */
|
|
154
|
+
subscribe: {
|
|
155
|
+
params: {
|
|
156
|
+
on: boolean;
|
|
157
|
+
};
|
|
158
|
+
result: {
|
|
159
|
+
ok: true;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/** `wake.deliver` params: the payload plus the target session. */
|
|
164
|
+
export interface WakeDeliverParams extends WakePayload {
|
|
165
|
+
session: string | null;
|
|
166
|
+
workspace: string | null;
|
|
167
|
+
}
|
|
168
|
+
/** `host.open` params. */
|
|
169
|
+
export interface HostOpenParams {
|
|
170
|
+
session: string | null;
|
|
171
|
+
url: string;
|
|
172
|
+
view_url: string;
|
|
173
|
+
title?: string;
|
|
174
|
+
}
|
|
175
|
+
/** Methods the daemon calls on the adapter. */
|
|
176
|
+
export interface DaemonToAdapter {
|
|
177
|
+
'wake.deliver': {
|
|
178
|
+
params: WakeDeliverParams;
|
|
179
|
+
result: {
|
|
180
|
+
status: WakeDeliverStatus;
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
'host.open': {
|
|
184
|
+
params: HostOpenParams;
|
|
185
|
+
result: {
|
|
186
|
+
opened: boolean;
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/** Events pushed to subscribed adapters as the `event` notification. */
|
|
191
|
+
export type HarnessEvent = LibraryEvent;
|
|
192
|
+
/** Handlers an adapter registers for the daemon's calls. */
|
|
193
|
+
export type DaemonCallHandlers = {
|
|
194
|
+
[M in keyof DaemonToAdapter]?: (params: DaemonToAdapter[M]['params']) => Promise<DaemonToAdapter[M]['result']> | DaemonToAdapter[M]['result'];
|
|
195
|
+
};
|
|
196
|
+
/** A JSON-RPC request or notification. */
|
|
197
|
+
export interface RpcRequest<P = unknown> {
|
|
198
|
+
jsonrpc: '2.0';
|
|
199
|
+
id?: string | number;
|
|
200
|
+
method: string;
|
|
201
|
+
params?: P;
|
|
202
|
+
}
|
|
203
|
+
/** A JSON-RPC response. */
|
|
204
|
+
export interface RpcResponse<R = unknown> {
|
|
205
|
+
jsonrpc: '2.0';
|
|
206
|
+
id: string | number;
|
|
207
|
+
result?: R;
|
|
208
|
+
error?: {
|
|
209
|
+
code: number;
|
|
210
|
+
message: string;
|
|
211
|
+
data?: Partial<OpenArtifactErrorBody>;
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
/** JSON-RPC error codes the daemon and adapters use. */
|
|
215
|
+
export declare const RPC_ERRORS: {
|
|
216
|
+
readonly parse: -32700;
|
|
217
|
+
readonly methodNotFound: -32601;
|
|
218
|
+
readonly invalidParams: -32602;
|
|
219
|
+
readonly server: -32000;
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* HTTP polling adapter routes (`POST`, `Authorization: Bearer <token>`,
|
|
223
|
+
* header `X-Open-Artifact-Harness: <name>`).
|
|
224
|
+
*/
|
|
225
|
+
export declare const POLL_ROUTES: {
|
|
226
|
+
readonly attach: "/api/open-artifact.session.attach";
|
|
227
|
+
/** Long-poll: answers with the next wakes for the session, or `[]` after the timeout. */
|
|
228
|
+
readonly wait: "/api/open-artifact.session.wait";
|
|
229
|
+
readonly status: "/api/open-artifact.session.status";
|
|
230
|
+
readonly detach: "/api/open-artifact.session.detach";
|
|
231
|
+
readonly tools: "/api/open-artifact.tools";
|
|
232
|
+
readonly toolsCall: "/api/open-artifact.tools.call";
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* A harness profile (`harnesses/<name>.json` in the daemon): what the daemon
|
|
236
|
+
* knows about a harness before its adapter connects.
|
|
237
|
+
*/
|
|
238
|
+
export interface HarnessProfile {
|
|
239
|
+
name: string;
|
|
240
|
+
title: string;
|
|
241
|
+
/** What the harness calls its agent. */
|
|
242
|
+
agentName: string;
|
|
243
|
+
/** Integration level: L1 MCP only, L2 MCP + hooks, L3 a full adapter. */
|
|
244
|
+
level: 'L1' | 'L2' | 'L3';
|
|
245
|
+
/** How the harness reaches the daemon. */
|
|
246
|
+
entry: 'harness-api' | 'mcp' | 'mod';
|
|
247
|
+
/** Package name of the harness plugin, when there is one. */
|
|
248
|
+
plugin?: string;
|
|
249
|
+
/** How to start the MCP bridge, for MCP-entry harnesses. */
|
|
250
|
+
mcp?: {
|
|
251
|
+
command: string;
|
|
252
|
+
args: string[];
|
|
253
|
+
};
|
|
254
|
+
/** Environment variable that holds the session id in a tool's process. */
|
|
255
|
+
sessionEnv?: string;
|
|
256
|
+
/** Where the harness looks for skills. */
|
|
257
|
+
skillsDir?: string;
|
|
258
|
+
/** Wake routes the harness supports, in order. */
|
|
259
|
+
wake: Array<'live' | 'inbox'>;
|
|
260
|
+
/**
|
|
261
|
+
* Where the daemon shows a page the agent opens (`Artifact open`, or `open: "after_first_write"`) when no adapter
|
|
262
|
+
* of the harness can (`host.open`): `browser`, the browser of this computer. Left out: nowhere; the agent gives
|
|
263
|
+
* the person the link.
|
|
264
|
+
*/
|
|
265
|
+
open?: 'browser';
|
|
266
|
+
}
|
|
267
|
+
/** One adapter connection, as `GET /api/open-artifact.harnesses` lists it. */
|
|
268
|
+
export interface AdapterInfo {
|
|
269
|
+
/** Connection id. */
|
|
270
|
+
id: string;
|
|
271
|
+
harness: string;
|
|
272
|
+
caps: AdapterCaps;
|
|
273
|
+
/** Keys of the sessions attached through it. */
|
|
274
|
+
sessions: string[];
|
|
275
|
+
/** An HTTP polling adapter rather than a WebSocket. */
|
|
276
|
+
polling: boolean;
|
|
277
|
+
}
|
|
278
|
+
/** `GET /api/open-artifact.harnesses`: the harnesses, their adapters and the sessions the daemon knows. */
|
|
279
|
+
export interface HarnessesResponse {
|
|
280
|
+
harnesses: HarnessInfo[];
|
|
281
|
+
adapters: AdapterInfo[];
|
|
282
|
+
sessions: Array<SessionRef & {
|
|
283
|
+
key: string;
|
|
284
|
+
status: OwnerStatus;
|
|
285
|
+
live: boolean;
|
|
286
|
+
title?: string;
|
|
287
|
+
}>;
|
|
288
|
+
}
|
package/src/harness.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Harness API: how a harness adapter (a plugin inside an agent harness)
|
|
3
|
+
* talks to the daemon.
|
|
4
|
+
*
|
|
5
|
+
* Transport: JSON-RPC 2.0 over a WebSocket at `<daemon>/__harness`, with the
|
|
6
|
+
* subprotocol {@link HARNESS_SUBPROTOCOL}. Both sides call: the adapter calls
|
|
7
|
+
* the daemon ({@link AdapterToDaemon}) and the daemon calls the adapter
|
|
8
|
+
* ({@link DaemonToAdapter}). The first call must be `hello` with the daemon
|
|
9
|
+
* token from `daemon.json`.
|
|
10
|
+
*
|
|
11
|
+
* Adapters that cannot hold a socket use the HTTP polling API instead
|
|
12
|
+
* ({@link POLL_ROUTES}): the same methods as `POST /api/open-artifact.session.*`, and
|
|
13
|
+
* `session.wait` long-polls for wakes.
|
|
14
|
+
*/
|
|
15
|
+
/** WebSocket path of the Harness API. */
|
|
16
|
+
export const HARNESS_PATH = '/__harness';
|
|
17
|
+
/** WebSocket subprotocol of the Harness API. */
|
|
18
|
+
export const HARNESS_SUBPROTOCOL = 'open-artifact-harness';
|
|
19
|
+
/** JSON-RPC error codes the daemon and adapters use. */
|
|
20
|
+
export const RPC_ERRORS = {
|
|
21
|
+
parse: -32700,
|
|
22
|
+
methodNotFound: -32601,
|
|
23
|
+
invalidParams: -32602,
|
|
24
|
+
server: -32000,
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* HTTP polling adapter routes (`POST`, `Authorization: Bearer <token>`,
|
|
28
|
+
* header `X-Open-Artifact-Harness: <name>`).
|
|
29
|
+
*/
|
|
30
|
+
export const POLL_ROUTES = {
|
|
31
|
+
attach: '/api/open-artifact.session.attach',
|
|
32
|
+
/** Long-poll: answers with the next wakes for the session, or `[]` after the timeout. */
|
|
33
|
+
wait: '/api/open-artifact.session.wait',
|
|
34
|
+
status: '/api/open-artifact.session.status',
|
|
35
|
+
detach: '/api/open-artifact.session.detach',
|
|
36
|
+
tools: '/api/open-artifact.tools',
|
|
37
|
+
toolsCall: '/api/open-artifact.tools.call',
|
|
38
|
+
};
|