@agentproto/driver 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/chunk-6NYFD4YS.mjs +205 -0
- package/dist/chunk-6NYFD4YS.mjs.map +1 -0
- package/dist/index.d.ts +134 -0
- package/dist/index.mjs +399 -0
- package/dist/index.mjs.map +1 -0
- package/dist/manifest/index.d.ts +104 -0
- package/dist/manifest/index.mjs +3 -0
- package/dist/manifest/index.mjs.map +1 -0
- package/dist/types-U3ItqOQG.d.ts +383 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jeremy André and agentproto contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import matter from 'gray-matter';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { createDoctype } from '@agentproto/define-doctype';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @agentproto/driver v0.1.0-alpha
|
|
7
|
+
* AIP-30 DRIVER.md `defineDriver` reference implementation.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var defineDriver = createDoctype({
|
|
11
|
+
aip: 30,
|
|
12
|
+
name: "driver",
|
|
13
|
+
validate(def) {
|
|
14
|
+
if (def.implements.length === 0) {
|
|
15
|
+
throw new Error(
|
|
16
|
+
`defineDriver: id='${def.id}' must declare \u22651 implements[] entry`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
const previewMap = mergeExecuteMap(def);
|
|
20
|
+
const declaredToolIds = new Set(
|
|
21
|
+
def.implements.map((e) => normalizeToolId(e.tool))
|
|
22
|
+
);
|
|
23
|
+
const executeKeys = new Set(Object.keys(previewMap));
|
|
24
|
+
for (const toolId of declaredToolIds) {
|
|
25
|
+
if (!executeKeys.has(toolId)) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`defineDriver: id='${def.id}' implements '${toolId}' but no execute['${toolId}'] body provided`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
for (const key of executeKeys) {
|
|
32
|
+
if (!declaredToolIds.has(key)) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
`defineDriver: id='${def.id}' has execute['${key}'] but '${key}' is not in implements[]`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
build(def) {
|
|
40
|
+
const executeMap = mergeExecuteMap(def);
|
|
41
|
+
return {
|
|
42
|
+
id: def.id,
|
|
43
|
+
name: def.name,
|
|
44
|
+
description: def.description,
|
|
45
|
+
version: def.version,
|
|
46
|
+
kind: def.kind,
|
|
47
|
+
implements: Object.freeze(def.implements.map(freezeImplements)),
|
|
48
|
+
execute: Object.freeze(executeMap),
|
|
49
|
+
install: Object.freeze([...def.install ?? []]),
|
|
50
|
+
versionCheck: def.versionCheck,
|
|
51
|
+
auth: def.auth,
|
|
52
|
+
network: Object.freeze({
|
|
53
|
+
egress: Object.freeze([...def.network?.egress ?? []]),
|
|
54
|
+
ingress: Object.freeze([...def.network?.ingress ?? []])
|
|
55
|
+
}),
|
|
56
|
+
region: Object.freeze([...def.region ?? ["global"]]),
|
|
57
|
+
policyTags: Object.freeze([...def.policyTags ?? []]),
|
|
58
|
+
costOverride: def.costOverride,
|
|
59
|
+
timeoutOverrideMs: def.timeoutOverrideMs,
|
|
60
|
+
retryOverride: def.retryOverride,
|
|
61
|
+
healthCheck: def.healthCheck,
|
|
62
|
+
tags: Object.freeze([...def.tags ?? []]),
|
|
63
|
+
metadata: Object.freeze({ ...def.metadata ?? {} }),
|
|
64
|
+
login: def.login,
|
|
65
|
+
refresh: def.refresh,
|
|
66
|
+
parseOutput: def.parseOutput,
|
|
67
|
+
detectExpiry: def.detectExpiry
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
function mergeExecuteMap(def) {
|
|
72
|
+
const executeMap = { ...def.execute ?? {} };
|
|
73
|
+
for (const impl of def.implementations ?? []) {
|
|
74
|
+
const id = impl.tool.id;
|
|
75
|
+
const typedBody = impl.body;
|
|
76
|
+
if (executeMap[id] && executeMap[id] !== typedBody) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
`defineDriver: id='${def.id}' has duplicate body for '${id}' \u2014 present in both 'execute' and 'implementations'. Pick one.`
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
executeMap[id] = typedBody;
|
|
82
|
+
}
|
|
83
|
+
return executeMap;
|
|
84
|
+
}
|
|
85
|
+
function freezeImplements(entry) {
|
|
86
|
+
return Object.freeze({
|
|
87
|
+
...entry,
|
|
88
|
+
schemaNarrowing: entry.schemaNarrowing ? Object.freeze({
|
|
89
|
+
dropInputs: Object.freeze([
|
|
90
|
+
...entry.schemaNarrowing.dropInputs ?? []
|
|
91
|
+
]),
|
|
92
|
+
dropOutputs: Object.freeze([
|
|
93
|
+
...entry.schemaNarrowing.dropOutputs ?? []
|
|
94
|
+
])
|
|
95
|
+
}) : void 0,
|
|
96
|
+
mapping: entry.mapping ? Object.freeze({ ...entry.mapping }) : void 0,
|
|
97
|
+
metadata: entry.metadata ? Object.freeze({ ...entry.metadata }) : void 0
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function normalizeToolId(ref) {
|
|
101
|
+
let s = ref.trim();
|
|
102
|
+
if (s.startsWith("./")) s = s.slice(2);
|
|
103
|
+
if (s.endsWith("/TOOL.md")) s = s.slice(0, -"/TOOL.md".length);
|
|
104
|
+
if (s.startsWith("tools/")) s = s.slice("tools/".length);
|
|
105
|
+
const lastSlash = s.lastIndexOf("/");
|
|
106
|
+
return lastSlash === -1 ? s : s.slice(lastSlash + 1);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// src/manifest/index.ts
|
|
110
|
+
var DRIVER_KIND = z.enum(["cli", "http", "mcp", "sdk", "builtin"]);
|
|
111
|
+
var IMPLEMENTS_ENTRY = z.object({
|
|
112
|
+
tool: z.string().min(1),
|
|
113
|
+
version: z.string().min(1),
|
|
114
|
+
schema_narrowing: z.object({
|
|
115
|
+
drop_inputs: z.array(z.string()).optional(),
|
|
116
|
+
drop_outputs: z.array(z.string()).optional()
|
|
117
|
+
}).optional(),
|
|
118
|
+
mapping: z.record(
|
|
119
|
+
z.string(),
|
|
120
|
+
z.union([
|
|
121
|
+
z.string(),
|
|
122
|
+
z.object({ from: z.string(), transform: z.string().optional() })
|
|
123
|
+
])
|
|
124
|
+
).optional(),
|
|
125
|
+
cost_override: z.unknown().optional(),
|
|
126
|
+
timeout_override_ms: z.number().int().positive().optional(),
|
|
127
|
+
retry_override: z.unknown().optional(),
|
|
128
|
+
metadata: z.record(z.string(), z.unknown()).optional()
|
|
129
|
+
}).loose();
|
|
130
|
+
var driverManifestFrontmatterSchema = z.object({
|
|
131
|
+
schema: z.literal("agentproto/driver/v1").optional(),
|
|
132
|
+
id: z.string().regex(/^[a-z0-9][a-z0-9.\-_]{1,79}$/),
|
|
133
|
+
name: z.string().min(1).max(120),
|
|
134
|
+
description: z.string().min(1).max(2e3),
|
|
135
|
+
version: z.string().regex(/^\d+\.\d+\.\d+/).optional(),
|
|
136
|
+
kind: DRIVER_KIND,
|
|
137
|
+
implements: z.array(IMPLEMENTS_ENTRY).min(1),
|
|
138
|
+
// Universal lifecycle / policy / sandbox blocks. Kept as `unknown`
|
|
139
|
+
// for block content — the kind-specific runtime packages own the
|
|
140
|
+
// strict shape; AIP-30 only requires presence + array-ness.
|
|
141
|
+
install: z.array(z.unknown()).optional(),
|
|
142
|
+
version_check: z.unknown().optional(),
|
|
143
|
+
auth: z.unknown().optional(),
|
|
144
|
+
network: z.object({
|
|
145
|
+
egress: z.array(z.string()).optional(),
|
|
146
|
+
ingress: z.array(z.string()).optional()
|
|
147
|
+
}).optional(),
|
|
148
|
+
region: z.array(z.string()).optional(),
|
|
149
|
+
policy_tags: z.array(z.string()).optional(),
|
|
150
|
+
cost_override: z.unknown().optional(),
|
|
151
|
+
timeout_override_ms: z.number().int().positive().optional(),
|
|
152
|
+
retry_override: z.unknown().optional(),
|
|
153
|
+
health_check: z.unknown().optional(),
|
|
154
|
+
tags: z.array(z.string()).optional(),
|
|
155
|
+
metadata: z.record(z.string(), z.unknown()).optional()
|
|
156
|
+
}).loose();
|
|
157
|
+
function parseDriverManifest(source) {
|
|
158
|
+
const parsed = matter(source);
|
|
159
|
+
if (Object.keys(parsed.data).length === 0) {
|
|
160
|
+
throw new Error("parseDriverManifest: missing or empty frontmatter");
|
|
161
|
+
}
|
|
162
|
+
const result = driverManifestFrontmatterSchema.safeParse(parsed.data);
|
|
163
|
+
if (!result.success) {
|
|
164
|
+
throw new Error(
|
|
165
|
+
`parseDriverManifest: invalid frontmatter \u2014 ${result.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ")}`
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
return { frontmatter: result.data, body: parsed.content };
|
|
169
|
+
}
|
|
170
|
+
function driverFromManifest(args) {
|
|
171
|
+
const fm = args.manifest.frontmatter;
|
|
172
|
+
const definition = {
|
|
173
|
+
id: fm.id,
|
|
174
|
+
name: fm.name,
|
|
175
|
+
description: fm.description,
|
|
176
|
+
version: fm.version,
|
|
177
|
+
kind: fm.kind,
|
|
178
|
+
implements: fm.implements.map((entry) => ({
|
|
179
|
+
tool: entry.tool,
|
|
180
|
+
version: entry.version,
|
|
181
|
+
schemaNarrowing: entry.schema_narrowing ? {
|
|
182
|
+
dropInputs: entry.schema_narrowing.drop_inputs,
|
|
183
|
+
dropOutputs: entry.schema_narrowing.drop_outputs
|
|
184
|
+
} : void 0,
|
|
185
|
+
mapping: entry.mapping,
|
|
186
|
+
costOverride: entry.cost_override,
|
|
187
|
+
timeoutOverrideMs: entry.timeout_override_ms,
|
|
188
|
+
retryOverride: entry.retry_override,
|
|
189
|
+
metadata: entry.metadata
|
|
190
|
+
})),
|
|
191
|
+
execute: args.execute,
|
|
192
|
+
implementations: args.implementations,
|
|
193
|
+
network: fm.network,
|
|
194
|
+
region: fm.region,
|
|
195
|
+
policyTags: fm.policy_tags,
|
|
196
|
+
timeoutOverrideMs: fm.timeout_override_ms,
|
|
197
|
+
tags: fm.tags,
|
|
198
|
+
metadata: fm.metadata
|
|
199
|
+
};
|
|
200
|
+
return defineDriver(definition);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export { defineDriver, driverFromManifest, driverManifestFrontmatterSchema, normalizeToolId, parseDriverManifest };
|
|
204
|
+
//# sourceMappingURL=chunk-6NYFD4YS.mjs.map
|
|
205
|
+
//# sourceMappingURL=chunk-6NYFD4YS.mjs.map
|
|
@@ -0,0 +1 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AAA;AAAA,MACZ,SAAS,KAAA,CAAM,OAAA;AAAA,MACf,eAAA,EAAiB,MAAM,gBAAA,GACnB;AAAA,QACE,UAAA,EAAY,MAAM,gBAAA,CAAiB,WAAA;AAAA,QACnC,WAAA,EAAa,MAAM,gBAAA,CAAiB;AAAA,OACtC,GACA,MAAA;AAAA,MACJ,SAAS,KAAA,CAAM,OAAA;AAAA,MACf,cAAc,KAAA,CAAM,aAAA;AAAA,MACpB,mBAAmB,KAAA,CAAM,mBAAA;AAAA,MACzB,eAAe,KAAA,CAAM,cAAA;AAAA,MACrB,UAAU,KAAA,CAAM;AAAA,KAClB,CAAE,CAAA;AAAA,IACF,SAAS,IAAA,CAAK,OAAA;AAAA,IACd,iBAAiB,IAAA,CAAK,eAAA;AAAA,IACtB,SAAS,EAAA,CAAG,OAAA;AAAA,IACZ,QAAQ,EAAA,CAAG,MAAA;AAAA,IACX,YAAY,EAAA,CAAG,WAAA;AAAA,IACf,mBAAmB,EAAA,CAAG,mBAAA;AAAA,IACtB,MAAM,EAAA,CAAG,IAAA;AAAA,IACT,UAAU,EAAA,CAAG;AAAA,GACf;AAEA,EAAA,OAAO,aAAa,UAAU,CAAA;AAChC","file":"chunk-6NYFD4YS.mjs","sourcesContent":["import { createDoctype } from \"@agentproto/define-doctype\"\nimport type {\n ExecuteFn,\n ImplementsEntry,\n DriverDefinition,\n DriverHandle,\n} from \"./types.js\"\n\n/**\n * AIP-30 reference implementation of `defineDriver`.\n *\n * Returns a {@link DriverHandle} with defaults applied. The resolver\n * (`resolveDriver`) and runners (`runTool`) consume this shape and\n * dispatch contract calls to the per-tool execute bodies.\n *\n * Built on `createDoctype` from `@agentproto/define-doctype`: the\n * id-pattern + description-length validation and the top-level\n * `Object.freeze` are shared with every other AIP defineX. The\n * spec-30-specific parts (implements vs execute consistency, merging\n * `implementations[]` into the execute map, freezing nested arrays\n * and objects) live in `validate` and `build` below.\n *\n * Conformance highlights ([§ Conformance rules](https://agentproto.sh/docs/aip-30)):\n * - Frontmatter is the source of truth — entries warn on mismatch and prefer frontmatter.\n * - `execute[<toolId>]` MUST exist for every `implements[]` entry.\n * - No I/O at module load — `defineDriver(...)` is pure construction.\n *\n * Two body-binding paths are accepted:\n *\n * 1. **Legacy bag** — `execute: { [toolId]: ExecuteFn }`. Used by\n * `.md`-driven dynamic loading where the contract handle isn't\n * in scope. Bodies receive `unknown`-typed inputs and must cast.\n * 2. **Typed implementations** — `implementations: ToolImplementation[]`.\n * Each impl carries its contract handle so the body's `input`,\n * `context`, and return are checked against the contract's\n * generics at compile time. Authors get IERC20-style type safety.\n *\n * Both can coexist on the same provider. On the same tool id, the\n * typed `implementations[]` form wins over the legacy bag.\n */\nexport const defineDriver = createDoctype<DriverDefinition, DriverHandle>({\n aip: 30,\n name: \"driver\",\n validate(def) {\n if (def.implements.length === 0) {\n throw new Error(\n `defineDriver: id='${def.id}' must declare ≥1 implements[] entry`,\n )\n }\n // The execute-map vs implements[] consistency check needs the merged\n // map; building it once and validating in `build` is fine — but we\n // also want a precise error on per-tool missing bodies before we\n // commit to the build path. Run that check here against a previewed\n // merged map so the thrown message matches the historical wording\n // (\"implements 'X' but no execute['X'] body provided\").\n const previewMap = mergeExecuteMap(def)\n const declaredToolIds = new Set(\n def.implements.map((e) => normalizeToolId(e.tool)),\n )\n const executeKeys = new Set(Object.keys(previewMap))\n for (const toolId of declaredToolIds) {\n if (!executeKeys.has(toolId)) {\n throw new Error(\n `defineDriver: id='${def.id}' implements '${toolId}' but no execute['${toolId}'] body provided`,\n )\n }\n }\n for (const key of executeKeys) {\n if (!declaredToolIds.has(key)) {\n throw new Error(\n `defineDriver: id='${def.id}' has execute['${key}'] but '${key}' is not in implements[]`,\n )\n }\n }\n },\n build(def) {\n const executeMap = mergeExecuteMap(def)\n return {\n id: def.id,\n name: def.name,\n description: def.description,\n version: def.version,\n kind: def.kind,\n implements: Object.freeze(def.implements.map(freezeImplements)),\n execute: Object.freeze(executeMap),\n install: Object.freeze([...(def.install ?? [])]),\n versionCheck: def.versionCheck,\n auth: def.auth,\n network: Object.freeze({\n egress: Object.freeze([...(def.network?.egress ?? [])]),\n ingress: Object.freeze([...(def.network?.ingress ?? [])]),\n }),\n region: Object.freeze([...(def.region ?? [\"global\"])]),\n policyTags: Object.freeze([...(def.policyTags ?? [])]),\n costOverride: def.costOverride,\n timeoutOverrideMs: def.timeoutOverrideMs,\n retryOverride: def.retryOverride,\n healthCheck: def.healthCheck,\n tags: Object.freeze([...(def.tags ?? [])]),\n metadata: Object.freeze({ ...(def.metadata ?? {}) }),\n login: def.login,\n refresh: def.refresh,\n parseOutput: def.parseOutput,\n detectExpiry: def.detectExpiry,\n }\n },\n})\n\n/**\n * Merge typed `implementations[]` into the runtime execute map. Each\n * ToolImplementation carries its contract handle, so we read\n * `impl.tool.id` to derive the binding key — authors don't restate\n * the id as a string. Typed bindings beat legacy bag on collision; a\n * collision with a *different* body raises an error so there's never\n * ambiguity about which body the resolver dispatched.\n */\nfunction mergeExecuteMap(def: DriverDefinition): Record<string, ExecuteFn> {\n const executeMap: Record<string, ExecuteFn> = { ...(def.execute ?? {}) }\n for (const impl of def.implementations ?? []) {\n const id = impl.tool.id\n const typedBody = impl.body as ExecuteFn\n if (executeMap[id] && executeMap[id] !== typedBody) {\n throw new Error(\n `defineDriver: id='${def.id}' has duplicate body for '${id}' — ` +\n `present in both 'execute' and 'implementations'. Pick one.`,\n )\n }\n executeMap[id] = typedBody\n }\n return executeMap\n}\n\nfunction freezeImplements(entry: ImplementsEntry): ImplementsEntry {\n return Object.freeze({\n ...entry,\n schemaNarrowing: entry.schemaNarrowing\n ? Object.freeze({\n dropInputs: Object.freeze([\n ...(entry.schemaNarrowing.dropInputs ?? []),\n ]),\n dropOutputs: Object.freeze([\n ...(entry.schemaNarrowing.dropOutputs ?? []),\n ]),\n })\n : undefined,\n mapping: entry.mapping ? Object.freeze({ ...entry.mapping }) : undefined,\n metadata: entry.metadata ? Object.freeze({ ...entry.metadata }) : undefined,\n })\n}\n\n/**\n * Normalise a tool ref (`./tools/foo/TOOL.md`, `tools/foo`,\n * `foo`) to its canonical id used as the `execute` map key.\n *\n * v1: strip leading `./`, strip `/TOOL.md` suffix, strip `tools/`\n * prefix, take the last path segment when no other normalisation\n * applies. Matches the convention in EXAMPLES.md.\n */\nexport function normalizeToolId(ref: string): string {\n let s = ref.trim()\n if (s.startsWith(\"./\")) s = s.slice(2)\n if (s.endsWith(\"/TOOL.md\")) s = s.slice(0, -\"/TOOL.md\".length)\n if (s.startsWith(\"tools/\")) s = s.slice(\"tools/\".length)\n // Last segment when path-shaped; otherwise the whole string.\n const lastSlash = s.lastIndexOf(\"/\")\n return lastSlash === -1 ? s : s.slice(lastSlash + 1)\n}\n","/**\n * AIP-30 DRIVER.md sidecar parser + manifest-to-handle constructor.\n *\n * Mirror of `@agentproto/tool/manifest`: the .md provides\n * metadata + dispatch declarations (`implements[]`, `install`, `auth`,\n * `network`, …); the TS module supplies the execute bodies. Both inputs\n * end up in `defineDriver` so the cross-AIP invariants (id pattern,\n * description length, top-level freeze, error prefix) run uniformly.\n *\n * The frontmatter schema below covers the AIP-30 §\"Frontmatter\" block\n * loosely — only the universally-required fields are strictly typed\n * (id, name, description, version, kind, implements). Subtype-specific\n * extras (CLI argv, HTTP endpoints, MCP tool names) live under\n * `metadata` or `implements[].metadata` with `unknown`-typed values\n * and are validated by the kind-specific runtime packages, not here.\n */\n\nimport matter from \"gray-matter\"\nimport { z } from \"zod\"\nimport { defineDriver } from \"../define-provider.js\"\nimport type { ToolImplementation } from \"../implement-tool.js\"\nimport type {\n DriverDefinition,\n DriverHandle,\n ExecuteFn,\n} from \"../types.js\"\n\nconst DRIVER_KIND = z.enum([\"cli\", \"http\", \"mcp\", \"sdk\", \"builtin\"])\n\nconst IMPLEMENTS_ENTRY = z\n .object({\n tool: z.string().min(1),\n version: z.string().min(1),\n schema_narrowing: z\n .object({\n drop_inputs: z.array(z.string()).optional(),\n drop_outputs: z.array(z.string()).optional(),\n })\n .optional(),\n mapping: z\n .record(\n z.string(),\n z.union([\n z.string(),\n z.object({ from: z.string(), transform: z.string().optional() }),\n ]),\n )\n .optional(),\n cost_override: z.unknown().optional(),\n timeout_override_ms: z.number().int().positive().optional(),\n retry_override: z.unknown().optional(),\n metadata: z.record(z.string(), z.unknown()).optional(),\n })\n .loose()\n\nexport const driverManifestFrontmatterSchema = z\n .object({\n schema: z.literal(\"agentproto/driver/v1\").optional(),\n id: z.string().regex(/^[a-z0-9][a-z0-9.\\-_]{1,79}$/),\n name: z.string().min(1).max(120),\n description: z.string().min(1).max(2000),\n version: z.string().regex(/^\\d+\\.\\d+\\.\\d+/).optional(),\n kind: DRIVER_KIND,\n implements: z.array(IMPLEMENTS_ENTRY).min(1),\n\n // Universal lifecycle / policy / sandbox blocks. Kept as `unknown`\n // for block content — the kind-specific runtime packages own the\n // strict shape; AIP-30 only requires presence + array-ness.\n install: z.array(z.unknown()).optional(),\n version_check: z.unknown().optional(),\n auth: z.unknown().optional(),\n network: z\n .object({\n egress: z.array(z.string()).optional(),\n ingress: z.array(z.string()).optional(),\n })\n .optional(),\n region: z.array(z.string()).optional(),\n policy_tags: z.array(z.string()).optional(),\n cost_override: z.unknown().optional(),\n timeout_override_ms: z.number().int().positive().optional(),\n retry_override: z.unknown().optional(),\n health_check: z.unknown().optional(),\n\n tags: z.array(z.string()).optional(),\n metadata: z.record(z.string(), z.unknown()).optional(),\n })\n .loose()\n\nexport type DriverManifestFrontmatter = z.infer<\n typeof driverManifestFrontmatterSchema\n>\n\nexport interface DriverManifest {\n frontmatter: DriverManifestFrontmatter\n body: string\n}\n\n/**\n * Parse a DRIVER.md source string into structured frontmatter + body.\n * Throws on missing frontmatter or schema-invalid frontmatter.\n */\nexport function parseDriverManifest(source: string): DriverManifest {\n const parsed = matter(source)\n if (Object.keys(parsed.data).length === 0) {\n throw new Error(\"parseDriverManifest: missing or empty frontmatter\")\n }\n const result = driverManifestFrontmatterSchema.safeParse(parsed.data)\n if (!result.success) {\n throw new Error(\n `parseDriverManifest: invalid frontmatter — ${result.error.issues\n .map((i) => `${i.path.join(\".\")}: ${i.message}`)\n .join(\"; \")}`,\n )\n }\n return { frontmatter: result.data, body: parsed.content }\n}\n\n/**\n * Build a {@link DriverHandle} from a parsed `DRIVER.md` manifest +\n * caller-supplied execute bodies. The .md is the source of truth for\n * dispatch metadata (`implements[]`, install, auth, network, …); the\n * TS module supplies the actual function bodies via `execute` (legacy\n * keyed bag) or `implementations` (typed via `implementTool(handle, body)`).\n *\n * Mirrors `toolFromManifest`: same shape, same single source of truth\n * principle. Goes through `defineDriver` so the AIP-30 invariants\n * (`implements[]` ↔ execute consistency, top-level freeze, error\n * prefix) run uniformly with the TS path.\n *\n * @example\n * const manifest = parseDriverManifest(readFileSync(\"./gh-cli/DRIVER.md\", \"utf8\"))\n * const ghCli = driverFromManifest({\n * manifest,\n * execute: {\n * \"list-prs\": async ({ input }) => { ... },\n * },\n * })\n */\nexport function driverFromManifest(args: {\n manifest: DriverManifest\n execute?: Record<string, ExecuteFn>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n implementations?: readonly ToolImplementation<any, any, any>[]\n}): DriverHandle {\n const fm = args.manifest.frontmatter\n\n const definition: DriverDefinition = {\n id: fm.id,\n name: fm.name,\n description: fm.description,\n version: fm.version,\n kind: fm.kind,\n implements: fm.implements.map((entry) => ({\n tool: entry.tool,\n version: entry.version,\n schemaNarrowing: entry.schema_narrowing\n ? {\n dropInputs: entry.schema_narrowing.drop_inputs,\n dropOutputs: entry.schema_narrowing.drop_outputs,\n }\n : undefined,\n mapping: entry.mapping,\n costOverride: entry.cost_override as DriverDefinition[\"costOverride\"],\n timeoutOverrideMs: entry.timeout_override_ms,\n retryOverride: entry.retry_override as DriverDefinition[\"retryOverride\"],\n metadata: entry.metadata,\n })),\n execute: args.execute,\n implementations: args.implementations,\n network: fm.network,\n region: fm.region,\n policyTags: fm.policy_tags,\n timeoutOverrideMs: fm.timeout_override_ms,\n tags: fm.tags,\n metadata: fm.metadata,\n }\n\n return defineDriver(definition)\n}\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { D as DriverDefinition, a as DriverHandle, R as ResolverContext, b as ResolverResult, M as MappingValue } from './types-U3ItqOQG.js';
|
|
2
|
+
export { A as AuthConfig, c as AuthLoginConfig, d as AuthRefreshConfig, C as CostOverride, e as DetectExpiryArgs, f as DriverContext, E as ExecuteArgs, g as ExecuteFn, H as HealthCheckConfig, I as ImplementsEntry, h as InstallMethod, L as LoginArgs, i as LoginResult, P as ParseOutputArgs, j as ParseOutputResult, k as RefreshArgs, l as RefreshResult, m as ResolverInput, n as RetryPolicy, T as ToolImplementation, o as TypedExecuteFn, V as VersionCheck, p as implementTool } from './types-U3ItqOQG.js';
|
|
3
|
+
import { ToolHandle, ToolContext } from '@agentproto/tool';
|
|
4
|
+
import * as _agentproto_manifest from '@agentproto/manifest';
|
|
5
|
+
import { DoctypeSpec } from '@agentproto/manifest';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* AIP-30 reference implementation of `defineDriver`.
|
|
9
|
+
*
|
|
10
|
+
* Returns a {@link DriverHandle} with defaults applied. The resolver
|
|
11
|
+
* (`resolveDriver`) and runners (`runTool`) consume this shape and
|
|
12
|
+
* dispatch contract calls to the per-tool execute bodies.
|
|
13
|
+
*
|
|
14
|
+
* Built on `createDoctype` from `@agentproto/define-doctype`: the
|
|
15
|
+
* id-pattern + description-length validation and the top-level
|
|
16
|
+
* `Object.freeze` are shared with every other AIP defineX. The
|
|
17
|
+
* spec-30-specific parts (implements vs execute consistency, merging
|
|
18
|
+
* `implementations[]` into the execute map, freezing nested arrays
|
|
19
|
+
* and objects) live in `validate` and `build` below.
|
|
20
|
+
*
|
|
21
|
+
* Conformance highlights ([§ Conformance rules](https://agentproto.sh/docs/aip-30)):
|
|
22
|
+
* - Frontmatter is the source of truth — entries warn on mismatch and prefer frontmatter.
|
|
23
|
+
* - `execute[<toolId>]` MUST exist for every `implements[]` entry.
|
|
24
|
+
* - No I/O at module load — `defineDriver(...)` is pure construction.
|
|
25
|
+
*
|
|
26
|
+
* Two body-binding paths are accepted:
|
|
27
|
+
*
|
|
28
|
+
* 1. **Legacy bag** — `execute: { [toolId]: ExecuteFn }`. Used by
|
|
29
|
+
* `.md`-driven dynamic loading where the contract handle isn't
|
|
30
|
+
* in scope. Bodies receive `unknown`-typed inputs and must cast.
|
|
31
|
+
* 2. **Typed implementations** — `implementations: ToolImplementation[]`.
|
|
32
|
+
* Each impl carries its contract handle so the body's `input`,
|
|
33
|
+
* `context`, and return are checked against the contract's
|
|
34
|
+
* generics at compile time. Authors get IERC20-style type safety.
|
|
35
|
+
*
|
|
36
|
+
* Both can coexist on the same provider. On the same tool id, the
|
|
37
|
+
* typed `implementations[]` form wins over the legacy bag.
|
|
38
|
+
*/
|
|
39
|
+
declare const defineDriver: (def: DriverDefinition) => DriverHandle;
|
|
40
|
+
/**
|
|
41
|
+
* Normalise a tool ref (`./tools/foo/TOOL.md`, `tools/foo`,
|
|
42
|
+
* `foo`) to its canonical id used as the `execute` map key.
|
|
43
|
+
*
|
|
44
|
+
* v1: strip leading `./`, strip `/TOOL.md` suffix, strip `tools/`
|
|
45
|
+
* prefix, take the last path segment when no other normalisation
|
|
46
|
+
* applies. Matches the convention in EXAMPLES.md.
|
|
47
|
+
*/
|
|
48
|
+
declare function normalizeToolId(ref: string): string;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* AIP-30 6-phase resolver. Picks one provider per call.
|
|
52
|
+
*
|
|
53
|
+
* Algorithm summary (full description in AIP-30 § Multi-provider routing):
|
|
54
|
+
*
|
|
55
|
+
* Phase 1 — Candidate set: filter providers implementing(tool.id) and
|
|
56
|
+
* respecting tool.driverConstraints (forbid / requireKind)
|
|
57
|
+
* and per-call schema_narrowing compatibility.
|
|
58
|
+
* Phase 2 — Capability gate: drop providers with failed install /
|
|
59
|
+
* version_check or stale failed health_check.
|
|
60
|
+
* Phase 3 — Policy filter: drop providers violating policy_tags
|
|
61
|
+
* allowlist or missing region match.
|
|
62
|
+
* Phase 4 — Pin override: if context.pinnedProvider, return it or fail.
|
|
63
|
+
* Phase 5 — Cost / preference rank: default_driver first, else by
|
|
64
|
+
* cost_units_per_call → kind preference → recency → lex(id).
|
|
65
|
+
* Phase 6 — Bind: return { provider, implementsEntry }.
|
|
66
|
+
*/
|
|
67
|
+
declare function resolveDriver(args: {
|
|
68
|
+
tool: ToolHandle;
|
|
69
|
+
candidates: readonly DriverHandle[];
|
|
70
|
+
context: ResolverContext;
|
|
71
|
+
/** Inputs the call is using; used in narrowing compatibility check. */
|
|
72
|
+
inputKeys?: readonly string[];
|
|
73
|
+
/** Per-provider availability (capability gate from Phase 2). */
|
|
74
|
+
availability?: Map<string, DriverAvailability>;
|
|
75
|
+
}): ResolverResult;
|
|
76
|
+
interface DriverAvailability {
|
|
77
|
+
installFailed?: boolean;
|
|
78
|
+
versionMismatch?: boolean;
|
|
79
|
+
authState?: "unknown" | "unauthed" | "authed" | "expired";
|
|
80
|
+
healthCheckFailedRecently?: boolean;
|
|
81
|
+
/** Last successful health-check timestamp, ISO-8601. */
|
|
82
|
+
lastHealthOk?: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* End-to-end dispatch of a TOOL contract through the AIP-30 resolver.
|
|
87
|
+
*
|
|
88
|
+
* 1. Resolve a provider via the 6-phase resolver.
|
|
89
|
+
* 2. Validate input + context against the contract's schemas (host's job, not provider's).
|
|
90
|
+
* 3. Apply mapping + schema-narrowing (refuse calls using dropped inputs).
|
|
91
|
+
* 4. Build per-call DriverContext (resolved secrets, signal).
|
|
92
|
+
* 5. Invoke `provider.execute[tool.id]({ input, context, driverCtx, signal })`.
|
|
93
|
+
* 6. Validate output against contract's outputSchema.
|
|
94
|
+
* 7. Return the typed result.
|
|
95
|
+
*
|
|
96
|
+
* Errors throw {@link ToolError}; consumers wrap into the standard
|
|
97
|
+
* `ToolResult<T>` envelope at the boundary.
|
|
98
|
+
*/
|
|
99
|
+
declare function runTool<TInput, TOutput, TContext extends ToolContext>(args: {
|
|
100
|
+
tool: ToolHandle<TInput, TOutput, TContext>;
|
|
101
|
+
candidates: readonly DriverHandle[];
|
|
102
|
+
input: unknown;
|
|
103
|
+
context?: unknown;
|
|
104
|
+
resolverContext?: ResolverContext;
|
|
105
|
+
availability?: Map<string, DriverAvailability>;
|
|
106
|
+
/** Resolved secrets to inject into DriverContext. */
|
|
107
|
+
secrets?: Record<string, string>;
|
|
108
|
+
/** Caller-set abort signal. Must be honoured. */
|
|
109
|
+
signal?: AbortSignal;
|
|
110
|
+
}): Promise<TOutput>;
|
|
111
|
+
/**
|
|
112
|
+
* Apply the implements entry's `mapping` to the input shape. v1
|
|
113
|
+
* supports identity rename (`prompt: prompt`), key rename
|
|
114
|
+
* (`style: artistic_style`), and `{ from, transform }` (the runtime
|
|
115
|
+
* looks up `transform` on the provider's transformer registry — out
|
|
116
|
+
* of scope for v1; we pass through the original value).
|
|
117
|
+
*
|
|
118
|
+
* When `mapping` is omitted, the input is returned verbatim.
|
|
119
|
+
*/
|
|
120
|
+
declare function applyMapping(input: unknown, mapping: Record<string, MappingValue> | undefined): unknown;
|
|
121
|
+
|
|
122
|
+
declare const driverSpec: DoctypeSpec<DriverDefinition, DriverHandle>;
|
|
123
|
+
declare const driverVerbs: _agentproto_manifest.Verbs<DriverDefinition, DriverHandle>;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @agentproto/driver — AIP-30 DRIVER.md `defineDriver`
|
|
127
|
+
* reference implementation + 6-phase resolver + per-call dispatch.
|
|
128
|
+
*
|
|
129
|
+
* Spec: https://agentproto.sh/docs/aip-30
|
|
130
|
+
*/
|
|
131
|
+
declare const SPEC_NAME: "agentdriver/v1";
|
|
132
|
+
declare const SPEC_VERSION: "1.0.0-alpha";
|
|
133
|
+
|
|
134
|
+
export { type DriverAvailability, DriverDefinition, DriverHandle, MappingValue, ResolverContext, ResolverResult, SPEC_NAME, SPEC_VERSION, applyMapping, defineDriver, driverSpec, driverVerbs, normalizeToolId, resolveDriver, runTool };
|