@agents24/node 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +42 -0
- package/compatibility.json +54 -0
- package/dist/artifacts.cjs +138 -0
- package/dist/artifacts.cjs.map +1 -0
- package/dist/artifacts.d.cts +76 -0
- package/dist/artifacts.d.ts +76 -0
- package/dist/artifacts.js +130 -0
- package/dist/artifacts.js.map +1 -0
- package/dist/index.cjs +733 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +564 -0
- package/dist/index.d.ts +564 -0
- package/dist/index.js +667 -0
- package/dist/index.js.map +1 -0
- package/dist/server.cjs +275 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +47 -0
- package/dist/server.d.ts +47 -0
- package/dist/server.js +271 -0
- package/dist/server.js.map +1 -0
- package/dist/types/agents.d.ts +28 -0
- package/dist/types/agents.d.ts.map +1 -0
- package/dist/types/artifacts.d.ts +75 -0
- package/dist/types/artifacts.d.ts.map +1 -0
- package/dist/types/builders.d.ts +27 -0
- package/dist/types/builders.d.ts.map +1 -0
- package/dist/types/client-runtime-admin.d.ts +17 -0
- package/dist/types/client-runtime-admin.d.ts.map +1 -0
- package/dist/types/client.d.ts +17 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/embed.d.ts +22 -0
- package/dist/types/embed.d.ts.map +1 -0
- package/dist/types/errors.d.ts +17 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/generated/manifest.d.ts +3 -0
- package/dist/types/generated/manifest.d.ts.map +1 -0
- package/dist/types/http.d.ts +25 -0
- package/dist/types/http.d.ts.map +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/runs.d.ts +17 -0
- package/dist/types/runs.d.ts.map +1 -0
- package/dist/types/server.d.ts +45 -0
- package/dist/types/server.d.ts.map +1 -0
- package/dist/types/streams.d.ts +4 -0
- package/dist/types/streams.d.ts.map +1 -0
- package/dist/types/types.d.ts +409 -0
- package/dist/types/types.d.ts.map +1 -0
- package/package.json +85 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Talmudpedia
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# `@agents24/node`
|
|
2
|
+
|
|
3
|
+
Last Updated: 2026-07-16
|
|
4
|
+
|
|
5
|
+
Trusted-server Agents24 SDK for organization-authenticated control-plane, server embed, authoring, artifact, client-deployment, and client-session mint operations. It supports Node 22 and 24 with ESM and CJS entrypoints.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { Agents24 } from "@agents24/node";
|
|
9
|
+
|
|
10
|
+
const agents24 = new Agents24({
|
|
11
|
+
baseUrl: process.env.AGENTS24_BASE_URL!,
|
|
12
|
+
apiKey: process.env.AGENTS24_API_KEY!,
|
|
13
|
+
organizationId: process.env.AGENTS24_ORGANIZATION_ID!,
|
|
14
|
+
projectId: process.env.AGENTS24_PROJECT_ID!,
|
|
15
|
+
});
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Create a browser session from a customer backend without sending customer identity to the browser runtime:
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
const session = await agents24.clientSessions.createBackendSession(
|
|
22
|
+
"deployment-id",
|
|
23
|
+
{
|
|
24
|
+
subject: authenticatedCustomer.id,
|
|
25
|
+
browser_origin: "https://app.example.com",
|
|
26
|
+
requested_capabilities: ["chat.stream", "threads.read"],
|
|
27
|
+
},
|
|
28
|
+
{ idempotencyKey: request.id },
|
|
29
|
+
);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Administer deployments through `agents24.clientDeployments`; use `agents24.agents`, `agents24.runs`, and `agents24.embed` for trusted Agent operations. End-user token networking remains in `@agents24/client`.
|
|
33
|
+
|
|
34
|
+
Artifact source imports the transport-free declaration DSL:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { defineArtifact, tool } from "@agents24/node/artifacts";
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Self-hosted Node artifact servers use `@agents24/node/server`. That server subpath does not re-export the declaration DSL.
|
|
41
|
+
|
|
42
|
+
This package is server-only. Never expose an organization API key to browser code. Persistent or native client-session enrollment requires DPoP; pass the proof as `dpopProof` in the mint request options and read a nonce challenge from `Agents24SDKError.responseHeaders`.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"contractHash": "de2b507f5d56de2bf7c4d6739c03617c4b4feef6ae827aaaac5f1d6150ec678e",
|
|
3
|
+
"contractVersion": "0.2.0",
|
|
4
|
+
"corpus": "conformance/v1/corpus.json",
|
|
5
|
+
"generatedBy": "@agents24/sdk-contract",
|
|
6
|
+
"packages": {
|
|
7
|
+
"@agents24/ai-sdk": {
|
|
8
|
+
"ai": ">=7 <8",
|
|
9
|
+
"aiSdkReact": ">=4 <5",
|
|
10
|
+
"peer": "@agents24/client"
|
|
11
|
+
},
|
|
12
|
+
"@agents24/chat-react": {
|
|
13
|
+
"peer": "@agents24/react",
|
|
14
|
+
"react": ">=19 <20",
|
|
15
|
+
"reactDom": ">=19 <20"
|
|
16
|
+
},
|
|
17
|
+
"@agents24/client": {
|
|
18
|
+
"contract": "de2b507f5d56de2bf7c4d6739c03617c4b4feef6ae827aaaac5f1d6150ec678e",
|
|
19
|
+
"runtime": "run-stream.v2"
|
|
20
|
+
},
|
|
21
|
+
"@agents24/node": {
|
|
22
|
+
"contract": "de2b507f5d56de2bf7c4d6739c03617c4b4feef6ae827aaaac5f1d6150ec678e",
|
|
23
|
+
"node": "^22.0.0 || ^24.0.0"
|
|
24
|
+
},
|
|
25
|
+
"@agents24/react": {
|
|
26
|
+
"peer": "@agents24/client",
|
|
27
|
+
"react": ">=19 <20"
|
|
28
|
+
},
|
|
29
|
+
"@talmudpedia/runtime-sdk": {
|
|
30
|
+
"contract": "de2b507f5d56de2bf7c4d6739c03617c4b4feef6ae827aaaac5f1d6150ec678e",
|
|
31
|
+
"protocolOwner": "@agents24/client"
|
|
32
|
+
},
|
|
33
|
+
"agents24": {
|
|
34
|
+
"contract": "de2b507f5d56de2bf7c4d6739c03617c4b4feef6ae827aaaac5f1d6150ec678e",
|
|
35
|
+
"python": ">=3.10"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"protocols": {
|
|
39
|
+
"runtime": {
|
|
40
|
+
"minimum": "2.0.0",
|
|
41
|
+
"wire": "run-stream.v2"
|
|
42
|
+
},
|
|
43
|
+
"threadSummary": {
|
|
44
|
+
"minimum": "1.0.0",
|
|
45
|
+
"wire": "agents24.thread_summary_event.v1"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"schemaVersion": "agents24.compatibility.v1",
|
|
49
|
+
"targetOperationCounts": {
|
|
50
|
+
"client": 19,
|
|
51
|
+
"node": 55,
|
|
52
|
+
"python": 55
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/artifacts-runtime.mjs
|
|
4
|
+
function schema(value) {
|
|
5
|
+
if (value == null) return {};
|
|
6
|
+
if (typeof value.toJSONSchema === "function") return value.toJSONSchema();
|
|
7
|
+
if (typeof value.toJsonSchema === "function") return value.toJsonSchema();
|
|
8
|
+
if (typeof value === "object") {
|
|
9
|
+
if (typeof value.parse === "function" && typeof value.safeParse === "function" && value._zod) {
|
|
10
|
+
throw new TypeError("Zod schemas must expose toJSONSchema(); install Zod v4 or pass z.toJSONSchema(schema)");
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
throw new TypeError("schema must be a JSON Schema object or expose toJSONSchema()");
|
|
15
|
+
}
|
|
16
|
+
function normalize(kind, definition = {}, handler) {
|
|
17
|
+
const actualHandler = handler || definition.handler || definition.execute;
|
|
18
|
+
const explicitName = String(definition.name || "").trim();
|
|
19
|
+
const name = explicitName || String(actualHandler?.name || "").trim();
|
|
20
|
+
const value = {
|
|
21
|
+
name,
|
|
22
|
+
kind,
|
|
23
|
+
description: definition.description || "",
|
|
24
|
+
input_schema: schema(definition.input_schema || definition.inputSchema || definition.input),
|
|
25
|
+
output_schema: schema(definition.output_schema || definition.outputSchema || definition.output),
|
|
26
|
+
config_schema: schema(definition.config_schema || definition.configSchema || definition.config),
|
|
27
|
+
ui_schema: definition.ui_schema || definition.uiSchema || definition.ui || {},
|
|
28
|
+
side_effects: definition.side_effects || definition.sideEffects || [],
|
|
29
|
+
execution_mode: definition.execution_mode || definition.executionMode || "interactive",
|
|
30
|
+
handler_ref: definition.handler_ref || definition.handlerRef || actualHandler?.name || name,
|
|
31
|
+
handler: actualHandler
|
|
32
|
+
};
|
|
33
|
+
Object.defineProperty(value, "__agents24ExplicitName", { value: Boolean(explicitName), enumerable: false });
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
function tool(definition = {}, handler) {
|
|
37
|
+
return normalize("tool", definition, handler);
|
|
38
|
+
}
|
|
39
|
+
function agentNode(definition = {}, handler) {
|
|
40
|
+
return normalize("agent_node", definition, handler);
|
|
41
|
+
}
|
|
42
|
+
function ragOperator(definition = {}, handler) {
|
|
43
|
+
return normalize("rag_operator", definition, handler);
|
|
44
|
+
}
|
|
45
|
+
function toolset(definition = {}) {
|
|
46
|
+
return {
|
|
47
|
+
__agents24Toolset: true,
|
|
48
|
+
name: String(definition.name || "").trim(),
|
|
49
|
+
description: String(definition.description || "").trim(),
|
|
50
|
+
tools: Array.isArray(definition.tools) ? definition.tools : []
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function entries(input) {
|
|
54
|
+
if (Array.isArray(input)) return input.map((item) => [null, item]);
|
|
55
|
+
return input && typeof input === "object" ? Object.entries(input) : [];
|
|
56
|
+
}
|
|
57
|
+
function normalizedExports(definition) {
|
|
58
|
+
const exports = [];
|
|
59
|
+
const namesByObject = /* @__PURE__ */ new Map();
|
|
60
|
+
for (const source of [definition.tools, definition.agentNodes, definition.ragOperators]) {
|
|
61
|
+
for (const [mappedName, raw] of entries(source)) {
|
|
62
|
+
if (!raw || typeof raw !== "object") throw new TypeError("Artifact exports must use tool, agentNode, or ragOperator");
|
|
63
|
+
const name = raw.__agents24ExplicitName ? raw.name.trim() : String(mappedName || raw.name || "").trim();
|
|
64
|
+
if (!name) throw new TypeError("Artifact exports require a name");
|
|
65
|
+
exports.push({ ...raw, name, handler_ref: raw.handler_ref || name });
|
|
66
|
+
namesByObject.set(raw, [...namesByObject.get(raw) || [], name]);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const names = exports.map((item) => item.name);
|
|
70
|
+
const duplicate = names.find((name, index) => names.indexOf(name) !== index);
|
|
71
|
+
if (duplicate) throw new TypeError(`Duplicate artifact export name '${duplicate}'`);
|
|
72
|
+
return { exports, namesByObject };
|
|
73
|
+
}
|
|
74
|
+
function normalizedToolsets(input, exports, namesByObject) {
|
|
75
|
+
if (input == null) return [];
|
|
76
|
+
if (Array.isArray(input) || typeof input !== "object") {
|
|
77
|
+
throw new TypeError("TypeScript artifact toolsets must be an object keyed by stable source key");
|
|
78
|
+
}
|
|
79
|
+
const tools = new Set(exports.filter((item) => item.kind === "tool").map((item) => item.name));
|
|
80
|
+
const seenNames = /* @__PURE__ */ new Set();
|
|
81
|
+
return Object.entries(input).map(([key, value]) => {
|
|
82
|
+
if (!key.trim()) throw new TypeError("Artifact toolset keys cannot be empty");
|
|
83
|
+
if (!value?.__agents24Toolset) throw new TypeError(`Toolset '${key}' must use toolset()`);
|
|
84
|
+
if (!value.name || !value.description || !value.tools.length) {
|
|
85
|
+
throw new TypeError(`Toolset '${key}' requires a name, description, and tool`);
|
|
86
|
+
}
|
|
87
|
+
const folded = value.name.toLocaleLowerCase();
|
|
88
|
+
if (seenNames.has(folded)) throw new TypeError(`Duplicate artifact toolset name '${value.name}'`);
|
|
89
|
+
seenNames.add(folded);
|
|
90
|
+
const members = value.tools.map((reference) => {
|
|
91
|
+
if (typeof reference === "string") return reference.trim();
|
|
92
|
+
const aliases = namesByObject.get(reference) || [];
|
|
93
|
+
if (aliases.length !== 1) throw new TypeError(`Toolset '${key}' contains an unresolved or ambiguous tool reference`);
|
|
94
|
+
return aliases[0];
|
|
95
|
+
});
|
|
96
|
+
if (new Set(members).size !== members.length) throw new TypeError(`Toolset '${key}' contains duplicate tools`);
|
|
97
|
+
for (const member of members) {
|
|
98
|
+
if (!tools.has(member)) throw new TypeError(`Toolset '${key}' references missing or non-tool export '${member}'`);
|
|
99
|
+
}
|
|
100
|
+
return { key, name: value.name, description: value.description, tools: members };
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function defineArtifact(definition = {}) {
|
|
104
|
+
const normalized = normalizedExports(definition);
|
|
105
|
+
return {
|
|
106
|
+
__agents24Artifact: true,
|
|
107
|
+
exports: normalized.exports,
|
|
108
|
+
toolsets: normalizedToolsets(definition.toolsets, normalized.exports, normalized.namesByObject),
|
|
109
|
+
__agents24ToolsetsDeclared: definition.toolsets != null
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function describeArtifact(value) {
|
|
113
|
+
const artifact = value && value.__agents24Artifact ? value : defineArtifact(value || {});
|
|
114
|
+
return artifact.exports.map(({ handler: _handler, ...item }) => item);
|
|
115
|
+
}
|
|
116
|
+
function describeArtifactContract(value) {
|
|
117
|
+
const artifact = value && value.__agents24Artifact ? value : defineArtifact(value || {});
|
|
118
|
+
return { exports: describeArtifact(artifact), toolsets: artifact.toolsets.map((item) => ({ ...item })) };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/artifacts.ts
|
|
122
|
+
var tool2 = tool;
|
|
123
|
+
var agentNode2 = agentNode;
|
|
124
|
+
var ragOperator2 = ragOperator;
|
|
125
|
+
var toolset2 = toolset;
|
|
126
|
+
var defineArtifact2 = defineArtifact;
|
|
127
|
+
var describeArtifact2 = describeArtifact;
|
|
128
|
+
var describeArtifactContract2 = describeArtifactContract;
|
|
129
|
+
|
|
130
|
+
exports.agentNode = agentNode2;
|
|
131
|
+
exports.defineArtifact = defineArtifact2;
|
|
132
|
+
exports.describeArtifact = describeArtifact2;
|
|
133
|
+
exports.describeArtifactContract = describeArtifactContract2;
|
|
134
|
+
exports.ragOperator = ragOperator2;
|
|
135
|
+
exports.tool = tool2;
|
|
136
|
+
exports.toolset = toolset2;
|
|
137
|
+
//# sourceMappingURL=artifacts.cjs.map
|
|
138
|
+
//# sourceMappingURL=artifacts.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/artifacts-runtime.mjs","../src/artifacts.ts"],"names":["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AAAA,GAAoB;AAI1B,IAAMC,YAAAA,GAAsB;AAI5B,IAAMC,QAAAA,GAAkB;AAGxB,IAAMC,eAAAA,GAAyB;AAG/B,IAAMC,iBAAAA,GAA2B;AAGjC,IAAMC,yBAAAA,GAAmC","file":"artifacts.cjs","sourcesContent":["function schema(value) {\n if (value == null) return {};\n if (typeof value.toJSONSchema === \"function\") return value.toJSONSchema();\n if (typeof value.toJsonSchema === \"function\") return value.toJsonSchema();\n if (typeof value === \"object\") {\n if (typeof value.parse === \"function\" && typeof value.safeParse === \"function\" && value._zod) {\n throw new TypeError(\"Zod schemas must expose toJSONSchema(); install Zod v4 or pass z.toJSONSchema(schema)\");\n }\n return value;\n }\n throw new TypeError(\"schema must be a JSON Schema object or expose toJSONSchema()\");\n}\n\nfunction normalize(kind, definition = {}, handler) {\n const actualHandler = handler || definition.handler || definition.execute;\n const explicitName = String(definition.name || \"\").trim();\n const name = explicitName || String(actualHandler?.name || \"\").trim();\n const value = {\n name,\n kind,\n description: definition.description || \"\",\n input_schema: schema(definition.input_schema || definition.inputSchema || definition.input),\n output_schema: schema(definition.output_schema || definition.outputSchema || definition.output),\n config_schema: schema(definition.config_schema || definition.configSchema || definition.config),\n ui_schema: definition.ui_schema || definition.uiSchema || definition.ui || {},\n side_effects: definition.side_effects || definition.sideEffects || [],\n execution_mode: definition.execution_mode || definition.executionMode || \"interactive\",\n handler_ref: definition.handler_ref || definition.handlerRef || actualHandler?.name || name,\n handler: actualHandler,\n };\n Object.defineProperty(value, \"__agents24ExplicitName\", { value: Boolean(explicitName), enumerable: false });\n return value;\n}\n\nexport function tool(definition = {}, handler) {\n return normalize(\"tool\", definition, handler);\n}\n\nexport function agentNode(definition = {}, handler) {\n return normalize(\"agent_node\", definition, handler);\n}\n\nexport function ragOperator(definition = {}, handler) {\n return normalize(\"rag_operator\", definition, handler);\n}\n\nexport function toolset(definition = {}) {\n return {\n __agents24Toolset: true,\n name: String(definition.name || \"\").trim(),\n description: String(definition.description || \"\").trim(),\n tools: Array.isArray(definition.tools) ? definition.tools : [],\n };\n}\n\nfunction entries(input) {\n if (Array.isArray(input)) return input.map((item) => [null, item]);\n return input && typeof input === \"object\" ? Object.entries(input) : [];\n}\n\nfunction normalizedExports(definition) {\n const exports = [];\n const namesByObject = new Map();\n for (const source of [definition.tools, definition.agentNodes, definition.ragOperators]) {\n for (const [mappedName, raw] of entries(source)) {\n if (!raw || typeof raw !== \"object\") throw new TypeError(\"Artifact exports must use tool, agentNode, or ragOperator\");\n const name = raw.__agents24ExplicitName ? raw.name.trim() : String(mappedName || raw.name || \"\").trim();\n if (!name) throw new TypeError(\"Artifact exports require a name\");\n exports.push({ ...raw, name, handler_ref: raw.handler_ref || name });\n namesByObject.set(raw, [...(namesByObject.get(raw) || []), name]);\n }\n }\n const names = exports.map((item) => item.name);\n const duplicate = names.find((name, index) => names.indexOf(name) !== index);\n if (duplicate) throw new TypeError(`Duplicate artifact export name '${duplicate}'`);\n return { exports, namesByObject };\n}\n\nfunction normalizedToolsets(input, exports, namesByObject) {\n if (input == null) return [];\n if (Array.isArray(input) || typeof input !== \"object\") {\n throw new TypeError(\"TypeScript artifact toolsets must be an object keyed by stable source key\");\n }\n const tools = new Set(exports.filter((item) => item.kind === \"tool\").map((item) => item.name));\n const seenNames = new Set();\n return Object.entries(input).map(([key, value]) => {\n if (!key.trim()) throw new TypeError(\"Artifact toolset keys cannot be empty\");\n if (!value?.__agents24Toolset) throw new TypeError(`Toolset '${key}' must use toolset()`);\n if (!value.name || !value.description || !value.tools.length) {\n throw new TypeError(`Toolset '${key}' requires a name, description, and tool`);\n }\n const folded = value.name.toLocaleLowerCase();\n if (seenNames.has(folded)) throw new TypeError(`Duplicate artifact toolset name '${value.name}'`);\n seenNames.add(folded);\n const members = value.tools.map((reference) => {\n if (typeof reference === \"string\") return reference.trim();\n const aliases = namesByObject.get(reference) || [];\n if (aliases.length !== 1) throw new TypeError(`Toolset '${key}' contains an unresolved or ambiguous tool reference`);\n return aliases[0];\n });\n if (new Set(members).size !== members.length) throw new TypeError(`Toolset '${key}' contains duplicate tools`);\n for (const member of members) {\n if (!tools.has(member)) throw new TypeError(`Toolset '${key}' references missing or non-tool export '${member}'`);\n }\n return { key, name: value.name, description: value.description, tools: members };\n });\n}\n\nexport function defineArtifact(definition = {}) {\n const normalized = normalizedExports(definition);\n return {\n __agents24Artifact: true,\n exports: normalized.exports,\n toolsets: normalizedToolsets(definition.toolsets, normalized.exports, normalized.namesByObject),\n __agents24ToolsetsDeclared: definition.toolsets != null,\n };\n}\n\nexport function describeArtifact(value) {\n const artifact = value && value.__agents24Artifact ? value : defineArtifact(value || {});\n return artifact.exports.map(({ handler: _handler, ...item }) => item);\n}\n\nexport function describeArtifactContract(value) {\n const artifact = value && value.__agents24Artifact ? value : defineArtifact(value || {});\n return { exports: describeArtifact(artifact), toolsets: artifact.toolsets.map((item) => ({ ...item })) };\n}\n","// The executable implementation is JavaScript so the platform can inject the\n// exact same source into Worker describe/build sandboxes without transpilation.\n// @ts-expect-error package-internal JavaScript runtime has typed bindings below\nimport * as runtime from \"./artifacts-runtime.mjs\";\n\nexport type JsonSchemaSource = Record<string, unknown> | {\n toJSONSchema?: () => Record<string, unknown>;\n toJsonSchema?: () => Record<string, unknown>;\n};\n\nexport type ArtifactHandler = (\n input: unknown,\n config: Record<string, unknown>,\n context: Record<string, unknown>,\n) => unknown | Promise<unknown>;\n\nexport type ArtifactExportDefinition = {\n name?: string;\n description?: string;\n input_schema?: JsonSchemaSource;\n inputSchema?: JsonSchemaSource;\n input?: JsonSchemaSource;\n output_schema?: JsonSchemaSource;\n outputSchema?: JsonSchemaSource;\n output?: JsonSchemaSource;\n config_schema?: JsonSchemaSource;\n configSchema?: JsonSchemaSource;\n config?: JsonSchemaSource;\n ui_schema?: Record<string, unknown>;\n uiSchema?: Record<string, unknown>;\n ui?: Record<string, unknown>;\n side_effects?: string[];\n sideEffects?: string[];\n execution_mode?: string;\n executionMode?: string;\n handler_ref?: string;\n handlerRef?: string;\n handler?: ArtifactHandler;\n execute?: ArtifactHandler;\n};\n\nexport type ArtifactExport = {\n name: string;\n kind: \"tool\" | \"agent_node\" | \"rag_operator\";\n description: string;\n input_schema: Record<string, unknown>;\n output_schema: Record<string, unknown>;\n config_schema: Record<string, unknown>;\n ui_schema: Record<string, unknown>;\n side_effects: string[];\n execution_mode: string;\n handler_ref: string;\n handler?: ArtifactHandler;\n readonly __agents24ExplicitName?: boolean;\n};\n\nexport type ArtifactToolset = {\n readonly __agents24Toolset: true;\n name: string;\n description: string;\n tools: Array<string | ArtifactExport>;\n};\n\nexport type ArtifactDefinition = {\n readonly __agents24Artifact: true;\n exports: ArtifactExport[];\n toolsets: Array<{ key: string; name: string; description: string; tools: string[] }>;\n readonly __agents24ToolsetsDeclared: boolean;\n};\n\nexport const tool = runtime.tool as (\n definition?: ArtifactExportDefinition,\n handler?: ArtifactHandler,\n) => ArtifactExport;\nexport const agentNode = runtime.agentNode as (\n definition?: ArtifactExportDefinition,\n handler?: ArtifactHandler,\n) => ArtifactExport;\nexport const ragOperator = runtime.ragOperator as (\n definition?: ArtifactExportDefinition,\n handler?: ArtifactHandler,\n) => ArtifactExport;\nexport const toolset = runtime.toolset as (\n definition?: { name?: string; description?: string; tools?: Array<string | ArtifactExport> },\n) => ArtifactToolset;\nexport const defineArtifact = runtime.defineArtifact as (\n definition?: Record<string, unknown>,\n) => ArtifactDefinition;\nexport const describeArtifact = runtime.describeArtifact as (\n value: ArtifactDefinition | Record<string, unknown>,\n) => Array<Omit<ArtifactExport, \"handler\">>;\nexport const describeArtifactContract = runtime.describeArtifactContract as (\n value: ArtifactDefinition | Record<string, unknown>,\n) => {\n exports: Array<Omit<ArtifactExport, \"handler\">>;\n toolsets: ArtifactDefinition[\"toolsets\"];\n};\n"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
type JsonSchemaSource = Record<string, unknown> | {
|
|
2
|
+
toJSONSchema?: () => Record<string, unknown>;
|
|
3
|
+
toJsonSchema?: () => Record<string, unknown>;
|
|
4
|
+
};
|
|
5
|
+
type ArtifactHandler = (input: unknown, config: Record<string, unknown>, context: Record<string, unknown>) => unknown | Promise<unknown>;
|
|
6
|
+
type ArtifactExportDefinition = {
|
|
7
|
+
name?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
input_schema?: JsonSchemaSource;
|
|
10
|
+
inputSchema?: JsonSchemaSource;
|
|
11
|
+
input?: JsonSchemaSource;
|
|
12
|
+
output_schema?: JsonSchemaSource;
|
|
13
|
+
outputSchema?: JsonSchemaSource;
|
|
14
|
+
output?: JsonSchemaSource;
|
|
15
|
+
config_schema?: JsonSchemaSource;
|
|
16
|
+
configSchema?: JsonSchemaSource;
|
|
17
|
+
config?: JsonSchemaSource;
|
|
18
|
+
ui_schema?: Record<string, unknown>;
|
|
19
|
+
uiSchema?: Record<string, unknown>;
|
|
20
|
+
ui?: Record<string, unknown>;
|
|
21
|
+
side_effects?: string[];
|
|
22
|
+
sideEffects?: string[];
|
|
23
|
+
execution_mode?: string;
|
|
24
|
+
executionMode?: string;
|
|
25
|
+
handler_ref?: string;
|
|
26
|
+
handlerRef?: string;
|
|
27
|
+
handler?: ArtifactHandler;
|
|
28
|
+
execute?: ArtifactHandler;
|
|
29
|
+
};
|
|
30
|
+
type ArtifactExport = {
|
|
31
|
+
name: string;
|
|
32
|
+
kind: "tool" | "agent_node" | "rag_operator";
|
|
33
|
+
description: string;
|
|
34
|
+
input_schema: Record<string, unknown>;
|
|
35
|
+
output_schema: Record<string, unknown>;
|
|
36
|
+
config_schema: Record<string, unknown>;
|
|
37
|
+
ui_schema: Record<string, unknown>;
|
|
38
|
+
side_effects: string[];
|
|
39
|
+
execution_mode: string;
|
|
40
|
+
handler_ref: string;
|
|
41
|
+
handler?: ArtifactHandler;
|
|
42
|
+
readonly __agents24ExplicitName?: boolean;
|
|
43
|
+
};
|
|
44
|
+
type ArtifactToolset = {
|
|
45
|
+
readonly __agents24Toolset: true;
|
|
46
|
+
name: string;
|
|
47
|
+
description: string;
|
|
48
|
+
tools: Array<string | ArtifactExport>;
|
|
49
|
+
};
|
|
50
|
+
type ArtifactDefinition = {
|
|
51
|
+
readonly __agents24Artifact: true;
|
|
52
|
+
exports: ArtifactExport[];
|
|
53
|
+
toolsets: Array<{
|
|
54
|
+
key: string;
|
|
55
|
+
name: string;
|
|
56
|
+
description: string;
|
|
57
|
+
tools: string[];
|
|
58
|
+
}>;
|
|
59
|
+
readonly __agents24ToolsetsDeclared: boolean;
|
|
60
|
+
};
|
|
61
|
+
declare const tool: (definition?: ArtifactExportDefinition, handler?: ArtifactHandler) => ArtifactExport;
|
|
62
|
+
declare const agentNode: (definition?: ArtifactExportDefinition, handler?: ArtifactHandler) => ArtifactExport;
|
|
63
|
+
declare const ragOperator: (definition?: ArtifactExportDefinition, handler?: ArtifactHandler) => ArtifactExport;
|
|
64
|
+
declare const toolset: (definition?: {
|
|
65
|
+
name?: string;
|
|
66
|
+
description?: string;
|
|
67
|
+
tools?: Array<string | ArtifactExport>;
|
|
68
|
+
}) => ArtifactToolset;
|
|
69
|
+
declare const defineArtifact: (definition?: Record<string, unknown>) => ArtifactDefinition;
|
|
70
|
+
declare const describeArtifact: (value: ArtifactDefinition | Record<string, unknown>) => Array<Omit<ArtifactExport, "handler">>;
|
|
71
|
+
declare const describeArtifactContract: (value: ArtifactDefinition | Record<string, unknown>) => {
|
|
72
|
+
exports: Array<Omit<ArtifactExport, "handler">>;
|
|
73
|
+
toolsets: ArtifactDefinition["toolsets"];
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export { type ArtifactDefinition, type ArtifactExport, type ArtifactExportDefinition, type ArtifactHandler, type ArtifactToolset, type JsonSchemaSource, agentNode, defineArtifact, describeArtifact, describeArtifactContract, ragOperator, tool, toolset };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
type JsonSchemaSource = Record<string, unknown> | {
|
|
2
|
+
toJSONSchema?: () => Record<string, unknown>;
|
|
3
|
+
toJsonSchema?: () => Record<string, unknown>;
|
|
4
|
+
};
|
|
5
|
+
type ArtifactHandler = (input: unknown, config: Record<string, unknown>, context: Record<string, unknown>) => unknown | Promise<unknown>;
|
|
6
|
+
type ArtifactExportDefinition = {
|
|
7
|
+
name?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
input_schema?: JsonSchemaSource;
|
|
10
|
+
inputSchema?: JsonSchemaSource;
|
|
11
|
+
input?: JsonSchemaSource;
|
|
12
|
+
output_schema?: JsonSchemaSource;
|
|
13
|
+
outputSchema?: JsonSchemaSource;
|
|
14
|
+
output?: JsonSchemaSource;
|
|
15
|
+
config_schema?: JsonSchemaSource;
|
|
16
|
+
configSchema?: JsonSchemaSource;
|
|
17
|
+
config?: JsonSchemaSource;
|
|
18
|
+
ui_schema?: Record<string, unknown>;
|
|
19
|
+
uiSchema?: Record<string, unknown>;
|
|
20
|
+
ui?: Record<string, unknown>;
|
|
21
|
+
side_effects?: string[];
|
|
22
|
+
sideEffects?: string[];
|
|
23
|
+
execution_mode?: string;
|
|
24
|
+
executionMode?: string;
|
|
25
|
+
handler_ref?: string;
|
|
26
|
+
handlerRef?: string;
|
|
27
|
+
handler?: ArtifactHandler;
|
|
28
|
+
execute?: ArtifactHandler;
|
|
29
|
+
};
|
|
30
|
+
type ArtifactExport = {
|
|
31
|
+
name: string;
|
|
32
|
+
kind: "tool" | "agent_node" | "rag_operator";
|
|
33
|
+
description: string;
|
|
34
|
+
input_schema: Record<string, unknown>;
|
|
35
|
+
output_schema: Record<string, unknown>;
|
|
36
|
+
config_schema: Record<string, unknown>;
|
|
37
|
+
ui_schema: Record<string, unknown>;
|
|
38
|
+
side_effects: string[];
|
|
39
|
+
execution_mode: string;
|
|
40
|
+
handler_ref: string;
|
|
41
|
+
handler?: ArtifactHandler;
|
|
42
|
+
readonly __agents24ExplicitName?: boolean;
|
|
43
|
+
};
|
|
44
|
+
type ArtifactToolset = {
|
|
45
|
+
readonly __agents24Toolset: true;
|
|
46
|
+
name: string;
|
|
47
|
+
description: string;
|
|
48
|
+
tools: Array<string | ArtifactExport>;
|
|
49
|
+
};
|
|
50
|
+
type ArtifactDefinition = {
|
|
51
|
+
readonly __agents24Artifact: true;
|
|
52
|
+
exports: ArtifactExport[];
|
|
53
|
+
toolsets: Array<{
|
|
54
|
+
key: string;
|
|
55
|
+
name: string;
|
|
56
|
+
description: string;
|
|
57
|
+
tools: string[];
|
|
58
|
+
}>;
|
|
59
|
+
readonly __agents24ToolsetsDeclared: boolean;
|
|
60
|
+
};
|
|
61
|
+
declare const tool: (definition?: ArtifactExportDefinition, handler?: ArtifactHandler) => ArtifactExport;
|
|
62
|
+
declare const agentNode: (definition?: ArtifactExportDefinition, handler?: ArtifactHandler) => ArtifactExport;
|
|
63
|
+
declare const ragOperator: (definition?: ArtifactExportDefinition, handler?: ArtifactHandler) => ArtifactExport;
|
|
64
|
+
declare const toolset: (definition?: {
|
|
65
|
+
name?: string;
|
|
66
|
+
description?: string;
|
|
67
|
+
tools?: Array<string | ArtifactExport>;
|
|
68
|
+
}) => ArtifactToolset;
|
|
69
|
+
declare const defineArtifact: (definition?: Record<string, unknown>) => ArtifactDefinition;
|
|
70
|
+
declare const describeArtifact: (value: ArtifactDefinition | Record<string, unknown>) => Array<Omit<ArtifactExport, "handler">>;
|
|
71
|
+
declare const describeArtifactContract: (value: ArtifactDefinition | Record<string, unknown>) => {
|
|
72
|
+
exports: Array<Omit<ArtifactExport, "handler">>;
|
|
73
|
+
toolsets: ArtifactDefinition["toolsets"];
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export { type ArtifactDefinition, type ArtifactExport, type ArtifactExportDefinition, type ArtifactHandler, type ArtifactToolset, type JsonSchemaSource, agentNode, defineArtifact, describeArtifact, describeArtifactContract, ragOperator, tool, toolset };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// src/artifacts-runtime.mjs
|
|
2
|
+
function schema(value) {
|
|
3
|
+
if (value == null) return {};
|
|
4
|
+
if (typeof value.toJSONSchema === "function") return value.toJSONSchema();
|
|
5
|
+
if (typeof value.toJsonSchema === "function") return value.toJsonSchema();
|
|
6
|
+
if (typeof value === "object") {
|
|
7
|
+
if (typeof value.parse === "function" && typeof value.safeParse === "function" && value._zod) {
|
|
8
|
+
throw new TypeError("Zod schemas must expose toJSONSchema(); install Zod v4 or pass z.toJSONSchema(schema)");
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
throw new TypeError("schema must be a JSON Schema object or expose toJSONSchema()");
|
|
13
|
+
}
|
|
14
|
+
function normalize(kind, definition = {}, handler) {
|
|
15
|
+
const actualHandler = handler || definition.handler || definition.execute;
|
|
16
|
+
const explicitName = String(definition.name || "").trim();
|
|
17
|
+
const name = explicitName || String(actualHandler?.name || "").trim();
|
|
18
|
+
const value = {
|
|
19
|
+
name,
|
|
20
|
+
kind,
|
|
21
|
+
description: definition.description || "",
|
|
22
|
+
input_schema: schema(definition.input_schema || definition.inputSchema || definition.input),
|
|
23
|
+
output_schema: schema(definition.output_schema || definition.outputSchema || definition.output),
|
|
24
|
+
config_schema: schema(definition.config_schema || definition.configSchema || definition.config),
|
|
25
|
+
ui_schema: definition.ui_schema || definition.uiSchema || definition.ui || {},
|
|
26
|
+
side_effects: definition.side_effects || definition.sideEffects || [],
|
|
27
|
+
execution_mode: definition.execution_mode || definition.executionMode || "interactive",
|
|
28
|
+
handler_ref: definition.handler_ref || definition.handlerRef || actualHandler?.name || name,
|
|
29
|
+
handler: actualHandler
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(value, "__agents24ExplicitName", { value: Boolean(explicitName), enumerable: false });
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
function tool(definition = {}, handler) {
|
|
35
|
+
return normalize("tool", definition, handler);
|
|
36
|
+
}
|
|
37
|
+
function agentNode(definition = {}, handler) {
|
|
38
|
+
return normalize("agent_node", definition, handler);
|
|
39
|
+
}
|
|
40
|
+
function ragOperator(definition = {}, handler) {
|
|
41
|
+
return normalize("rag_operator", definition, handler);
|
|
42
|
+
}
|
|
43
|
+
function toolset(definition = {}) {
|
|
44
|
+
return {
|
|
45
|
+
__agents24Toolset: true,
|
|
46
|
+
name: String(definition.name || "").trim(),
|
|
47
|
+
description: String(definition.description || "").trim(),
|
|
48
|
+
tools: Array.isArray(definition.tools) ? definition.tools : []
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function entries(input) {
|
|
52
|
+
if (Array.isArray(input)) return input.map((item) => [null, item]);
|
|
53
|
+
return input && typeof input === "object" ? Object.entries(input) : [];
|
|
54
|
+
}
|
|
55
|
+
function normalizedExports(definition) {
|
|
56
|
+
const exports = [];
|
|
57
|
+
const namesByObject = /* @__PURE__ */ new Map();
|
|
58
|
+
for (const source of [definition.tools, definition.agentNodes, definition.ragOperators]) {
|
|
59
|
+
for (const [mappedName, raw] of entries(source)) {
|
|
60
|
+
if (!raw || typeof raw !== "object") throw new TypeError("Artifact exports must use tool, agentNode, or ragOperator");
|
|
61
|
+
const name = raw.__agents24ExplicitName ? raw.name.trim() : String(mappedName || raw.name || "").trim();
|
|
62
|
+
if (!name) throw new TypeError("Artifact exports require a name");
|
|
63
|
+
exports.push({ ...raw, name, handler_ref: raw.handler_ref || name });
|
|
64
|
+
namesByObject.set(raw, [...namesByObject.get(raw) || [], name]);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const names = exports.map((item) => item.name);
|
|
68
|
+
const duplicate = names.find((name, index) => names.indexOf(name) !== index);
|
|
69
|
+
if (duplicate) throw new TypeError(`Duplicate artifact export name '${duplicate}'`);
|
|
70
|
+
return { exports, namesByObject };
|
|
71
|
+
}
|
|
72
|
+
function normalizedToolsets(input, exports, namesByObject) {
|
|
73
|
+
if (input == null) return [];
|
|
74
|
+
if (Array.isArray(input) || typeof input !== "object") {
|
|
75
|
+
throw new TypeError("TypeScript artifact toolsets must be an object keyed by stable source key");
|
|
76
|
+
}
|
|
77
|
+
const tools = new Set(exports.filter((item) => item.kind === "tool").map((item) => item.name));
|
|
78
|
+
const seenNames = /* @__PURE__ */ new Set();
|
|
79
|
+
return Object.entries(input).map(([key, value]) => {
|
|
80
|
+
if (!key.trim()) throw new TypeError("Artifact toolset keys cannot be empty");
|
|
81
|
+
if (!value?.__agents24Toolset) throw new TypeError(`Toolset '${key}' must use toolset()`);
|
|
82
|
+
if (!value.name || !value.description || !value.tools.length) {
|
|
83
|
+
throw new TypeError(`Toolset '${key}' requires a name, description, and tool`);
|
|
84
|
+
}
|
|
85
|
+
const folded = value.name.toLocaleLowerCase();
|
|
86
|
+
if (seenNames.has(folded)) throw new TypeError(`Duplicate artifact toolset name '${value.name}'`);
|
|
87
|
+
seenNames.add(folded);
|
|
88
|
+
const members = value.tools.map((reference) => {
|
|
89
|
+
if (typeof reference === "string") return reference.trim();
|
|
90
|
+
const aliases = namesByObject.get(reference) || [];
|
|
91
|
+
if (aliases.length !== 1) throw new TypeError(`Toolset '${key}' contains an unresolved or ambiguous tool reference`);
|
|
92
|
+
return aliases[0];
|
|
93
|
+
});
|
|
94
|
+
if (new Set(members).size !== members.length) throw new TypeError(`Toolset '${key}' contains duplicate tools`);
|
|
95
|
+
for (const member of members) {
|
|
96
|
+
if (!tools.has(member)) throw new TypeError(`Toolset '${key}' references missing or non-tool export '${member}'`);
|
|
97
|
+
}
|
|
98
|
+
return { key, name: value.name, description: value.description, tools: members };
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function defineArtifact(definition = {}) {
|
|
102
|
+
const normalized = normalizedExports(definition);
|
|
103
|
+
return {
|
|
104
|
+
__agents24Artifact: true,
|
|
105
|
+
exports: normalized.exports,
|
|
106
|
+
toolsets: normalizedToolsets(definition.toolsets, normalized.exports, normalized.namesByObject),
|
|
107
|
+
__agents24ToolsetsDeclared: definition.toolsets != null
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function describeArtifact(value) {
|
|
111
|
+
const artifact = value && value.__agents24Artifact ? value : defineArtifact(value || {});
|
|
112
|
+
return artifact.exports.map(({ handler: _handler, ...item }) => item);
|
|
113
|
+
}
|
|
114
|
+
function describeArtifactContract(value) {
|
|
115
|
+
const artifact = value && value.__agents24Artifact ? value : defineArtifact(value || {});
|
|
116
|
+
return { exports: describeArtifact(artifact), toolsets: artifact.toolsets.map((item) => ({ ...item })) };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// src/artifacts.ts
|
|
120
|
+
var tool2 = tool;
|
|
121
|
+
var agentNode2 = agentNode;
|
|
122
|
+
var ragOperator2 = ragOperator;
|
|
123
|
+
var toolset2 = toolset;
|
|
124
|
+
var defineArtifact2 = defineArtifact;
|
|
125
|
+
var describeArtifact2 = describeArtifact;
|
|
126
|
+
var describeArtifactContract2 = describeArtifactContract;
|
|
127
|
+
|
|
128
|
+
export { agentNode2 as agentNode, defineArtifact2 as defineArtifact, describeArtifact2 as describeArtifact, describeArtifactContract2 as describeArtifactContract, ragOperator2 as ragOperator, tool2 as tool, toolset2 as toolset };
|
|
129
|
+
//# sourceMappingURL=artifacts.js.map
|
|
130
|
+
//# sourceMappingURL=artifacts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/artifacts-runtime.mjs","../src/artifacts.ts"],"names":["tool","agentNode","ragOperator","toolset","defineArtifact","describeArtifact","describeArtifactContract"],"mappings":";AAAA,SAAS,OAAO,KAAA,EAAO;AACrB,EAAA,IAAI,KAAA,IAAS,IAAA,EAAM,OAAO,EAAC;AAC3B,EAAA,IAAI,OAAO,KAAA,CAAM,YAAA,KAAiB,UAAA,EAAY,OAAO,MAAM,YAAA,EAAa;AACxE,EAAA,IAAI,OAAO,KAAA,CAAM,YAAA,KAAiB,UAAA,EAAY,OAAO,MAAM,YAAA,EAAa;AACxE,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,IAAA,IAAI,OAAO,MAAM,KAAA,KAAU,UAAA,IAAc,OAAO,KAAA,CAAM,SAAA,KAAc,UAAA,IAAc,KAAA,CAAM,IAAA,EAAM;AAC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B,UAAA,CAAW,UAAU,UAAA,CAAW,OAAA,EAAS,WAAW,aAAa,CAAA;AAAA,IAC9F,0BAAA,EAA4B,WAAW,QAAA,IAAY;AAAA,GACrD;AACF;AAEO,SAAS,iBAAiB,KAAA,EAAO;AACtC,EAAA,MAAM,QAAA,GAAW,SAAS,KAAA,CAAM,kBAAA,GAAqB,QAAQ,cAAA,CAAe,KAAA,IAAS,EAAE,CAAA;AACvF,EAAA,OAAO,QAAA,CAAS,OAAA,CAAQ,GAAA,CAAI,CAAC,EAAE,SAAS,QAAA,EAAU,GAAG,IAAA,EAAK,KAAM,IAAI,CAAA;AACtE;AAEO,SAAS,yBAAyB,KAAA,EAAO;AAC9C,EAAA,MAAM,QAAA,GAAW,SAAS,KAAA,CAAM,kBAAA,GAAqB,QAAQ,cAAA,CAAe,KAAA,IAAS,EAAE,CAAA;AACvF,EAAA,OAAO,EAAE,OAAA,EAAS,gBAAA,CAAiB,QAAQ,GAAG,QAAA,EAAU,QAAA,CAAS,QAAA,CAAS,GAAA,CAAI,CAAC,IAAA,MAAU,EAAE,GAAG,IAAA,GAAO,CAAA,EAAE;AACzG;;;ACxDO,IAAMA,KAAAA,GAAe;AAIrB,IAAMC,UAAAA,GAAoB;AAI1B,IAAMC,YAAAA,GAAsB;AAI5B,IAAMC,QAAAA,GAAkB;AAGxB,IAAMC,eAAAA,GAAyB;AAG/B,IAAMC,iBAAAA,GAA2B;AAGjC,IAAMC,yBAAAA,GAAmC","file":"artifacts.js","sourcesContent":["function schema(value) {\n if (value == null) return {};\n if (typeof value.toJSONSchema === \"function\") return value.toJSONSchema();\n if (typeof value.toJsonSchema === \"function\") return value.toJsonSchema();\n if (typeof value === \"object\") {\n if (typeof value.parse === \"function\" && typeof value.safeParse === \"function\" && value._zod) {\n throw new TypeError(\"Zod schemas must expose toJSONSchema(); install Zod v4 or pass z.toJSONSchema(schema)\");\n }\n return value;\n }\n throw new TypeError(\"schema must be a JSON Schema object or expose toJSONSchema()\");\n}\n\nfunction normalize(kind, definition = {}, handler) {\n const actualHandler = handler || definition.handler || definition.execute;\n const explicitName = String(definition.name || \"\").trim();\n const name = explicitName || String(actualHandler?.name || \"\").trim();\n const value = {\n name,\n kind,\n description: definition.description || \"\",\n input_schema: schema(definition.input_schema || definition.inputSchema || definition.input),\n output_schema: schema(definition.output_schema || definition.outputSchema || definition.output),\n config_schema: schema(definition.config_schema || definition.configSchema || definition.config),\n ui_schema: definition.ui_schema || definition.uiSchema || definition.ui || {},\n side_effects: definition.side_effects || definition.sideEffects || [],\n execution_mode: definition.execution_mode || definition.executionMode || \"interactive\",\n handler_ref: definition.handler_ref || definition.handlerRef || actualHandler?.name || name,\n handler: actualHandler,\n };\n Object.defineProperty(value, \"__agents24ExplicitName\", { value: Boolean(explicitName), enumerable: false });\n return value;\n}\n\nexport function tool(definition = {}, handler) {\n return normalize(\"tool\", definition, handler);\n}\n\nexport function agentNode(definition = {}, handler) {\n return normalize(\"agent_node\", definition, handler);\n}\n\nexport function ragOperator(definition = {}, handler) {\n return normalize(\"rag_operator\", definition, handler);\n}\n\nexport function toolset(definition = {}) {\n return {\n __agents24Toolset: true,\n name: String(definition.name || \"\").trim(),\n description: String(definition.description || \"\").trim(),\n tools: Array.isArray(definition.tools) ? definition.tools : [],\n };\n}\n\nfunction entries(input) {\n if (Array.isArray(input)) return input.map((item) => [null, item]);\n return input && typeof input === \"object\" ? Object.entries(input) : [];\n}\n\nfunction normalizedExports(definition) {\n const exports = [];\n const namesByObject = new Map();\n for (const source of [definition.tools, definition.agentNodes, definition.ragOperators]) {\n for (const [mappedName, raw] of entries(source)) {\n if (!raw || typeof raw !== \"object\") throw new TypeError(\"Artifact exports must use tool, agentNode, or ragOperator\");\n const name = raw.__agents24ExplicitName ? raw.name.trim() : String(mappedName || raw.name || \"\").trim();\n if (!name) throw new TypeError(\"Artifact exports require a name\");\n exports.push({ ...raw, name, handler_ref: raw.handler_ref || name });\n namesByObject.set(raw, [...(namesByObject.get(raw) || []), name]);\n }\n }\n const names = exports.map((item) => item.name);\n const duplicate = names.find((name, index) => names.indexOf(name) !== index);\n if (duplicate) throw new TypeError(`Duplicate artifact export name '${duplicate}'`);\n return { exports, namesByObject };\n}\n\nfunction normalizedToolsets(input, exports, namesByObject) {\n if (input == null) return [];\n if (Array.isArray(input) || typeof input !== \"object\") {\n throw new TypeError(\"TypeScript artifact toolsets must be an object keyed by stable source key\");\n }\n const tools = new Set(exports.filter((item) => item.kind === \"tool\").map((item) => item.name));\n const seenNames = new Set();\n return Object.entries(input).map(([key, value]) => {\n if (!key.trim()) throw new TypeError(\"Artifact toolset keys cannot be empty\");\n if (!value?.__agents24Toolset) throw new TypeError(`Toolset '${key}' must use toolset()`);\n if (!value.name || !value.description || !value.tools.length) {\n throw new TypeError(`Toolset '${key}' requires a name, description, and tool`);\n }\n const folded = value.name.toLocaleLowerCase();\n if (seenNames.has(folded)) throw new TypeError(`Duplicate artifact toolset name '${value.name}'`);\n seenNames.add(folded);\n const members = value.tools.map((reference) => {\n if (typeof reference === \"string\") return reference.trim();\n const aliases = namesByObject.get(reference) || [];\n if (aliases.length !== 1) throw new TypeError(`Toolset '${key}' contains an unresolved or ambiguous tool reference`);\n return aliases[0];\n });\n if (new Set(members).size !== members.length) throw new TypeError(`Toolset '${key}' contains duplicate tools`);\n for (const member of members) {\n if (!tools.has(member)) throw new TypeError(`Toolset '${key}' references missing or non-tool export '${member}'`);\n }\n return { key, name: value.name, description: value.description, tools: members };\n });\n}\n\nexport function defineArtifact(definition = {}) {\n const normalized = normalizedExports(definition);\n return {\n __agents24Artifact: true,\n exports: normalized.exports,\n toolsets: normalizedToolsets(definition.toolsets, normalized.exports, normalized.namesByObject),\n __agents24ToolsetsDeclared: definition.toolsets != null,\n };\n}\n\nexport function describeArtifact(value) {\n const artifact = value && value.__agents24Artifact ? value : defineArtifact(value || {});\n return artifact.exports.map(({ handler: _handler, ...item }) => item);\n}\n\nexport function describeArtifactContract(value) {\n const artifact = value && value.__agents24Artifact ? value : defineArtifact(value || {});\n return { exports: describeArtifact(artifact), toolsets: artifact.toolsets.map((item) => ({ ...item })) };\n}\n","// The executable implementation is JavaScript so the platform can inject the\n// exact same source into Worker describe/build sandboxes without transpilation.\n// @ts-expect-error package-internal JavaScript runtime has typed bindings below\nimport * as runtime from \"./artifacts-runtime.mjs\";\n\nexport type JsonSchemaSource = Record<string, unknown> | {\n toJSONSchema?: () => Record<string, unknown>;\n toJsonSchema?: () => Record<string, unknown>;\n};\n\nexport type ArtifactHandler = (\n input: unknown,\n config: Record<string, unknown>,\n context: Record<string, unknown>,\n) => unknown | Promise<unknown>;\n\nexport type ArtifactExportDefinition = {\n name?: string;\n description?: string;\n input_schema?: JsonSchemaSource;\n inputSchema?: JsonSchemaSource;\n input?: JsonSchemaSource;\n output_schema?: JsonSchemaSource;\n outputSchema?: JsonSchemaSource;\n output?: JsonSchemaSource;\n config_schema?: JsonSchemaSource;\n configSchema?: JsonSchemaSource;\n config?: JsonSchemaSource;\n ui_schema?: Record<string, unknown>;\n uiSchema?: Record<string, unknown>;\n ui?: Record<string, unknown>;\n side_effects?: string[];\n sideEffects?: string[];\n execution_mode?: string;\n executionMode?: string;\n handler_ref?: string;\n handlerRef?: string;\n handler?: ArtifactHandler;\n execute?: ArtifactHandler;\n};\n\nexport type ArtifactExport = {\n name: string;\n kind: \"tool\" | \"agent_node\" | \"rag_operator\";\n description: string;\n input_schema: Record<string, unknown>;\n output_schema: Record<string, unknown>;\n config_schema: Record<string, unknown>;\n ui_schema: Record<string, unknown>;\n side_effects: string[];\n execution_mode: string;\n handler_ref: string;\n handler?: ArtifactHandler;\n readonly __agents24ExplicitName?: boolean;\n};\n\nexport type ArtifactToolset = {\n readonly __agents24Toolset: true;\n name: string;\n description: string;\n tools: Array<string | ArtifactExport>;\n};\n\nexport type ArtifactDefinition = {\n readonly __agents24Artifact: true;\n exports: ArtifactExport[];\n toolsets: Array<{ key: string; name: string; description: string; tools: string[] }>;\n readonly __agents24ToolsetsDeclared: boolean;\n};\n\nexport const tool = runtime.tool as (\n definition?: ArtifactExportDefinition,\n handler?: ArtifactHandler,\n) => ArtifactExport;\nexport const agentNode = runtime.agentNode as (\n definition?: ArtifactExportDefinition,\n handler?: ArtifactHandler,\n) => ArtifactExport;\nexport const ragOperator = runtime.ragOperator as (\n definition?: ArtifactExportDefinition,\n handler?: ArtifactHandler,\n) => ArtifactExport;\nexport const toolset = runtime.toolset as (\n definition?: { name?: string; description?: string; tools?: Array<string | ArtifactExport> },\n) => ArtifactToolset;\nexport const defineArtifact = runtime.defineArtifact as (\n definition?: Record<string, unknown>,\n) => ArtifactDefinition;\nexport const describeArtifact = runtime.describeArtifact as (\n value: ArtifactDefinition | Record<string, unknown>,\n) => Array<Omit<ArtifactExport, \"handler\">>;\nexport const describeArtifactContract = runtime.describeArtifactContract as (\n value: ArtifactDefinition | Record<string, unknown>,\n) => {\n exports: Array<Omit<ArtifactExport, \"handler\">>;\n toolsets: ArtifactDefinition[\"toolsets\"];\n};\n"]}
|