@agentproto/app-kit 0.2.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/README.md +142 -0
- package/dist/define-app.d.ts +26 -0
- package/dist/define-app.d.ts.map +1 -0
- package/dist/emit.d.ts +33 -0
- package/dist/emit.d.ts.map +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +182 -0
- package/dist/index.mjs.map +1 -0
- package/dist/refs.d.ts +11 -0
- package/dist/refs.d.ts.map +1 -0
- package/dist/types.d.ts +132 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +71 -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/README.md
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# @agentproto/app-kit
|
|
2
|
+
|
|
3
|
+
Declare one or more **agents** (with their system prompts) and the **workflows**
|
|
4
|
+
they run in one TypeScript module, then import them anywhere.
|
|
5
|
+
|
|
6
|
+
A thin umbrella over AIP-42 [`defineAgent`](../agent) + AIP-15
|
|
7
|
+
[`defineWorkflow`](../workflow). It doesn't re-validate their fields — those ran
|
|
8
|
+
when you built the handles — it validates the *coupling* and gives you two ways
|
|
9
|
+
to consume the bundle: runnable Mastra agents, or emitted `.md` manifests.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { defineApp } from "@agentproto/app-kit"
|
|
13
|
+
import { defineAgent } from "@agentproto/agent"
|
|
14
|
+
import { defineWorkflow } from "@agentproto/workflow"
|
|
15
|
+
|
|
16
|
+
export const reviewApp = defineApp({
|
|
17
|
+
agents: [
|
|
18
|
+
{
|
|
19
|
+
agent: defineAgent({
|
|
20
|
+
schema: "agent/v1",
|
|
21
|
+
id: "@agentik/reviewer",
|
|
22
|
+
description: "Reviews a PR diff and reports findings.",
|
|
23
|
+
model: "claude-sonnet-5",
|
|
24
|
+
boundaries: ["Never run gh pr merge"],
|
|
25
|
+
workflows: [{ ref: "review-and-fix" }], // ← must match a bundled workflow
|
|
26
|
+
}),
|
|
27
|
+
body: `You are a rigorous PR reviewer. Report findings; change nothing.`,
|
|
28
|
+
},
|
|
29
|
+
// body optional — omit it and the prompt composes from the agent's
|
|
30
|
+
// persona / boundaries / traits.
|
|
31
|
+
{ agent: defineAgent({ schema: "agent/v1", id: "fixer", description: "Applies fixes.", model: "claude-sonnet-5", workflows: [{ ref: "review-and-fix" }] }) },
|
|
32
|
+
],
|
|
33
|
+
workflows: [
|
|
34
|
+
defineWorkflow({
|
|
35
|
+
id: "review-and-fix",
|
|
36
|
+
name: "Review and fix",
|
|
37
|
+
description: "Read the diff, report findings.",
|
|
38
|
+
version: "0.1.0",
|
|
39
|
+
inputs: {},
|
|
40
|
+
outputs: {},
|
|
41
|
+
steps: [{ id: "review", kind: "tool", tool: "read_diff" }],
|
|
42
|
+
}),
|
|
43
|
+
],
|
|
44
|
+
attach: [ /* any AIP handle: AIP-6 company, AIP-25 persona, AIP-47 role, policy… */ ],
|
|
45
|
+
workspace: { // ← optional home workspace (AIP-34)
|
|
46
|
+
id: "@acme/reviewers",
|
|
47
|
+
name: "Acme Reviewers",
|
|
48
|
+
owner: { type: "guild", id: "guild_123", slug: "acme" }, // = the tenant
|
|
49
|
+
// storage defaults to { inline: { provider: "local-fs", config: {} } }
|
|
50
|
+
},
|
|
51
|
+
})
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## The tenant + local storage — it's the workspace, not a folder
|
|
55
|
+
|
|
56
|
+
An app can declare a home **`workspace`** (AIP-34 `WORKSPACE.md`). Reuse it
|
|
57
|
+
instead of inventing tenant folders, because AIP-34/35 already model both axes:
|
|
58
|
+
|
|
59
|
+
- **Tenant** = the workspace's `owner` — `{ type: "guild" | "user" | "org", id, slug }`.
|
|
60
|
+
Not a `tenants/<t>/` path segment; an identity on the manifest.
|
|
61
|
+
- **Local storage** = the AIP-35 `storage` block — `provider: "local-fs"` (also
|
|
62
|
+
`dev-local`, `local-ide`, `github`, `mastra-s3`, …). Defaults to `local-fs`.
|
|
63
|
+
|
|
64
|
+
Pass either a `{ id, name, owner, storage? }` **shorthand** (completed with a
|
|
65
|
+
local-fs default + validated by `defineWorkspace`) or a pre-built
|
|
66
|
+
[`defineWorkspace`](../workspace) handle. This is the same workspace model Guilde
|
|
67
|
+
already uses — a guild's `system` workspace mounted at `/.guilde` holding its
|
|
68
|
+
operator / role / skill definitions.
|
|
69
|
+
|
|
70
|
+
## Where is the system prompt? — it's the `body`
|
|
71
|
+
|
|
72
|
+
There is **no `systemPrompt` field anywhere in AIP**. An AGENT.md is
|
|
73
|
+
*frontmatter (metadata) + body (the prompt)*, and the frontmatter schema is
|
|
74
|
+
`.strict()` — so `defineAgent` structurally cannot hold prose. The prompt is the
|
|
75
|
+
**body**, and it's optional: omit it and the prompt composes from the agent's
|
|
76
|
+
`persona` (AIP-25), `boundaries`, and `traits` — the same way Guilde assembles an
|
|
77
|
+
operator's prompt from AIP-47 role instructions + persona rather than a stored
|
|
78
|
+
string. `composeInstructions` (in [`@agentproto/mastra`](../mastra)) is the
|
|
79
|
+
assembler.
|
|
80
|
+
|
|
81
|
+
## The attachment invariant
|
|
82
|
+
|
|
83
|
+
`defineApp` enforces the coupling: agent ids are unique; every `agent.workflows[]`
|
|
84
|
+
ref must resolve to a bundled workflow; every bundled workflow must be referenced
|
|
85
|
+
by at least one agent. A dangling ref or an orphan workflow throws
|
|
86
|
+
`AppDefinitionError`. `attach` carries any other AIP handle verbatim (structural
|
|
87
|
+
`{ id }`), so a company, persona, or role rides along without app-kit depending
|
|
88
|
+
on each doctype package.
|
|
89
|
+
|
|
90
|
+
## Consuming a bundle
|
|
91
|
+
|
|
92
|
+
### `handle.toMastraAgents(resolvers)` — run them
|
|
93
|
+
|
|
94
|
+
Builds every agent, keyed by id, turning each `body` into a **real Mastra
|
|
95
|
+
`instructions` field** via [`@agentproto/mastra`](../mastra). You supply the
|
|
96
|
+
resolvers (model, tools, memory…).
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
const built = await reviewApp.toMastraAgents({ resolveModel: (ref) => registry.resolve(ref) })
|
|
100
|
+
built["@agentik/reviewer"].agent // a runnable Mastra Agent
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**Use just some of a team.** Pass `only` to build a subset instead of the whole
|
|
104
|
+
app — so a host doesn't pay to build agents it won't run. Unknown ids throw.
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
const built = await reviewApp.toMastraAgents({ resolveModel }, ["@agentik/reviewer"])
|
|
108
|
+
const [reviewer] = reviewApp.pick(["@agentik/reviewer"]) // select without building
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`handle.toMastraAgent(resolvers)` is a convenience for single-agent apps (throws
|
|
112
|
+
if the app has more than one). `@mastra/core` is a **peer dependency** — install
|
|
113
|
+
it in the host if you call either. `emit` has no Mastra dependency.
|
|
114
|
+
|
|
115
|
+
### `handle.emit(dir)` — ship them
|
|
116
|
+
|
|
117
|
+
Writes the manifests under an **agentproto-owned base** — it doesn't squat the
|
|
118
|
+
shared root `.agents/` convention:
|
|
119
|
+
|
|
120
|
+
```
|
|
121
|
+
<dir>/WORKSPACE.md (AIP-34 root manifest — only when the app has a workspace)
|
|
122
|
+
<dir>/.agentproto/agents/reviewer/AGENT.md
|
|
123
|
+
<dir>/.agentproto/agents/fixer/AGENT.md
|
|
124
|
+
<dir>/.agentproto/workflows/review-and-fix/WORKFLOW.md (shared — a workflow may be run by several agents)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The daemon's state root is migrating toward a `tenants/<t>/…` segment
|
|
128
|
+
(AIP-46 / DESIGN.md §9); app-kit will add that segment once the daemon's tenant
|
|
129
|
+
layer lands, rather than inventing the shape ahead of it.
|
|
130
|
+
|
|
131
|
+
Both are plain markdown: frontmatter = the validated handle, body = the agent's
|
|
132
|
+
`body` (AGENT.md) / the workflow description (WORKFLOW.md). Because a
|
|
133
|
+
`defineWorkflow` handle is pure data, the `WORKFLOW.md` needs no `entry:` module —
|
|
134
|
+
the manifest *is* the workflow, so `loadWorkflowHandle` returns it directly.
|
|
135
|
+
|
|
136
|
+
## Runtime note
|
|
137
|
+
|
|
138
|
+
`toMastraAgents` is the path where a `body` becomes a **true** model
|
|
139
|
+
`instructions` field, because that wiring lives in the mastra adapter. The
|
|
140
|
+
generic daemon session-spawn has no system-prompt field today (instructions ride
|
|
141
|
+
in as prepended prompt text for CLI adapters), so an emitted AGENT.md reaches the
|
|
142
|
+
model as a real system prompt only through a mastra-family runtime.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `defineApp({ agents, workflows, attach })` — bundle one or more AIP-42
|
|
3
|
+
* agents, the AIP-15 workflows they run, and any other AIP artifacts into
|
|
4
|
+
* one cross-linked, frozen handle.
|
|
5
|
+
*
|
|
6
|
+
* The only new invariant app-kit adds is *attachment*: the agents and the
|
|
7
|
+
* bundled workflows must reference each other. Everything else (field
|
|
8
|
+
* validation) already ran when the caller built the handles with
|
|
9
|
+
* `defineAgent` / `defineWorkflow`, so `defineApp` validates the coupling,
|
|
10
|
+
* not the fields.
|
|
11
|
+
*
|
|
12
|
+
* - agent ids are unique within the app.
|
|
13
|
+
* - every `agent.workflows[]` ref MUST resolve to a bundled workflow id.
|
|
14
|
+
* - every bundled workflow MUST be referenced by at least one agent.
|
|
15
|
+
*
|
|
16
|
+
* A dangling ref (an agent points at a workflow the app didn't bundle) or
|
|
17
|
+
* an orphan (a bundled workflow no agent lists) throws — that is what "an
|
|
18
|
+
* agent attached to its workflows" means, made checkable.
|
|
19
|
+
*/
|
|
20
|
+
import type { AppDefinition, AppHandle, DoctypeHandle } from "./types.js";
|
|
21
|
+
export declare class AppDefinitionError extends Error {
|
|
22
|
+
constructor(message: string);
|
|
23
|
+
}
|
|
24
|
+
export declare function defineApp(def: AppDefinition): AppHandle;
|
|
25
|
+
export type { DoctypeHandle };
|
|
26
|
+
//# sourceMappingURL=define-app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-app.d.ts","sourceRoot":"","sources":["../src/define-app.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAOH,OAAO,KAAK,EAEV,aAAa,EACb,SAAS,EACT,aAAa,EAGd,MAAM,YAAY,CAAA;AAInB,qBAAa,kBAAmB,SAAQ,KAAK;gBAC/B,OAAO,EAAE,MAAM;CAI5B;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,aAAa,GAAG,SAAS,CAqDvD;AA8GD,YAAY,EAAE,aAAa,EAAE,CAAA"}
|
package/dist/emit.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `emitApp(app, dir)` — write an app's agents + workflows to disk under an
|
|
3
|
+
* agentproto-owned base, so the manifests don't squat the shared root
|
|
4
|
+
* `.agents/` convention:
|
|
5
|
+
*
|
|
6
|
+
* <dir>/WORKSPACE.md (when the app has a
|
|
7
|
+
* workspace — AIP-34 root
|
|
8
|
+
* manifest; owner = tenant)
|
|
9
|
+
* <dir>/.agentproto/agents/<id>/AGENT.md (one per agent)
|
|
10
|
+
* <dir>/.agentproto/workflows/<wf.id>/WORKFLOW.md (shared — a workflow may
|
|
11
|
+
* be run by several agents)
|
|
12
|
+
*
|
|
13
|
+
* The "tenant" isn't a `tenants/<t>/…` path segment — it's the `owner` of
|
|
14
|
+
* the AIP-34 WORKSPACE.md (guild / user / org), and local storage is its
|
|
15
|
+
* AIP-35 `storage` block. So there is no bespoke tenant folder to invent.
|
|
16
|
+
*
|
|
17
|
+
* Both are plain markdown manifests: frontmatter = the validated handle,
|
|
18
|
+
* body = the agent's `body` (its system prompt) or the workflow description.
|
|
19
|
+
* Because a `defineWorkflow` handle is pure data, the WORKFLOW.md needs no
|
|
20
|
+
* `entry:` module — the manifest *is* the workflow, so `loadWorkflowHandle`
|
|
21
|
+
* returns it directly with nothing to reconcile against.
|
|
22
|
+
*/
|
|
23
|
+
import type { WorkflowHandle } from "@agentproto/workflow";
|
|
24
|
+
import type { WorkspaceHandle } from "@agentproto/workspace";
|
|
25
|
+
import type { AgentEntry, EmittedApp } from "./types.js";
|
|
26
|
+
interface EmitInput {
|
|
27
|
+
readonly agents: readonly AgentEntry[];
|
|
28
|
+
readonly workflows: readonly WorkflowHandle[];
|
|
29
|
+
readonly workspace?: WorkspaceHandle;
|
|
30
|
+
}
|
|
31
|
+
export declare function emitApp(app: EmitInput, dir: string): Promise<EmittedApp>;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=emit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../src/emit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAKH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAGxD,UAAU,SAAS;IACjB,QAAQ,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,CAAA;IACtC,QAAQ,CAAC,SAAS,EAAE,SAAS,cAAc,EAAE,CAAA;IAC7C,QAAQ,CAAC,SAAS,CAAC,EAAE,eAAe,CAAA;CACrC;AAED,wBAAsB,OAAO,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAkC9E"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @agentproto/app-kit — declare one or more agents (with their system
|
|
3
|
+
* prompts) and the workflows they run in one TypeScript module, then
|
|
4
|
+
* import them anywhere.
|
|
5
|
+
*
|
|
6
|
+
* A thin umbrella over AIP-42 `defineAgent` + AIP-15 `defineWorkflow`:
|
|
7
|
+
*
|
|
8
|
+
* - `defineApp({ agents, workflows, attach })` cross-links agents and
|
|
9
|
+
* workflows (every workflow an agent lists must be bundled, and every
|
|
10
|
+
* bundled workflow must be listed by some agent), and carries any
|
|
11
|
+
* other AIP handles you `attach` (AIP-6 company, AIP-25 persona,
|
|
12
|
+
* AIP-47 role…). Returns a frozen `AppHandle`.
|
|
13
|
+
* - `handle.toMastraAgents(resolvers)` builds each agent into a Mastra
|
|
14
|
+
* agent whose `instructions` field is the real system prompt — the
|
|
15
|
+
* AGENT.md body (via `@agentproto/mastra`).
|
|
16
|
+
* - `handle.emit(dir)` writes `.agentproto/agents/<id>/AGENT.md` + shared
|
|
17
|
+
* `.agentproto/workflows/<id>/WORKFLOW.md` manifests under an
|
|
18
|
+
* agentproto-owned base (not the shared root `.agents/`), plus a root
|
|
19
|
+
* `WORKSPACE.md` when the app has a `workspace`.
|
|
20
|
+
*
|
|
21
|
+
* An app may declare a home `workspace` (AIP-34 `defineWorkspace`, or a
|
|
22
|
+
* `{ id, name, owner, storage? }` shorthand). Its `owner` is the tenant
|
|
23
|
+
* (guild / user / org) and its `storage` the backing store (defaults to
|
|
24
|
+
* local-fs) — the tenant/local-storage model AIP-34/35 already ship, so
|
|
25
|
+
* app-kit reuses it rather than inventing tenant folders.
|
|
26
|
+
*
|
|
27
|
+
* There is no `systemPrompt` field in AIP: the prompt is the AGENT.md
|
|
28
|
+
* BODY (frontmatter is `.strict()`). So each agent carries an optional
|
|
29
|
+
* `body`; omit it and the prompt composes from persona / boundaries /
|
|
30
|
+
* traits, the way Guilde assembles an operator prompt from role + persona.
|
|
31
|
+
*
|
|
32
|
+
* `@mastra/core` is a peer dependency — install it in the host if you
|
|
33
|
+
* call `toMastraAgent(s)`. `emit` has no Mastra dependency.
|
|
34
|
+
*/
|
|
35
|
+
export { defineApp, AppDefinitionError } from "./define-app.js";
|
|
36
|
+
export { emitApp } from "./emit.js";
|
|
37
|
+
export { refKey, stripOwner } from "./refs.js";
|
|
38
|
+
export type { AppDefinition, AppHandle, AgentEntry, DoctypeHandle, WorkspaceShorthand, WorkspaceInput, ToMastraAgentOptions, EmittedApp, } from "./types.js";
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC9C,YAAY,EACV,aAAa,EACb,SAAS,EACT,UAAU,EACV,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EACpB,UAAU,GACX,MAAM,YAAY,CAAA"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { buildMastraAgent } from '@agentproto/mastra';
|
|
2
|
+
import { defineWorkspace } from '@agentproto/workspace';
|
|
3
|
+
import { mkdir, writeFile } from 'fs/promises';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
import matter from 'gray-matter';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @agentproto/app-kit v0.1.0
|
|
9
|
+
* Declare an agent + its workflows in one TS module (AIP-42 + AIP-15).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
// src/refs.ts
|
|
14
|
+
function refKey(ref) {
|
|
15
|
+
if (typeof ref === "string") return ref;
|
|
16
|
+
return ref.ref ?? ref.file ?? JSON.stringify(ref.inline ?? ref);
|
|
17
|
+
}
|
|
18
|
+
function stripOwner(id) {
|
|
19
|
+
const m = id.match(/^@[^/]+\/(.+)$/);
|
|
20
|
+
return m ? m[1] : id;
|
|
21
|
+
}
|
|
22
|
+
async function emitApp(app, dir) {
|
|
23
|
+
let workspacePath;
|
|
24
|
+
if (app.workspace) {
|
|
25
|
+
await mkdir(dir, { recursive: true });
|
|
26
|
+
workspacePath = join(dir, "WORKSPACE.md");
|
|
27
|
+
await writeFile(
|
|
28
|
+
workspacePath,
|
|
29
|
+
toManifest(app.workspace, app.workspace.description ?? app.workspace.name),
|
|
30
|
+
"utf8"
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
const agentPaths = {};
|
|
34
|
+
for (const { agent, body } of app.agents) {
|
|
35
|
+
const agentDir = join(dir, ".agentproto", "agents", stripOwner(agent.id));
|
|
36
|
+
await mkdir(agentDir, { recursive: true });
|
|
37
|
+
const agentPath = join(agentDir, "AGENT.md");
|
|
38
|
+
await writeFile(agentPath, toManifest(agent, body ?? ""), "utf8");
|
|
39
|
+
agentPaths[agent.id] = agentPath;
|
|
40
|
+
}
|
|
41
|
+
const workflowPaths = [];
|
|
42
|
+
for (const wf of app.workflows) {
|
|
43
|
+
const wfDir = join(dir, ".agentproto", "workflows", wf.id);
|
|
44
|
+
await mkdir(wfDir, { recursive: true });
|
|
45
|
+
const wfPath = join(wfDir, "WORKFLOW.md");
|
|
46
|
+
await writeFile(wfPath, toManifest(wf, wf.description ?? ""), "utf8");
|
|
47
|
+
workflowPaths.push(wfPath);
|
|
48
|
+
}
|
|
49
|
+
return { agentPaths, workflowPaths, ...workspacePath ? { workspacePath } : {} };
|
|
50
|
+
}
|
|
51
|
+
function toManifest(handle, body) {
|
|
52
|
+
const data = JSON.parse(JSON.stringify(handle));
|
|
53
|
+
return matter.stringify(`
|
|
54
|
+
${body}
|
|
55
|
+
`, data);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// src/define-app.ts
|
|
59
|
+
var AppDefinitionError = class extends Error {
|
|
60
|
+
constructor(message) {
|
|
61
|
+
super(`defineApp (app-kit): ${message}`);
|
|
62
|
+
this.name = "AppDefinitionError";
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
function defineApp(def) {
|
|
66
|
+
if (!Array.isArray(def.agents) || def.agents.length === 0) {
|
|
67
|
+
throw new AppDefinitionError("`agents` must be a non-empty array.");
|
|
68
|
+
}
|
|
69
|
+
const agents = def.agents.map(normalizeEntry);
|
|
70
|
+
const workflows = def.workflows ?? [];
|
|
71
|
+
const attachments = def.attach ?? [];
|
|
72
|
+
const workspace = def.workspace ? toWorkspaceHandle(def.workspace) : void 0;
|
|
73
|
+
validateAttachment(agents, workflows);
|
|
74
|
+
const frozenAgents = Object.freeze(agents.map((e) => Object.freeze({ ...e })));
|
|
75
|
+
const frozenWorkflows = Object.freeze([...workflows]);
|
|
76
|
+
const frozenAttachments = Object.freeze([...attachments]);
|
|
77
|
+
const handle = {
|
|
78
|
+
agents: frozenAgents,
|
|
79
|
+
workflows: frozenWorkflows,
|
|
80
|
+
attachments: frozenAttachments,
|
|
81
|
+
...workspace ? { workspace } : {},
|
|
82
|
+
async toMastraAgents(opts, only) {
|
|
83
|
+
const targets = only ? selectAgents(frozenAgents, only) : frozenAgents;
|
|
84
|
+
const out = {};
|
|
85
|
+
for (const entry of targets) {
|
|
86
|
+
out[entry.agent.id] = await buildOne(entry, opts);
|
|
87
|
+
}
|
|
88
|
+
return out;
|
|
89
|
+
},
|
|
90
|
+
pick(ids) {
|
|
91
|
+
return selectAgents(frozenAgents, ids);
|
|
92
|
+
},
|
|
93
|
+
async toMastraAgent(opts) {
|
|
94
|
+
if (frozenAgents.length !== 1) {
|
|
95
|
+
throw new AppDefinitionError(
|
|
96
|
+
`toMastraAgent requires exactly one agent (app has ${frozenAgents.length}); use toMastraAgents.`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
return buildOne(frozenAgents[0], opts);
|
|
100
|
+
},
|
|
101
|
+
emit(dir) {
|
|
102
|
+
return emitApp(
|
|
103
|
+
{ agents: frozenAgents, workflows: frozenWorkflows, ...workspace ? { workspace } : {} },
|
|
104
|
+
dir
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
return Object.freeze(handle);
|
|
109
|
+
}
|
|
110
|
+
function toWorkspaceHandle(input) {
|
|
111
|
+
if ("schema" in input) return input;
|
|
112
|
+
return defineWorkspace({
|
|
113
|
+
schema: "workspace/v1",
|
|
114
|
+
version: input.version ?? "0.1.0",
|
|
115
|
+
id: input.id,
|
|
116
|
+
name: input.name,
|
|
117
|
+
owner: input.owner,
|
|
118
|
+
storage: input.storage ?? { inline: { provider: "local-fs", config: {} } },
|
|
119
|
+
...input.description ? { description: input.description } : {}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function selectAgents(agents, ids) {
|
|
123
|
+
const byId = new Map(agents.map((e) => [e.agent.id, e]));
|
|
124
|
+
return ids.map((id) => {
|
|
125
|
+
const entry = byId.get(id);
|
|
126
|
+
if (!entry) {
|
|
127
|
+
throw new AppDefinitionError(
|
|
128
|
+
`agent '${id}' is not in this app. Bundled: [${[...byId.keys()].join(", ")}].`
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
return entry;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
function buildOne(entry, opts) {
|
|
135
|
+
return buildMastraAgent(entry.agent, { body: entry.body, ...opts });
|
|
136
|
+
}
|
|
137
|
+
function normalizeEntry(input) {
|
|
138
|
+
if ("agent" in input) return input;
|
|
139
|
+
return { agent: input };
|
|
140
|
+
}
|
|
141
|
+
function validateAttachment(agents, workflows) {
|
|
142
|
+
const seenAgentIds = /* @__PURE__ */ new Set();
|
|
143
|
+
for (const { agent } of agents) {
|
|
144
|
+
if (seenAgentIds.has(agent.id)) {
|
|
145
|
+
throw new AppDefinitionError(`duplicate agent id '${agent.id}' in the bundle.`);
|
|
146
|
+
}
|
|
147
|
+
seenAgentIds.add(agent.id);
|
|
148
|
+
}
|
|
149
|
+
const bundledIds = /* @__PURE__ */ new Set();
|
|
150
|
+
for (const wf of workflows) {
|
|
151
|
+
if (bundledIds.has(wf.id)) {
|
|
152
|
+
throw new AppDefinitionError(`duplicate workflow id '${wf.id}' in the bundle.`);
|
|
153
|
+
}
|
|
154
|
+
bundledIds.add(wf.id);
|
|
155
|
+
}
|
|
156
|
+
const referenced = /* @__PURE__ */ new Set();
|
|
157
|
+
for (const { agent } of agents) {
|
|
158
|
+
for (const ref of workflowRefs(agent)) {
|
|
159
|
+
const key = refKey(ref);
|
|
160
|
+
referenced.add(key);
|
|
161
|
+
if (!bundledIds.has(key)) {
|
|
162
|
+
throw new AppDefinitionError(
|
|
163
|
+
`agent '${agent.id}' references workflow '${key}' but the app does not bundle it. Bundled: [${[...bundledIds].join(", ") || "none"}].`
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
for (const id of bundledIds) {
|
|
169
|
+
if (!referenced.has(id)) {
|
|
170
|
+
throw new AppDefinitionError(
|
|
171
|
+
`workflow '${id}' is bundled but no agent lists it in workflows[]. Add { ref: "${id}" } to an agent, or drop the workflow.`
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function workflowRefs(agent) {
|
|
177
|
+
return agent.workflows ?? [];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export { AppDefinitionError, defineApp, emitApp, refKey, stripOwner };
|
|
181
|
+
//# sourceMappingURL=index.mjs.map
|
|
182
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/refs.ts","../src/emit.ts","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AAA;AAAA,OACrB;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,aAAa,KAAA,EAAuC;AAC3D,EAAA,OAAO,KAAA,CAAM,aAAa,EAAC;AAC7B","file":"index.mjs","sourcesContent":["/**\n * Ref-key extraction, shared with the same convention `buildMastraAgent`\n * uses (`packages/mastra/src/build-agent.ts` `refKey`). An AIP-27 ref is\n * a string shorthand or `{ ref | file | inline }`; the key is the string,\n * else `.ref`, else `.file`, else a stable JSON of the inline payload.\n */\n\nimport type { AnyRef } from \"@agentproto/agent\"\n\nexport function refKey(ref: AnyRef): string {\n if (typeof ref === \"string\") return ref\n return ref.ref ?? ref.file ?? JSON.stringify(ref.inline ?? ref)\n}\n\n/** `@agentik/writer` → `writer`; bare ids untouched. */\nexport function stripOwner(id: string): string {\n const m = id.match(/^@[^/]+\\/(.+)$/)\n return m ? m[1]! : id\n}\n","/**\n * `emitApp(app, dir)` — write an app's agents + workflows to disk under an\n * agentproto-owned base, so the manifests don't squat the shared root\n * `.agents/` convention:\n *\n * <dir>/WORKSPACE.md (when the app has a\n * workspace — AIP-34 root\n * manifest; owner = tenant)\n * <dir>/.agentproto/agents/<id>/AGENT.md (one per agent)\n * <dir>/.agentproto/workflows/<wf.id>/WORKFLOW.md (shared — a workflow may\n * be run by several agents)\n *\n * The \"tenant\" isn't a `tenants/<t>/…` path segment — it's the `owner` of\n * the AIP-34 WORKSPACE.md (guild / user / org), and local storage is its\n * AIP-35 `storage` block. So there is no bespoke tenant folder to invent.\n *\n * Both are plain markdown manifests: frontmatter = the validated handle,\n * body = the agent's `body` (its system prompt) or the workflow description.\n * Because a `defineWorkflow` handle is pure data, the WORKFLOW.md needs no\n * `entry:` module — the manifest *is* the workflow, so `loadWorkflowHandle`\n * returns it directly with nothing to reconcile against.\n */\n\nimport { mkdir, writeFile } from \"node:fs/promises\"\nimport { join } from \"node:path\"\nimport matter from \"gray-matter\"\nimport type { WorkflowHandle } from \"@agentproto/workflow\"\nimport type { WorkspaceHandle } from \"@agentproto/workspace\"\nimport type { AgentEntry, EmittedApp } from \"./types.js\"\nimport { stripOwner } from \"./refs.js\"\n\ninterface EmitInput {\n readonly agents: readonly AgentEntry[]\n readonly workflows: readonly WorkflowHandle[]\n readonly workspace?: WorkspaceHandle\n}\n\nexport async function emitApp(app: EmitInput, dir: string): Promise<EmittedApp> {\n // Root WORKSPACE.md (AIP-34): the workspace manifest whose `owner` names\n // the tenant and whose `storage` names the backing store. The agents +\n // workflows below live *inside* this workspace, under `.agentproto/`.\n let workspacePath: string | undefined\n if (app.workspace) {\n await mkdir(dir, { recursive: true })\n workspacePath = join(dir, \"WORKSPACE.md\")\n await writeFile(\n workspacePath,\n toManifest(app.workspace, app.workspace.description ?? app.workspace.name),\n \"utf8\",\n )\n }\n\n const agentPaths: Record<string, string> = {}\n for (const { agent, body } of app.agents) {\n const agentDir = join(dir, \".agentproto\", \"agents\", stripOwner(agent.id))\n await mkdir(agentDir, { recursive: true })\n const agentPath = join(agentDir, \"AGENT.md\")\n await writeFile(agentPath, toManifest(agent, body ?? \"\"), \"utf8\")\n agentPaths[agent.id] = agentPath\n }\n\n const workflowPaths: string[] = []\n for (const wf of app.workflows) {\n const wfDir = join(dir, \".agentproto\", \"workflows\", wf.id)\n await mkdir(wfDir, { recursive: true })\n const wfPath = join(wfDir, \"WORKFLOW.md\")\n await writeFile(wfPath, toManifest(wf, wf.description ?? \"\"), \"utf8\")\n workflowPaths.push(wfPath)\n }\n\n return { agentPaths, workflowPaths, ...(workspacePath ? { workspacePath } : {}) }\n}\n\n/**\n * Serialize a handle to a `.md` manifest. gray-matter's YAML engine\n * rejects `undefined` values; a JSON clone drops them and yields a plain\n * data object (AIP handles are pure data, no functions/Dates) that\n * round-trips through the matching `parse*Manifest`. gray-matter appends\n * a trailing newline, so manifests end in exactly one newline.\n */\nfunction toManifest(handle: object, body: string): string {\n const data: Record<string, unknown> = JSON.parse(JSON.stringify(handle))\n return matter.stringify(`\\n${body}\\n`, data)\n}\n","/**\n * `defineApp({ agents, workflows, attach })` — bundle one or more AIP-42\n * agents, the AIP-15 workflows they run, and any other AIP artifacts into\n * one cross-linked, frozen handle.\n *\n * The only new invariant app-kit adds is *attachment*: the agents and the\n * bundled workflows must reference each other. Everything else (field\n * validation) already ran when the caller built the handles with\n * `defineAgent` / `defineWorkflow`, so `defineApp` validates the coupling,\n * not the fields.\n *\n * - agent ids are unique within the app.\n * - every `agent.workflows[]` ref MUST resolve to a bundled workflow id.\n * - every bundled workflow MUST be referenced by at least one agent.\n *\n * A dangling ref (an agent points at a workflow the app didn't bundle) or\n * an orphan (a bundled workflow no agent lists) throws — that is what \"an\n * agent attached to its workflows\" means, made checkable.\n */\n\nimport { buildMastraAgent } from \"@agentproto/mastra\"\nimport { defineWorkspace } from \"@agentproto/workspace\"\nimport type { AgentHandle, AnyRef } from \"@agentproto/agent\"\nimport type { WorkflowHandle } from \"@agentproto/workflow\"\nimport type { WorkspaceHandle } from \"@agentproto/workspace\"\nimport type {\n AgentEntry,\n AppDefinition,\n AppHandle,\n DoctypeHandle,\n ToMastraAgentOptions,\n WorkspaceInput,\n} from \"./types.js\"\nimport { refKey } from \"./refs.js\"\nimport { emitApp } from \"./emit.js\"\n\nexport class AppDefinitionError extends Error {\n constructor(message: string) {\n super(`defineApp (app-kit): ${message}`)\n this.name = \"AppDefinitionError\"\n }\n}\n\nexport function defineApp(def: AppDefinition): AppHandle {\n if (!Array.isArray(def.agents) || def.agents.length === 0) {\n throw new AppDefinitionError(\"`agents` must be a non-empty array.\")\n }\n\n const agents = def.agents.map(normalizeEntry)\n const workflows = def.workflows ?? []\n const attachments = def.attach ?? []\n const workspace = def.workspace ? toWorkspaceHandle(def.workspace) : undefined\n\n validateAttachment(agents, workflows)\n\n const frozenAgents = Object.freeze(agents.map((e) => Object.freeze({ ...e })))\n const frozenWorkflows = Object.freeze([...workflows])\n const frozenAttachments = Object.freeze([...attachments])\n\n const handle: AppHandle = {\n agents: frozenAgents,\n workflows: frozenWorkflows,\n attachments: frozenAttachments,\n ...(workspace ? { workspace } : {}),\n\n async toMastraAgents(opts: ToMastraAgentOptions, only?: readonly string[]) {\n const targets = only ? selectAgents(frozenAgents, only) : frozenAgents\n const out: Record<string, Awaited<ReturnType<typeof buildMastraAgent>>> = {}\n for (const entry of targets) {\n out[entry.agent.id] = await buildOne(entry, opts)\n }\n return out\n },\n\n pick(ids: readonly string[]) {\n return selectAgents(frozenAgents, ids)\n },\n\n async toMastraAgent(opts: ToMastraAgentOptions) {\n if (frozenAgents.length !== 1) {\n throw new AppDefinitionError(\n `toMastraAgent requires exactly one agent (app has ${frozenAgents.length}); use toMastraAgents.`,\n )\n }\n return buildOne(frozenAgents[0]!, opts)\n },\n\n emit(dir: string) {\n return emitApp(\n { agents: frozenAgents, workflows: frozenWorkflows, ...(workspace ? { workspace } : {}) },\n dir,\n )\n },\n }\n\n return Object.freeze(handle)\n}\n\n/**\n * Normalize the `workspace` input to an AIP-34 `WorkspaceHandle`. A built\n * handle (already run through `defineWorkspace`) carries `schema:\n * \"workspace/v1\"` and passes straight through; a `WorkspaceShorthand` is\n * completed with a local-fs storage default and a `0.1.0` version, then\n * validated by `defineWorkspace` — so a malformed shorthand fails with the\n * same AIP-34 diagnostic as a malformed WORKSPACE.md.\n */\nfunction toWorkspaceHandle(input: WorkspaceInput): WorkspaceHandle {\n if (\"schema\" in input) return input\n return defineWorkspace({\n schema: \"workspace/v1\",\n version: input.version ?? \"0.1.0\",\n id: input.id,\n name: input.name,\n owner: input.owner,\n storage: input.storage ?? { inline: { provider: \"local-fs\", config: {} } },\n ...(input.description ? { description: input.description } : {}),\n })\n}\n\n/**\n * Resolve `ids` to their app entries, preserving the caller's order. Throws\n * `AppDefinitionError` on any id the app doesn't bundle — a hand-picked list\n * that names a missing agent is a bug, not a silent no-op.\n */\nfunction selectAgents(\n agents: readonly AgentEntry[],\n ids: readonly string[],\n): readonly AgentEntry[] {\n const byId = new Map(agents.map((e) => [e.agent.id, e]))\n return ids.map((id) => {\n const entry = byId.get(id)\n if (!entry) {\n throw new AppDefinitionError(\n `agent '${id}' is not in this app. Bundled: [${[...byId.keys()].join(\", \")}].`,\n )\n }\n return entry\n })\n}\n\nfunction buildOne(entry: AgentEntry, opts: ToMastraAgentOptions) {\n // `entry.body` (the AGENT.md body) wins as instructions; an explicit\n // `opts.body` still overrides, matching buildMastraAgent's contract.\n return buildMastraAgent(entry.agent, { body: entry.body, ...opts })\n}\n\nfunction normalizeEntry(input: AgentEntry | AgentHandle): AgentEntry {\n // An AgentEntry has an `.agent`; a bare AgentHandle has `.id`/`.schema`.\n if (\"agent\" in input) return input\n return { agent: input }\n}\n\n/**\n * The attachment invariant across all agents: bundled workflow ids and\n * the union of every agent's `workflows[]` refs must be the same set.\n * External/registry workflow refs are out of scope for an app bundle —\n * if an agent lists it, the app must ship it.\n */\nfunction validateAttachment(\n agents: readonly AgentEntry[],\n workflows: readonly WorkflowHandle[],\n): void {\n const seenAgentIds = new Set<string>()\n for (const { agent } of agents) {\n if (seenAgentIds.has(agent.id)) {\n throw new AppDefinitionError(`duplicate agent id '${agent.id}' in the bundle.`)\n }\n seenAgentIds.add(agent.id)\n }\n\n const bundledIds = new Set<string>()\n for (const wf of workflows) {\n if (bundledIds.has(wf.id)) {\n throw new AppDefinitionError(`duplicate workflow id '${wf.id}' in the bundle.`)\n }\n bundledIds.add(wf.id)\n }\n\n const referenced = new Set<string>()\n for (const { agent } of agents) {\n for (const ref of workflowRefs(agent)) {\n const key = refKey(ref)\n referenced.add(key)\n if (!bundledIds.has(key)) {\n throw new AppDefinitionError(\n `agent '${agent.id}' references workflow '${key}' but the app does not bundle it. ` +\n `Bundled: [${[...bundledIds].join(\", \") || \"none\"}].`,\n )\n }\n }\n }\n\n for (const id of bundledIds) {\n if (!referenced.has(id)) {\n throw new AppDefinitionError(\n `workflow '${id}' is bundled but no agent lists it in workflows[]. ` +\n `Add { ref: \"${id}\" } to an agent, or drop the workflow.`,\n )\n }\n }\n}\n\nfunction workflowRefs(agent: AgentHandle): readonly AnyRef[] {\n return agent.workflows ?? []\n}\n\nexport type { DoctypeHandle }\n"]}
|
package/dist/refs.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ref-key extraction, shared with the same convention `buildMastraAgent`
|
|
3
|
+
* uses (`packages/mastra/src/build-agent.ts` `refKey`). An AIP-27 ref is
|
|
4
|
+
* a string shorthand or `{ ref | file | inline }`; the key is the string,
|
|
5
|
+
* else `.ref`, else `.file`, else a stable JSON of the inline payload.
|
|
6
|
+
*/
|
|
7
|
+
import type { AnyRef } from "@agentproto/agent";
|
|
8
|
+
export declare function refKey(ref: AnyRef): string;
|
|
9
|
+
/** `@agentik/writer` → `writer`; bare ids untouched. */
|
|
10
|
+
export declare function stripOwner(id: string): string;
|
|
11
|
+
//# sourceMappingURL=refs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refs.d.ts","sourceRoot":"","sources":["../src/refs.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE/C,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG1C;AAED,wDAAwD;AACxD,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAG7C"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for `@agentproto/app-kit`.
|
|
3
|
+
*
|
|
4
|
+
* An "app" is the smallest shippable unit that couples one or more AIP-42
|
|
5
|
+
* agents with the AIP-15 workflows they run — plus any other AIP artifacts
|
|
6
|
+
* you want to ride along (an AIP-6 company, AIP-25 personas, AIP-47 roles,
|
|
7
|
+
* policies…). The agents and workflows are authored with the existing
|
|
8
|
+
* `defineAgent` / `defineWorkflow`; app-kit bundles + cross-links them.
|
|
9
|
+
*
|
|
10
|
+
* On the system prompt: there is no `systemPrompt` field anywhere in AIP.
|
|
11
|
+
* The prompt is the free-text BODY of an AGENT.md (AIP-42) — frontmatter is
|
|
12
|
+
* `.strict()` and holds only metadata. So each agent carries an optional
|
|
13
|
+
* `body`; when omitted the prompt composes from the agent's persona /
|
|
14
|
+
* boundaries / traits (`composeInstructions` falls back to `description`),
|
|
15
|
+
* the same way Guilde assembles an operator's prompt from AIP-47 role
|
|
16
|
+
* instructions + AIP-25 persona rather than a stored string.
|
|
17
|
+
*/
|
|
18
|
+
import type { AgentHandle } from "@agentproto/agent";
|
|
19
|
+
import type { WorkflowHandle } from "@agentproto/workflow";
|
|
20
|
+
import type { WorkspaceHandle, WorkspaceDefinition } from "@agentproto/workspace";
|
|
21
|
+
import type { BuildMastraAgentResult, BuildMastraAgentOptions } from "@agentproto/mastra";
|
|
22
|
+
/**
|
|
23
|
+
* An agent paired with the prose that becomes its system prompt. `body`
|
|
24
|
+
* is the AGENT.md body (AIP-42) — the only place free-text instructions
|
|
25
|
+
* live. Optional: omit it to let the prompt compose from the agent's
|
|
26
|
+
* structured fields.
|
|
27
|
+
*/
|
|
28
|
+
export interface AgentEntry {
|
|
29
|
+
readonly agent: AgentHandle;
|
|
30
|
+
/** The AGENT.md body / system prompt. Optional — composed if absent. */
|
|
31
|
+
readonly body?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Structural view of any AIP doctype handle (agent, company, persona,
|
|
35
|
+
* role, policy…). Every `defineX` handle has a stable `id`; `schema`
|
|
36
|
+
* carries the doctype literal when the doctype declares one. Kept
|
|
37
|
+
* structural so an app can `attach` any AIP artifact without app-kit
|
|
38
|
+
* depending on each doctype package.
|
|
39
|
+
*/
|
|
40
|
+
export interface DoctypeHandle {
|
|
41
|
+
readonly id: string;
|
|
42
|
+
readonly schema?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Lightweight way to give an app a home workspace without hand-writing a
|
|
46
|
+
* full AIP-34 `defineWorkspace(...)`. `owner` is the tenant identity
|
|
47
|
+
* (guild / user / org — the tenant model AIP-34 already ships, not a folder
|
|
48
|
+
* segment); `storage` is the AIP-35 STORAGE block and defaults to local
|
|
49
|
+
* filesystem. `id` is the globally-addressable `@<owner-slug>/<workspace>`,
|
|
50
|
+
* whose owner segment MUST equal `owner.slug`.
|
|
51
|
+
*/
|
|
52
|
+
export interface WorkspaceShorthand {
|
|
53
|
+
readonly id: string;
|
|
54
|
+
readonly name: string;
|
|
55
|
+
readonly owner: WorkspaceDefinition["owner"];
|
|
56
|
+
/** AIP-35 STORAGE block. Defaults to `{ inline: { provider: "local-fs", config: {} } }`. */
|
|
57
|
+
readonly storage?: WorkspaceDefinition["storage"];
|
|
58
|
+
readonly version?: string;
|
|
59
|
+
readonly description?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* A home workspace for an app: either a full AIP-34 `WorkspaceHandle`
|
|
63
|
+
* (from `defineWorkspace`) or the `WorkspaceShorthand` above. Discriminated
|
|
64
|
+
* structurally — a built handle carries `schema: "workspace/v1"`.
|
|
65
|
+
*/
|
|
66
|
+
export type WorkspaceInput = WorkspaceHandle | WorkspaceShorthand;
|
|
67
|
+
/**
|
|
68
|
+
* Input to `defineApp`. Each `agents[]` entry is an already-validated
|
|
69
|
+
* `AgentHandle` (bare, no body) or an `AgentEntry` (handle + body).
|
|
70
|
+
*/
|
|
71
|
+
export interface AppDefinition {
|
|
72
|
+
readonly agents: readonly (AgentEntry | AgentHandle)[];
|
|
73
|
+
readonly workflows?: readonly WorkflowHandle[];
|
|
74
|
+
/** Any other AIP handles to carry with the app (AIP-6/25/47/…). */
|
|
75
|
+
readonly attach?: readonly DoctypeHandle[];
|
|
76
|
+
/**
|
|
77
|
+
* Optional home workspace (AIP-34). When set, the app is content
|
|
78
|
+
* *inside* a workspace whose `owner` names the tenant and whose
|
|
79
|
+
* `storage` names the backing store — `emit` writes a root `WORKSPACE.md`
|
|
80
|
+
* alongside the agents. Omit for a workspace-less bundle.
|
|
81
|
+
*/
|
|
82
|
+
readonly workspace?: WorkspaceInput;
|
|
83
|
+
}
|
|
84
|
+
/** Options for `toMastraAgent(s)`. Same resolvers as `buildMastraAgent`. */
|
|
85
|
+
export type ToMastraAgentOptions = BuildMastraAgentOptions;
|
|
86
|
+
/** Paths written by `AppHandle.emit`. */
|
|
87
|
+
export interface EmittedApp {
|
|
88
|
+
/** Absolute paths to the written `AGENT.md` files, keyed by agent id. */
|
|
89
|
+
readonly agentPaths: Readonly<Record<string, string>>;
|
|
90
|
+
/** Absolute paths to the written `WORKFLOW.md` files, in input order. */
|
|
91
|
+
readonly workflowPaths: readonly string[];
|
|
92
|
+
/** Absolute path to the root `WORKSPACE.md`, when the app has a workspace. */
|
|
93
|
+
readonly workspacePath?: string;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The frozen result of `defineApp`. Carries the cross-linked agents +
|
|
97
|
+
* workflows + attachments and the two consumption paths.
|
|
98
|
+
*/
|
|
99
|
+
export interface AppHandle {
|
|
100
|
+
readonly agents: readonly AgentEntry[];
|
|
101
|
+
readonly workflows: readonly WorkflowHandle[];
|
|
102
|
+
readonly attachments: readonly DoctypeHandle[];
|
|
103
|
+
/** The app's home workspace (AIP-34), normalized to a handle. Absent if none. */
|
|
104
|
+
readonly workspace?: WorkspaceHandle;
|
|
105
|
+
/**
|
|
106
|
+
* Build agents into runnable Mastra agents whose `instructions` field is
|
|
107
|
+
* the real system prompt (body → `composeInstructions`), keyed by agent id.
|
|
108
|
+
*
|
|
109
|
+
* Pass `only` to build just those agent ids instead of the whole app — the
|
|
110
|
+
* "use n of a team" path, so a host doesn't pay to build agents it won't
|
|
111
|
+
* run. Every id in `only` must belong to the app (unknown ids throw).
|
|
112
|
+
*/
|
|
113
|
+
toMastraAgents(opts: ToMastraAgentOptions, only?: readonly string[]): Promise<Record<string, BuildMastraAgentResult>>;
|
|
114
|
+
/**
|
|
115
|
+
* Select a subset of the app's agents by id, as a fresh readonly list —
|
|
116
|
+
* without building them. Throws `AppDefinitionError` on an unknown id.
|
|
117
|
+
* Handy to inspect or hand-pick before `toMastraAgents`.
|
|
118
|
+
*/
|
|
119
|
+
pick(ids: readonly string[]): readonly AgentEntry[];
|
|
120
|
+
/**
|
|
121
|
+
* Single-agent convenience. Throws if the app has zero or more than
|
|
122
|
+
* one agent — use `toMastraAgents` for multi-agent apps.
|
|
123
|
+
*/
|
|
124
|
+
toMastraAgent(opts: ToMastraAgentOptions): Promise<BuildMastraAgentResult>;
|
|
125
|
+
/**
|
|
126
|
+
* Write one `AGENT.md` per agent + one shared `WORKFLOW.md` per workflow
|
|
127
|
+
* under `<dir>/.agentproto/`, plus a root `<dir>/WORKSPACE.md` when the
|
|
128
|
+
* app has a `workspace`. Returns the written paths.
|
|
129
|
+
*/
|
|
130
|
+
emit(dir: string): Promise<EmittedApp>;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AACjF,OAAO,KAAK,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAA;AAEzF;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAA;IAC3B,wEAAwE;IACxE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CACvB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,MAAM,CAAC,EAAE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,EAAE,CAAA;IACtC,QAAQ,CAAC,SAAS,EAAE,SAAS,cAAc,EAAE,CAAA;IAC7C,QAAQ,CAAC,WAAW,EAAE,SAAS,aAAa,EAAE,CAAA;IAC9C,iFAAiF;IACjF,QAAQ,CAAC,SAAS,CAAC,EAAE,eAAe,CAAA;IAEpC;;;;;;;OAOG;IACH,cAAc,CACZ,IAAI,EAAE,oBAAoB,EAC1B,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,GACvB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC,CAAA;IAElD;;;;OAIG;IACH,IAAI,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,UAAU,EAAE,CAAA;IAEnD;;;OAGG;IACH,aAAa,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAA;IAE1E;;;;OAIG;IACH,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;CACvC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentproto/app-kit",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "@agentproto/app-kit — declare an agent (with its system prompt) and its workflows in one TypeScript module and import them anywhere. A thin umbrella over AIP-42 defineAgent + AIP-15 defineWorkflow: defineApp cross-links the two (every workflow agent-step must target the app's agent, every agent workflow ref must resolve), toMastraAgent turns the AGENT.md body into a real Mastra `instructions` field, and emit writes the .agents/<id>/AGENT.md + WORKFLOW.md(+entry) pair that runs through the agentproto-run lane unchanged.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"agentproto",
|
|
7
|
+
"aip-42",
|
|
8
|
+
"aip-15",
|
|
9
|
+
"defineApp",
|
|
10
|
+
"agent",
|
|
11
|
+
"workflow",
|
|
12
|
+
"open-standard"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://agentproto.sh/docs/aip-42",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/agentproto/ts",
|
|
18
|
+
"directory": "packages/app-kit"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/agentproto/ts/issues"
|
|
22
|
+
},
|
|
23
|
+
"license": "Apache-2.0",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "dist/index.mjs",
|
|
26
|
+
"module": "dist/index.mjs",
|
|
27
|
+
"types": "dist/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.mjs",
|
|
32
|
+
"default": "./dist/index.mjs"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"README.md",
|
|
39
|
+
"LICENSE"
|
|
40
|
+
],
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"gray-matter": "^4.0.3",
|
|
46
|
+
"@agentproto/agent": "0.2.1",
|
|
47
|
+
"@agentproto/mastra": "0.2.2",
|
|
48
|
+
"@agentproto/workflow": "0.1.0",
|
|
49
|
+
"@agentproto/workspace": "0.1.0"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@mastra/core": ">=1.0.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@mastra/core": "1.32.1",
|
|
56
|
+
"@types/node": "^25.6.2",
|
|
57
|
+
"tsup": "^8.5.1",
|
|
58
|
+
"typescript": "^5.9.3",
|
|
59
|
+
"vitest": "^3.2.4",
|
|
60
|
+
"@agentproto/tooling": "0.1.0-alpha.0",
|
|
61
|
+
"@agentproto/workflow-loader": "0.1.0"
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"dev": "tsup --watch",
|
|
65
|
+
"build": "tsup && tsc -p tsconfig.build.json",
|
|
66
|
+
"clean": "rm -rf dist",
|
|
67
|
+
"check-types": "tsc --noEmit",
|
|
68
|
+
"test": "vitest run",
|
|
69
|
+
"test:watch": "vitest"
|
|
70
|
+
}
|
|
71
|
+
}
|