@capybara-hq/plugin-sdk 0.0.0-stage → 0.1.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 +2 -0
- package/README.md +27 -2
- package/dist/agent-template.d.ts +47 -0
- package/dist/agent-template.js +123 -0
- package/dist/bootstrap.d.ts +67 -0
- package/dist/bootstrap.js +109 -0
- package/dist/cards.d.ts +64 -0
- package/dist/cards.js +217 -0
- package/dist/channel.d.ts +230 -0
- package/dist/channel.js +26 -0
- package/dist/connector-auth.d.ts +64 -0
- package/dist/connector-auth.js +96 -0
- package/dist/connector.d.ts +154 -0
- package/dist/connector.js +1 -0
- package/dist/ctx.d.ts +176 -0
- package/dist/ctx.js +1 -0
- package/dist/define-extension.d.ts +41 -0
- package/dist/define-extension.js +85 -0
- package/dist/directory.d.ts +29 -0
- package/dist/directory.js +1 -0
- package/dist/extension-point.d.ts +29 -0
- package/dist/extension-point.js +36 -0
- package/dist/file-preview.d.ts +64 -0
- package/dist/file-preview.js +72 -0
- package/dist/frontmatter.d.ts +12 -0
- package/dist/frontmatter.js +36 -0
- package/dist/hooks.d.ts +194 -0
- package/dist/hooks.js +14 -0
- package/dist/identity.d.ts +44 -0
- package/dist/identity.js +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +27 -0
- package/dist/marketplace.d.ts +99 -0
- package/dist/marketplace.js +256 -0
- package/dist/model-params.d.ts +82 -0
- package/dist/model-params.js +222 -0
- package/dist/model.d.ts +227 -0
- package/dist/model.js +152 -0
- package/dist/permissions.d.ts +67 -0
- package/dist/permissions.js +271 -0
- package/dist/plugin-manifest.d.ts +141 -0
- package/dist/plugin-manifest.js +322 -0
- package/dist/plugin-package.d.ts +139 -0
- package/dist/plugin-package.js +448 -0
- package/dist/sandbox.d.ts +152 -0
- package/dist/sandbox.js +96 -0
- package/dist/secret.d.ts +5 -0
- package/dist/secret.js +8 -0
- package/dist/semver-range.d.ts +6 -0
- package/dist/semver-range.js +12 -0
- package/dist/skill-invocation.d.ts +83 -0
- package/dist/skill-invocation.js +201 -0
- package/dist/skill-keys.d.ts +9 -0
- package/dist/skill-keys.js +16 -0
- package/dist/skill.d.ts +77 -0
- package/dist/skill.js +244 -0
- package/dist/storage.d.ts +96 -0
- package/dist/storage.js +9 -0
- package/dist/tool.d.ts +154 -0
- package/dist/tool.js +218 -0
- package/dist/ui.d.ts +265 -0
- package/dist/ui.js +358 -0
- package/dist/url.d.ts +2 -0
- package/dist/url.js +12 -0
- package/package.json +40 -3
- package/schemas/bootstrap.v1.schema.json +125 -0
- package/schemas/connector-template.v1.schema.json +116 -0
- package/schemas/marketplace.v1.schema.json +270 -0
- package/schemas/plugin.v1.schema.json +330 -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,28 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @capybara-hq/plugin-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The SDK for writing plugins for [Capybara](https://github.com/capybara-hq/core), an open-source enterprise agent platform. It holds
|
|
4
|
+
the types, extension point contracts (`model-provider@2`, `channel@1`, `connector@1`, `sandbox@1`,
|
|
5
|
+
`object-store@1` and others) and pure functions that a plugin's extension is written against, and the
|
|
6
|
+
package formats: the plugin manifest `.capybara-plugin/plugin.json` (`parsePluginManifest`),
|
|
7
|
+
connector template files `connectors/<id>.json` (`parseConnectorTemplateFile`) and the marketplace
|
|
8
|
+
manifest `marketplace.json` (`parseMarketplaceManifest`), with their JSON Schemas in `schemas/`
|
|
9
|
+
(`plugin.v1`, `connector-template.v1`, `marketplace.v1`; reference them from a file's `$schema` as
|
|
10
|
+
`https://capybarahq.com/schemas/<file>`). An extension depends only on this package and third-party
|
|
11
|
+
npm packages; the host provides it at runtime.
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @capybara-hq/plugin-sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
- Writing an extension: [.agents/skills/writing-extensions](https://github.com/capybara-hq/core/tree/main/.agents/skills/writing-extensions)
|
|
18
|
+
and the reference plugin [plugins/example-counter](https://github.com/capybara-hq/core/tree/main/plugins/example-counter).
|
|
19
|
+
- Writing a plugin (manifest, skills, connector templates, dependencies, marketplaces):
|
|
20
|
+
[.agents/skills/writing-plugins](https://github.com/capybara-hq/core/tree/main/.agents/skills/writing-plugins).
|
|
21
|
+
- The repository: [capybara-hq/core](https://github.com/capybara-hq/core).
|
|
22
|
+
|
|
23
|
+
Capybara is on 0.x: the SDK may change in breaking ways between minor versions, and each release's
|
|
24
|
+
notes describe how to migrate.
|
|
25
|
+
|
|
26
|
+
## License
|
|
27
|
+
|
|
28
|
+
[Apache-2.0](https://github.com/capybara-hq/core/blob/main/LICENSE). See `NOTICE`.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** The model tier of a template: a kernel purpose, never a model id (spec §5.4). */
|
|
2
|
+
export type AgentTemplateTier = "inherit" | "fast" | "standard" | "capable";
|
|
3
|
+
/** A parsed agent template. Optional fields are absent when the frontmatter omits them. */
|
|
4
|
+
export interface AgentTemplate {
|
|
5
|
+
/** `^[a-z0-9][a-z0-9-]{0,63}$`; the type name is `<plugin>:<name>`. */
|
|
6
|
+
name: string;
|
|
7
|
+
/** When to use it (trimmed, at most 4096 characters). */
|
|
8
|
+
description: string;
|
|
9
|
+
/** The body after the frontmatter, unchanged. */
|
|
10
|
+
instructions: string;
|
|
11
|
+
/** Tool keys allowed (an allowlist); omitted = the parent's tools. */
|
|
12
|
+
tools?: string[];
|
|
13
|
+
/** Tool keys removed. */
|
|
14
|
+
disallowedTools?: string[];
|
|
15
|
+
/** Tightened policies by tool key. */
|
|
16
|
+
toolPolicies?: Record<string, "ask" | "deny">;
|
|
17
|
+
/** Default `inherit`. */
|
|
18
|
+
model?: AgentTemplateTier;
|
|
19
|
+
effort?: "low" | "medium" | "high" | "xhigh" | "max";
|
|
20
|
+
/** Step limit (the kernel caps it at `runtime.maxSteps`). */
|
|
21
|
+
maxSteps?: number;
|
|
22
|
+
/** Skill names preloaded (pinned) in the sub-agent. */
|
|
23
|
+
skills?: string[];
|
|
24
|
+
}
|
|
25
|
+
/** Limits of agent templates. */
|
|
26
|
+
export declare const AGENT_TEMPLATE_LIMITS: {
|
|
27
|
+
/** Characters of the body (instructions). */
|
|
28
|
+
readonly bodyChars: 100000;
|
|
29
|
+
readonly descriptionChars: 4096;
|
|
30
|
+
/** Templates in one plugin. */
|
|
31
|
+
readonly perPlugin: 64;
|
|
32
|
+
/** Preloaded skills. */
|
|
33
|
+
readonly skills: 3;
|
|
34
|
+
/** Entries of `tools` and of `disallowedTools`. */
|
|
35
|
+
readonly tools: 200;
|
|
36
|
+
};
|
|
37
|
+
/** The name rule of a template (the catalog item name rule). */
|
|
38
|
+
export declare const AGENT_TEMPLATE_NAME_RE: RegExp;
|
|
39
|
+
/**
|
|
40
|
+
* Parses an agent template file. Returns the template, or every problem found (English, for the
|
|
41
|
+
* plugin author or an admin). Keys the format does not define are ignored. Never throws.
|
|
42
|
+
*/
|
|
43
|
+
export declare function parseAgentTemplate(text: string): {
|
|
44
|
+
template: AgentTemplate;
|
|
45
|
+
} | {
|
|
46
|
+
errors: string[];
|
|
47
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent templates (`agents/<name>.md` in a plugin; sub-agents spec §16.1): Markdown with YAML
|
|
3
|
+
* frontmatter, the body being the instructions. A template is a type an agent with the builtin
|
|
4
|
+
* `agent` tool can dispatch as a sub-agent (`<plugin>:<name>` in its roster). Used by the kernel,
|
|
5
|
+
* the packer and `capybara-plugin check`.
|
|
6
|
+
*/
|
|
7
|
+
import { readFrontmatter } from "./frontmatter.js";
|
|
8
|
+
import { isSkillName } from "./skill.js";
|
|
9
|
+
/** Limits of agent templates. */
|
|
10
|
+
export const AGENT_TEMPLATE_LIMITS = {
|
|
11
|
+
/** Characters of the body (instructions). */
|
|
12
|
+
bodyChars: 100_000,
|
|
13
|
+
descriptionChars: 4096,
|
|
14
|
+
/** Templates in one plugin. */
|
|
15
|
+
perPlugin: 64,
|
|
16
|
+
/** Preloaded skills. */
|
|
17
|
+
skills: 3,
|
|
18
|
+
/** Entries of `tools` and of `disallowedTools`. */
|
|
19
|
+
tools: 200,
|
|
20
|
+
};
|
|
21
|
+
/** The name rule of a template (the catalog item name rule). */
|
|
22
|
+
export const AGENT_TEMPLATE_NAME_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
23
|
+
const TIERS = ["inherit", "fast", "standard", "capable"];
|
|
24
|
+
const EFFORTS = ["low", "medium", "high", "xhigh", "max"];
|
|
25
|
+
const FRONTMATTER_MAX_CHARS = 64 * 1024;
|
|
26
|
+
/** The kernel's tool key rule (model-visible keys): no dots, no whitespace, at most 64 chars. */
|
|
27
|
+
const TOOL_KEY_RE = /^[a-zA-Z0-9_-]{1,64}$/;
|
|
28
|
+
const chars = (s) => [...s].length;
|
|
29
|
+
const isToolKey = (v) => typeof v === "string" && TOOL_KEY_RE.test(v);
|
|
30
|
+
const toolList = (v) => Array.isArray(v) &&
|
|
31
|
+
v.length <= AGENT_TEMPLATE_LIMITS.tools &&
|
|
32
|
+
v.every(isToolKey) &&
|
|
33
|
+
new Set(v).size === v.length;
|
|
34
|
+
const toolListRule = `a list of at most ${AGENT_TEMPLATE_LIMITS.tools} distinct tool keys (letters, digits, _ and -, up to 64 characters)`;
|
|
35
|
+
/**
|
|
36
|
+
* Parses an agent template file. Returns the template, or every problem found (English, for the
|
|
37
|
+
* plugin author or an admin). Keys the format does not define are ignored. Never throws.
|
|
38
|
+
*/
|
|
39
|
+
export function parseAgentTemplate(text) {
|
|
40
|
+
const read = readFrontmatter(text, "an agent template", FRONTMATTER_MAX_CHARS);
|
|
41
|
+
if ("errors" in read)
|
|
42
|
+
return read;
|
|
43
|
+
const { frontmatter: fm, body } = read;
|
|
44
|
+
const errors = [];
|
|
45
|
+
const L = AGENT_TEMPLATE_LIMITS;
|
|
46
|
+
const name = fm.name;
|
|
47
|
+
if (name === undefined || name === null)
|
|
48
|
+
errors.push("name is required");
|
|
49
|
+
else if (typeof name !== "string" || !AGENT_TEMPLATE_NAME_RE.test(name)) {
|
|
50
|
+
errors.push("name must match ^[a-z0-9][a-z0-9-]{0,63}$");
|
|
51
|
+
}
|
|
52
|
+
let description = "";
|
|
53
|
+
if (fm.description === undefined || fm.description === null) {
|
|
54
|
+
errors.push("description is required");
|
|
55
|
+
}
|
|
56
|
+
else if (typeof fm.description !== "string" || fm.description.trim() === "") {
|
|
57
|
+
errors.push("description must be a non-empty string");
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
description = fm.description.trim();
|
|
61
|
+
if (chars(description) > L.descriptionChars) {
|
|
62
|
+
errors.push(`description must be at most ${L.descriptionChars} characters`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (chars(body) > L.bodyChars) {
|
|
66
|
+
errors.push(`the body (instructions) must be at most ${L.bodyChars} characters`);
|
|
67
|
+
}
|
|
68
|
+
const out = { name: name, description, instructions: body };
|
|
69
|
+
if (fm.tools !== undefined) {
|
|
70
|
+
if (toolList(fm.tools))
|
|
71
|
+
out.tools = fm.tools;
|
|
72
|
+
else
|
|
73
|
+
errors.push(`tools must be ${toolListRule}`);
|
|
74
|
+
}
|
|
75
|
+
if (fm.disallowedTools !== undefined) {
|
|
76
|
+
if (toolList(fm.disallowedTools))
|
|
77
|
+
out.disallowedTools = fm.disallowedTools;
|
|
78
|
+
else
|
|
79
|
+
errors.push(`disallowedTools must be ${toolListRule}`);
|
|
80
|
+
}
|
|
81
|
+
if (fm.toolPolicies !== undefined) {
|
|
82
|
+
const p = fm.toolPolicies;
|
|
83
|
+
const ok = p !== null &&
|
|
84
|
+
typeof p === "object" &&
|
|
85
|
+
!Array.isArray(p) &&
|
|
86
|
+
Object.keys(p).length <= L.tools &&
|
|
87
|
+
Object.entries(p).every(([k, v]) => isToolKey(k) && (v === "ask" || v === "deny"));
|
|
88
|
+
if (ok)
|
|
89
|
+
out.toolPolicies = { ...p };
|
|
90
|
+
else
|
|
91
|
+
errors.push("toolPolicies must map tool keys to ask or deny");
|
|
92
|
+
}
|
|
93
|
+
if (fm.model !== undefined) {
|
|
94
|
+
if (TIERS.includes(fm.model))
|
|
95
|
+
out.model = fm.model;
|
|
96
|
+
else
|
|
97
|
+
errors.push(`model must be one of ${TIERS.join(", ")}`);
|
|
98
|
+
}
|
|
99
|
+
if (fm.effort !== undefined) {
|
|
100
|
+
if (EFFORTS.includes(fm.effort)) {
|
|
101
|
+
out.effort = fm.effort;
|
|
102
|
+
}
|
|
103
|
+
else
|
|
104
|
+
errors.push(`effort must be one of ${EFFORTS.join(", ")}`);
|
|
105
|
+
}
|
|
106
|
+
if (fm.maxSteps !== undefined) {
|
|
107
|
+
if (Number.isInteger(fm.maxSteps) && fm.maxSteps >= 1) {
|
|
108
|
+
out.maxSteps = fm.maxSteps;
|
|
109
|
+
}
|
|
110
|
+
else
|
|
111
|
+
errors.push("maxSteps must be an integer of at least 1");
|
|
112
|
+
}
|
|
113
|
+
if (fm.skills !== undefined) {
|
|
114
|
+
const s = fm.skills;
|
|
115
|
+
if (Array.isArray(s) && s.length <= L.skills && s.every(isSkillName))
|
|
116
|
+
out.skills = s;
|
|
117
|
+
else
|
|
118
|
+
errors.push(`skills must list at most ${L.skills} skill names`);
|
|
119
|
+
}
|
|
120
|
+
if (errors.length > 0)
|
|
121
|
+
return { errors };
|
|
122
|
+
return { template: out };
|
|
123
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* The bootstrap manifest `packages/kernel/bootstrap.json` (package ecosystem spec §7): the plugins
|
|
4
|
+
* a deployment installs at init, each pinned to an exact version and the sha512 of its tgz. The
|
|
5
|
+
* bootstrap step verifies every tgz against `integrity` before reading it.
|
|
6
|
+
*
|
|
7
|
+
* Two entry kinds: `source: "npm"` (the published package; the official `marketplace` commit is then
|
|
8
|
+
* required, and `check:bootstrap` compares the entries with it) and `source: "workspace"` (until
|
|
9
|
+
* the official plugins are published: `path` is packed with `packages/plugin-tools`, which is
|
|
10
|
+
* byte-reproducible, and `integrity` is that pack's sha512).
|
|
11
|
+
*
|
|
12
|
+
* Objects are strict (unknown keys rejected, `$schema` allowed): the manifest ships with core, so
|
|
13
|
+
* there is no older reader to stay compatible with and a misspelt key is a mistake. The committed
|
|
14
|
+
* JSON Schema (`schemas/bootstrap.v1.schema.json`) is generated from {@link BootstrapManifestSchema}
|
|
15
|
+
* by `pnpm gen:package-schemas`; the cross-field rules (unique names, `marketplace` required with an
|
|
16
|
+
* npm entry) are decided only by {@link parseBootstrapManifest}.
|
|
17
|
+
*/
|
|
18
|
+
/** Manifest format version. */
|
|
19
|
+
export declare const BOOTSTRAP_MANIFEST_SCHEMA_VERSION = 1;
|
|
20
|
+
/** One pinned plugin. */
|
|
21
|
+
export type BootstrapEntry = {
|
|
22
|
+
/** Catalog item name (`^[a-z0-9][a-z0-9-]{0,63}$`). */
|
|
23
|
+
name: string;
|
|
24
|
+
source: "npm";
|
|
25
|
+
/** npm package name. */
|
|
26
|
+
npm: string;
|
|
27
|
+
/** Exact semver. */
|
|
28
|
+
version: string;
|
|
29
|
+
/** `sha512-<base64>` of the package tgz. */
|
|
30
|
+
integrity: string;
|
|
31
|
+
/** Enabled in every org and neither disableable nor uninstallable. */
|
|
32
|
+
required: boolean;
|
|
33
|
+
} | {
|
|
34
|
+
name: string;
|
|
35
|
+
source: "workspace";
|
|
36
|
+
/** `plugins/<dir>`, relative to the repository root. */
|
|
37
|
+
path: string;
|
|
38
|
+
version: string;
|
|
39
|
+
integrity: string;
|
|
40
|
+
required: boolean;
|
|
41
|
+
};
|
|
42
|
+
/** `bootstrap.json`. */
|
|
43
|
+
export interface BootstrapManifest {
|
|
44
|
+
$schema?: string;
|
|
45
|
+
schemaVersion: 1;
|
|
46
|
+
/** The official marketplace commit the npm entries are checked against; required with npm entries. */
|
|
47
|
+
marketplace?: {
|
|
48
|
+
url: string;
|
|
49
|
+
commit: string;
|
|
50
|
+
};
|
|
51
|
+
/** Names are unique. */
|
|
52
|
+
plugins: BootstrapEntry[];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The zod schema of `bootstrap.json` (strict objects). The JSON Schema is generated with
|
|
56
|
+
* `z.toJSONSchema(BootstrapManifestSchema, { io: "input" })`.
|
|
57
|
+
*/
|
|
58
|
+
export declare const BootstrapManifestSchema: z.ZodType<BootstrapManifest>;
|
|
59
|
+
/**
|
|
60
|
+
* Validates and parses `bootstrap.json`. Invalid input returns `{ errors }` (`<path>: <reason>`, at
|
|
61
|
+
* most 50); never throws.
|
|
62
|
+
*/
|
|
63
|
+
export declare function parseBootstrapManifest(json: unknown): BootstrapManifest | {
|
|
64
|
+
errors: string[];
|
|
65
|
+
};
|
|
66
|
+
/** The file name of an entry's tgz in the bootstrap directory: `<name>-<version>.tgz`. */
|
|
67
|
+
export declare function bootstrapFileName(e: BootstrapEntry): string;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { CATALOG_ITEM_NAME_RE, NPM_PACKAGE_NAME_RE, SEMVER_VERSION_RE, SHA512_INTEGRITY_RE, } from "./plugin-package.js";
|
|
3
|
+
/**
|
|
4
|
+
* The bootstrap manifest `packages/kernel/bootstrap.json` (package ecosystem spec §7): the plugins
|
|
5
|
+
* a deployment installs at init, each pinned to an exact version and the sha512 of its tgz. The
|
|
6
|
+
* bootstrap step verifies every tgz against `integrity` before reading it.
|
|
7
|
+
*
|
|
8
|
+
* Two entry kinds: `source: "npm"` (the published package; the official `marketplace` commit is then
|
|
9
|
+
* required, and `check:bootstrap` compares the entries with it) and `source: "workspace"` (until
|
|
10
|
+
* the official plugins are published: `path` is packed with `packages/plugin-tools`, which is
|
|
11
|
+
* byte-reproducible, and `integrity` is that pack's sha512).
|
|
12
|
+
*
|
|
13
|
+
* Objects are strict (unknown keys rejected, `$schema` allowed): the manifest ships with core, so
|
|
14
|
+
* there is no older reader to stay compatible with and a misspelt key is a mistake. The committed
|
|
15
|
+
* JSON Schema (`schemas/bootstrap.v1.schema.json`) is generated from {@link BootstrapManifestSchema}
|
|
16
|
+
* by `pnpm gen:package-schemas`; the cross-field rules (unique names, `marketplace` required with an
|
|
17
|
+
* npm entry) are decided only by {@link parseBootstrapManifest}.
|
|
18
|
+
*/
|
|
19
|
+
/** Manifest format version. */
|
|
20
|
+
export const BOOTSTRAP_MANIFEST_SCHEMA_VERSION = 1;
|
|
21
|
+
const MAX_ERRORS = 50;
|
|
22
|
+
const URL_CHARS = 2000;
|
|
23
|
+
const COMMIT_RE = /^[0-9a-f]{40}$/;
|
|
24
|
+
const HTTPS_URL_RE = /^https:\/\/\S+$/;
|
|
25
|
+
const WORKSPACE_PATH_RE = /^plugins\/[a-z0-9][a-z0-9-]{0,63}$/;
|
|
26
|
+
const common = {
|
|
27
|
+
name: z
|
|
28
|
+
.string()
|
|
29
|
+
.regex(CATALOG_ITEM_NAME_RE, { message: "name must match ^[a-z0-9][a-z0-9-]{0,63}$" }),
|
|
30
|
+
version: z
|
|
31
|
+
.string()
|
|
32
|
+
.max(256)
|
|
33
|
+
.regex(SEMVER_VERSION_RE, { message: "version must be an exact semver version" }),
|
|
34
|
+
integrity: z
|
|
35
|
+
.string()
|
|
36
|
+
.regex(SHA512_INTEGRITY_RE, { message: "integrity must be sha512-<86 base64 chars>==" }),
|
|
37
|
+
required: z.boolean(),
|
|
38
|
+
};
|
|
39
|
+
const entry = z.discriminatedUnion("source", [
|
|
40
|
+
z.strictObject({
|
|
41
|
+
...common,
|
|
42
|
+
source: z.literal("npm"),
|
|
43
|
+
npm: z
|
|
44
|
+
.string()
|
|
45
|
+
.max(214)
|
|
46
|
+
.regex(NPM_PACKAGE_NAME_RE, { message: "npm must be an npm package name" }),
|
|
47
|
+
}),
|
|
48
|
+
z.strictObject({
|
|
49
|
+
...common,
|
|
50
|
+
source: z.literal("workspace"),
|
|
51
|
+
path: z.string().regex(WORKSPACE_PATH_RE, { message: "path must be plugins/<dir>" }),
|
|
52
|
+
}),
|
|
53
|
+
]);
|
|
54
|
+
const schema = z
|
|
55
|
+
.strictObject({
|
|
56
|
+
$schema: z.string().max(URL_CHARS).optional(),
|
|
57
|
+
schemaVersion: z.literal(BOOTSTRAP_MANIFEST_SCHEMA_VERSION),
|
|
58
|
+
marketplace: z
|
|
59
|
+
.strictObject({
|
|
60
|
+
url: z.string().max(URL_CHARS).regex(HTTPS_URL_RE, { message: "url must be an https URL" }),
|
|
61
|
+
commit: z.string().regex(COMMIT_RE, { message: "commit must be 40 hex characters" }),
|
|
62
|
+
})
|
|
63
|
+
.optional(),
|
|
64
|
+
plugins: z.array(entry).max(500),
|
|
65
|
+
})
|
|
66
|
+
.superRefine((m, ctx) => {
|
|
67
|
+
const seen = new Set();
|
|
68
|
+
m.plugins.forEach((e, i) => {
|
|
69
|
+
if (seen.has(e.name)) {
|
|
70
|
+
ctx.addIssue({
|
|
71
|
+
code: "custom",
|
|
72
|
+
path: ["plugins", i, "name"],
|
|
73
|
+
message: `duplicate entry ${e.name}`,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
seen.add(e.name);
|
|
77
|
+
});
|
|
78
|
+
if (m.marketplace === undefined && m.plugins.some((e) => e.source === "npm")) {
|
|
79
|
+
ctx.addIssue({
|
|
80
|
+
code: "custom",
|
|
81
|
+
path: ["marketplace"],
|
|
82
|
+
message: 'required when an entry has source "npm"',
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
/**
|
|
87
|
+
* The zod schema of `bootstrap.json` (strict objects). The JSON Schema is generated with
|
|
88
|
+
* `z.toJSONSchema(BootstrapManifestSchema, { io: "input" })`.
|
|
89
|
+
*/
|
|
90
|
+
export const BootstrapManifestSchema = schema;
|
|
91
|
+
/**
|
|
92
|
+
* Validates and parses `bootstrap.json`. Invalid input returns `{ errors }` (`<path>: <reason>`, at
|
|
93
|
+
* most 50); never throws.
|
|
94
|
+
*/
|
|
95
|
+
export function parseBootstrapManifest(json) {
|
|
96
|
+
const r = BootstrapManifestSchema.safeParse(json);
|
|
97
|
+
if (r.success)
|
|
98
|
+
return r.data;
|
|
99
|
+
return {
|
|
100
|
+
errors: r.error.issues.slice(0, MAX_ERRORS).map((i) => {
|
|
101
|
+
const path = i.path.map(String).join(".");
|
|
102
|
+
return path ? `${path}: ${i.message}` : i.message;
|
|
103
|
+
}),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** The file name of an entry's tgz in the bootstrap directory: `<name>-<version>.tgz`. */
|
|
107
|
+
export function bootstrapFileName(e) {
|
|
108
|
+
return `${e.name}-${e.version}.tgz`;
|
|
109
|
+
}
|
package/dist/cards.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type FormAnswer, type InputForm } from "./tool.js";
|
|
2
|
+
/**
|
|
3
|
+
* 渠道中立的 IM 卡片:由内核定义与产出,渠道插件按各自 IM 的原生格式渲染;
|
|
4
|
+
* 不支持卡片的渠道用 {@link renderCardAsText} 退回为文本。
|
|
5
|
+
*/
|
|
6
|
+
export type ChannelCard = {
|
|
7
|
+
kind: "approval";
|
|
8
|
+
id: string;
|
|
9
|
+
title: string;
|
|
10
|
+
toolName: string;
|
|
11
|
+
appName?: string;
|
|
12
|
+
agentName: string;
|
|
13
|
+
inputPreview: string;
|
|
14
|
+
scopes: ("once" | "session" | "always")[];
|
|
15
|
+
expiresAt: string;
|
|
16
|
+
state: "pending" | "approved" | "denied" | "expired" | "cancelled";
|
|
17
|
+
decidedBy?: string;
|
|
18
|
+
/** A denied approval: the reason the person gave (plain text, never formatted). */
|
|
19
|
+
denyReason?: string;
|
|
20
|
+
/** 可决定该审批的会话网页链接。 */
|
|
21
|
+
webUrl: string;
|
|
22
|
+
} | {
|
|
23
|
+
kind: "question";
|
|
24
|
+
id: string;
|
|
25
|
+
form: InputForm;
|
|
26
|
+
state: "pending" | "answered" | "expired" | "cancelled";
|
|
27
|
+
answerSummary?: string;
|
|
28
|
+
webUrl: string;
|
|
29
|
+
} | {
|
|
30
|
+
kind: "connect";
|
|
31
|
+
appName: string;
|
|
32
|
+
url: string;
|
|
33
|
+
} | {
|
|
34
|
+
kind: "bind";
|
|
35
|
+
url: string;
|
|
36
|
+
text: string;
|
|
37
|
+
};
|
|
38
|
+
/** 用户在 IM 卡片上的操作,由渠道插件解析后经入站事件交给内核。 */
|
|
39
|
+
export interface CardAction {
|
|
40
|
+
cardKind: "approval" | "question";
|
|
41
|
+
cardId: string;
|
|
42
|
+
action: "approve" | "deny" | "answer";
|
|
43
|
+
scope?: "once" | "session" | "always";
|
|
44
|
+
answer?: FormAnswer;
|
|
45
|
+
}
|
|
46
|
+
/** 发往 IM 的一条消息:text 为 Markdown(渠道插件转换为原生富文本),可附卡片。 */
|
|
47
|
+
export interface OutboundMessage {
|
|
48
|
+
text: string;
|
|
49
|
+
cards?: ChannelCard[];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 提问能否在 IM 内直接作答:仅当表单恰有一个枚举字段(单选 ≤ 5 项 / 多选 ≤ 10 项)且不允许「其他」时为真;
|
|
53
|
+
* 否则卡片只给网页链接。
|
|
54
|
+
*/
|
|
55
|
+
export declare function questionRenderableInline(form: InputForm): boolean;
|
|
56
|
+
/** 校验卡片结构,返回问题列表(空 = 合法)。 */
|
|
57
|
+
export declare function validateChannelCard(card: unknown): string[];
|
|
58
|
+
/** A UI locale. */
|
|
59
|
+
export type Locale = "zh" | "en";
|
|
60
|
+
/**
|
|
61
|
+
* 不支持卡片的渠道的统一退回文本(含链接);固定话术按 locale 取 zh / en。结果是 Markdown(放进
|
|
62
|
+
* `OutboundMessage.text`,由渠道插件转换):模型可控的字段放在代码里(见 `asCode`),不会产生链接。
|
|
63
|
+
*/
|
|
64
|
+
export declare function renderCardAsText(card: ChannelCard, locale: Locale): string;
|