@sponsio/sdk 0.1.0-alpha.3 → 0.2.0-alpha.4
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/bin/sponsio.cjs +11 -0
- package/contracts/benchmark/agentdojo.yaml +551 -0
- package/contracts/benchmark/odcv_bench.yaml +393 -0
- package/contracts/benchmark/redcode_exec.yaml +488 -0
- package/contracts/benchmark/swebench.yaml +176 -0
- package/contracts/benchmark/tau2_bench.yaml +984 -0
- package/contracts/capability/credentials.yaml +8 -8
- package/contracts/capability/database.yaml +6 -6
- package/contracts/capability/filesystem-strict.yaml +4 -4
- package/contracts/capability/filesystem.yaml +9 -9
- package/contracts/capability/host-config-integrity.yaml +285 -0
- package/contracts/capability/self-modify.yaml +214 -9
- package/contracts/capability/shell.yaml +25 -32
- package/contracts/capability/subagent.yaml +5 -5
- package/contracts/core/llm_safety.yaml +21 -13
- package/contracts/incident/claude-code-secret-bypass.yaml +11 -12
- package/contracts/incident/cursor-railway-wipe.yaml +3 -3
- package/contracts/incident/mcp-composition.yaml +12 -12
- package/contracts/incident/openclaw.yaml +54 -45
- package/contracts/incident/subagent-escape.yaml +4 -4
- package/contracts/premium/.gitkeep +5 -6
- package/dist/cli/check.d.ts +2 -0
- package/dist/cli/check.d.ts.map +1 -0
- package/dist/cli/check.js +283 -0
- package/dist/cli/check.js.map +1 -0
- package/dist/cli/cli.d.ts +25 -0
- package/dist/cli/cli.d.ts.map +1 -0
- package/dist/cli/cli.js +459 -0
- package/dist/cli/cli.js.map +1 -0
- package/dist/cli/config.d.ts +88 -0
- package/dist/cli/config.d.ts.map +1 -0
- package/dist/cli/config.js +243 -0
- package/dist/cli/config.js.map +1 -0
- package/dist/cli/demo.d.ts +12 -0
- package/dist/cli/demo.d.ts.map +1 -0
- package/dist/cli/demo.js +350 -0
- package/dist/cli/demo.js.map +1 -0
- package/dist/cli/doctor.d.ts +11 -0
- package/dist/cli/doctor.d.ts.map +1 -0
- package/dist/cli/doctor.js +201 -0
- package/dist/cli/doctor.js.map +1 -0
- package/dist/cli/eval.d.ts +2 -0
- package/dist/cli/eval.d.ts.map +1 -0
- package/dist/cli/eval.js +361 -0
- package/dist/cli/eval.js.map +1 -0
- package/dist/cli/explain.d.ts +2 -0
- package/dist/cli/explain.d.ts.map +1 -0
- package/dist/cli/explain.js +266 -0
- package/dist/cli/explain.js.map +1 -0
- package/dist/cli/export-sessions.d.ts +2 -0
- package/dist/cli/export-sessions.d.ts.map +1 -0
- package/dist/cli/export-sessions.js +182 -0
- package/dist/cli/export-sessions.js.map +1 -0
- package/dist/cli/export.d.ts +2 -0
- package/dist/cli/export.d.ts.map +1 -0
- package/dist/cli/export.js +222 -0
- package/dist/cli/export.js.map +1 -0
- package/dist/cli/extractors/common.d.ts +27 -0
- package/dist/cli/extractors/common.d.ts.map +1 -0
- package/dist/cli/extractors/common.js +107 -0
- package/dist/cli/extractors/common.js.map +1 -0
- package/dist/cli/extractors/generic.d.ts +37 -0
- package/dist/cli/extractors/generic.d.ts.map +1 -0
- package/dist/cli/extractors/generic.js +185 -0
- package/dist/cli/extractors/generic.js.map +1 -0
- package/dist/cli/extractors/langchain.d.ts +18 -0
- package/dist/cli/extractors/langchain.d.ts.map +1 -0
- package/dist/cli/extractors/langchain.js +86 -0
- package/dist/cli/extractors/langchain.js.map +1 -0
- package/dist/cli/extractors/vercel.d.ts +17 -0
- package/dist/cli/extractors/vercel.d.ts.map +1 -0
- package/dist/cli/extractors/vercel.js +46 -0
- package/dist/cli/extractors/vercel.js.map +1 -0
- package/dist/cli/index.d.ts +38 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +146 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/init.d.ts +2 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +177 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/mode.d.ts +2 -0
- package/dist/cli/mode.d.ts.map +1 -0
- package/dist/cli/mode.js +71 -0
- package/dist/cli/mode.js.map +1 -0
- package/dist/cli/onboard.d.ts +88 -0
- package/dist/cli/onboard.d.ts.map +1 -0
- package/dist/cli/onboard.js +758 -0
- package/dist/cli/onboard.js.map +1 -0
- package/dist/cli/otlp.d.ts +27 -0
- package/dist/cli/otlp.d.ts.map +1 -0
- package/dist/cli/otlp.js +79 -0
- package/dist/cli/otlp.js.map +1 -0
- package/dist/cli/package.json +1 -0
- package/dist/cli/packs.d.ts +16 -0
- package/dist/cli/packs.d.ts.map +1 -0
- package/dist/cli/packs.js +184 -0
- package/dist/cli/packs.js.map +1 -0
- package/dist/cli/patterns.d.ts +16 -0
- package/dist/cli/patterns.d.ts.map +1 -0
- package/dist/cli/patterns.js +136 -0
- package/dist/cli/patterns.js.map +1 -0
- package/dist/cli/prompt.d.ts +2 -0
- package/dist/cli/prompt.d.ts.map +1 -0
- package/dist/cli/prompt.js +54 -0
- package/dist/cli/prompt.js.map +1 -0
- package/dist/cli/replay.d.ts +2 -0
- package/dist/cli/replay.d.ts.map +1 -0
- package/dist/cli/replay.js +196 -0
- package/dist/cli/replay.js.map +1 -0
- package/dist/cli/report.d.ts +57 -0
- package/dist/cli/report.d.ts.map +1 -0
- package/dist/cli/report.js +298 -0
- package/dist/cli/report.js.map +1 -0
- package/dist/cli/scan.d.ts +2 -0
- package/dist/cli/scan.d.ts.map +1 -0
- package/dist/cli/scan.js +172 -0
- package/dist/cli/scan.js.map +1 -0
- package/dist/cli/skill.d.ts +15 -0
- package/dist/cli/skill.d.ts.map +1 -0
- package/dist/cli/skill.js +131 -0
- package/dist/cli/skill.js.map +1 -0
- package/dist/cli/tokens.d.ts +31 -0
- package/dist/cli/tokens.d.ts.map +1 -0
- package/dist/cli/tokens.js +73 -0
- package/dist/cli/tokens.js.map +1 -0
- package/dist/cli/types.d.ts +46 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +3 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli/validate.d.ts +19 -0
- package/dist/cli/validate.d.ts.map +1 -0
- package/dist/cli/validate.js +205 -0
- package/dist/cli/validate.js.map +1 -0
- package/dist/cli/zod.d.ts +36 -0
- package/dist/cli/zod.d.ts.map +1 -0
- package/dist/cli/zod.js +226 -0
- package/dist/cli/zod.js.map +1 -0
- package/dist/contract.d.ts +13 -13
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +21 -21
- package/dist/contract.js.map +1 -1
- package/dist/core/config-loader.d.ts +1 -1
- package/dist/core/config-loader.d.ts.map +1 -1
- package/dist/core/config-loader.js +100 -26
- package/dist/core/config-loader.js.map +1 -1
- package/dist/core/evaluator.d.ts +9 -1
- package/dist/core/evaluator.d.ts.map +1 -1
- package/dist/core/evaluator.js +189 -13
- package/dist/core/evaluator.js.map +1 -1
- package/dist/core/formula.d.ts +76 -17
- package/dist/core/formula.d.ts.map +1 -1
- package/dist/core/formula.js +83 -1
- package/dist/core/formula.js.map +1 -1
- package/dist/core/grounding.d.ts +50 -3
- package/dist/core/grounding.d.ts.map +1 -1
- package/dist/core/grounding.js +317 -141
- package/dist/core/grounding.js.map +1 -1
- package/dist/core/nl-parser.d.ts +1 -1
- package/dist/core/nl-parser.d.ts.map +1 -1
- package/dist/core/nl-parser.js +76 -4
- package/dist/core/nl-parser.js.map +1 -1
- package/dist/core/pack-loader.d.ts.map +1 -1
- package/dist/core/pack-loader.js +14 -2
- package/dist/core/pack-loader.js.map +1 -1
- package/dist/core/parser.d.ts.map +1 -1
- package/dist/core/parser.js +30 -1
- package/dist/core/parser.js.map +1 -1
- package/dist/core/pattern-factory.d.ts +4 -4
- package/dist/core/pattern-factory.d.ts.map +1 -1
- package/dist/core/pattern-factory.js +53 -4
- package/dist/core/pattern-factory.js.map +1 -1
- package/dist/core/patterns.d.ts +127 -5
- package/dist/core/patterns.d.ts.map +1 -1
- package/dist/core/patterns.js +267 -3
- package/dist/core/patterns.js.map +1 -1
- package/dist/core/session-log.d.ts.map +1 -1
- package/dist/core/session-log.js +20 -1
- package/dist/core/session-log.js.map +1 -1
- package/dist/core/spans.d.ts +1 -1
- package/dist/core/spans.d.ts.map +1 -1
- package/dist/core/spans.js.map +1 -1
- package/dist/core/sto.d.ts +30 -66
- package/dist/core/sto.d.ts.map +1 -1
- package/dist/core/sto.js +39 -100
- package/dist/core/sto.js.map +1 -1
- package/dist/index.d.ts +83 -33
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +194 -142
- package/dist/index.js.map +1 -1
- package/dist/integrations/openai-agents.d.ts.map +1 -1
- package/dist/integrations/openai-agents.js +6 -4
- package/dist/integrations/openai-agents.js.map +1 -1
- package/dist/integrations/vercel-ai.d.ts.map +1 -1
- package/dist/integrations/vercel-ai.js +21 -3
- package/dist/integrations/vercel-ai.js.map +1 -1
- package/dist/render/tokens.d.ts.map +1 -1
- package/dist/render/tokens.js +1 -0
- package/dist/render/tokens.js.map +1 -1
- package/package.json +35 -7
- package/prompts/onboard.md +246 -0
- package/prompts/scan.md +123 -0
- package/skills/SKILL.md +432 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runExportCli = runExportCli;
|
|
4
|
+
/**
|
|
5
|
+
* ``sponsio export`` — convert Sponsio-native trace dumps to OTLP JSON.
|
|
6
|
+
*
|
|
7
|
+
* Mirrors the Python ``sponsio export`` command. Input is either a
|
|
8
|
+
* single ``.json`` file (a `Trace.export()` dump) or a directory of
|
|
9
|
+
* them; output is per-source-file OTLP JSON written into ``--to``,
|
|
10
|
+
* filenames prefixed with ``--label`` so they're ready for
|
|
11
|
+
* ``sponsio eval``.
|
|
12
|
+
*
|
|
13
|
+
* Event-type coverage is intentionally narrow: this command produces
|
|
14
|
+
* tool_call spans plus a generic fallback for unknown event types.
|
|
15
|
+
* LLM spans (``llm_request`` / ``llm_response``) are emitted as a
|
|
16
|
+
* single fallback span — full OTLP gen-ai parity stays in the Python
|
|
17
|
+
* exporter.
|
|
18
|
+
*/
|
|
19
|
+
const node_fs_1 = require("node:fs");
|
|
20
|
+
const node_path_1 = require("node:path");
|
|
21
|
+
const HELP = "sponsio export — Sponsio-native trace dumps -> OTLP JSON\n" +
|
|
22
|
+
"\n" +
|
|
23
|
+
"USAGE:\n" +
|
|
24
|
+
" sponsio export <source> --to <dir> [options]\n" +
|
|
25
|
+
"\n" +
|
|
26
|
+
"ARGUMENTS:\n" +
|
|
27
|
+
" <source> Single .json file or directory of Sponsio native trace dumps\n" +
|
|
28
|
+
"\n" +
|
|
29
|
+
"OPTIONS:\n" +
|
|
30
|
+
" --to <dir> Output directory for OTLP-JSON files (required)\n" +
|
|
31
|
+
" --label <l> Filename prefix: safe | unsafe | none (default: safe)\n" +
|
|
32
|
+
" --agent <id> Override service.name in the OTLP output\n" +
|
|
33
|
+
" --glob <pattern> Only convert files matching pattern (dir mode, default: *.json)\n" +
|
|
34
|
+
" -h, --help Show this help\n" +
|
|
35
|
+
"\n" +
|
|
36
|
+
"EXAMPLES:\n" +
|
|
37
|
+
" sponsio export run.json --to traces/\n" +
|
|
38
|
+
" sponsio export /var/log/sponsio/ --to traces/ --label unsafe\n";
|
|
39
|
+
const BASE_NS = 1700000000000000000n; // BigInt for exact ns math
|
|
40
|
+
const STEP_NS = 1000000000n;
|
|
41
|
+
function attr(key, value) {
|
|
42
|
+
if (typeof value === "boolean")
|
|
43
|
+
return { key, value: { boolValue: value } };
|
|
44
|
+
if (typeof value === "number") {
|
|
45
|
+
if (Number.isInteger(value))
|
|
46
|
+
return { key, value: { intValue: String(value) } };
|
|
47
|
+
return { key, value: { doubleValue: value } };
|
|
48
|
+
}
|
|
49
|
+
if (typeof value === "string")
|
|
50
|
+
return { key, value: { stringValue: value } };
|
|
51
|
+
return { key, value: { stringValue: String(value) } };
|
|
52
|
+
}
|
|
53
|
+
function spanTimeNs(ts) {
|
|
54
|
+
return BASE_NS + BigInt(ts) * STEP_NS;
|
|
55
|
+
}
|
|
56
|
+
function buildToolSpan(ev) {
|
|
57
|
+
const startNs = spanTimeNs(ev.ts ?? 0);
|
|
58
|
+
const endNs = startNs + 500000000n;
|
|
59
|
+
const attrs = [];
|
|
60
|
+
for (const [k, v] of Object.entries(ev.args ?? {})) {
|
|
61
|
+
attrs.push(attr(`args.${k}`, v));
|
|
62
|
+
}
|
|
63
|
+
if (ev.content !== undefined)
|
|
64
|
+
attrs.push(attr("tool.output", ev.content));
|
|
65
|
+
const span = {
|
|
66
|
+
traceId: "0".repeat(32),
|
|
67
|
+
spanId: (ev.ts ?? 0).toString(16).padStart(16, "0"),
|
|
68
|
+
name: ev.tool ?? "tool_call",
|
|
69
|
+
startTimeUnixNano: startNs.toString(),
|
|
70
|
+
endTimeUnixNano: endNs.toString(),
|
|
71
|
+
status: { code: 1 },
|
|
72
|
+
};
|
|
73
|
+
if (attrs.length)
|
|
74
|
+
span.attributes = attrs;
|
|
75
|
+
return span;
|
|
76
|
+
}
|
|
77
|
+
function buildFallbackSpan(ev) {
|
|
78
|
+
const startNs = spanTimeNs(ev.ts ?? 0);
|
|
79
|
+
const endNs = startNs + 500000000n;
|
|
80
|
+
const attrs = [];
|
|
81
|
+
if (ev.tool !== undefined)
|
|
82
|
+
attrs.push(attr("sponsio.tool", ev.tool));
|
|
83
|
+
if (ev.key !== undefined)
|
|
84
|
+
attrs.push(attr("sponsio.key", ev.key));
|
|
85
|
+
if (ev.contains !== undefined)
|
|
86
|
+
attrs.push(attr("sponsio.contains", ev.contains.join(",")));
|
|
87
|
+
if (ev.to !== undefined)
|
|
88
|
+
attrs.push(attr("sponsio.to", ev.to));
|
|
89
|
+
if (ev.content !== undefined)
|
|
90
|
+
attrs.push(attr("sponsio.content", ev.content));
|
|
91
|
+
const span = {
|
|
92
|
+
traceId: "0".repeat(32),
|
|
93
|
+
spanId: (ev.ts ?? 0).toString(16).padStart(16, "0"),
|
|
94
|
+
name: ev.event_type ?? "event",
|
|
95
|
+
startTimeUnixNano: startNs.toString(),
|
|
96
|
+
endTimeUnixNano: endNs.toString(),
|
|
97
|
+
status: { code: 1 },
|
|
98
|
+
};
|
|
99
|
+
if (attrs.length)
|
|
100
|
+
span.attributes = attrs;
|
|
101
|
+
return span;
|
|
102
|
+
}
|
|
103
|
+
function eventToSpan(ev) {
|
|
104
|
+
if (ev.event_type === "tool_call" || ev.tool)
|
|
105
|
+
return buildToolSpan(ev);
|
|
106
|
+
return buildFallbackSpan(ev);
|
|
107
|
+
}
|
|
108
|
+
function traceToOtlp(trace, agentId) {
|
|
109
|
+
const resolvedAgent = agentId ?? trace.metadata?.agent_id ?? trace.events[0]?.agent ?? "agent";
|
|
110
|
+
const spans = (trace.events ?? []).map(eventToSpan);
|
|
111
|
+
return {
|
|
112
|
+
resourceSpans: [
|
|
113
|
+
{
|
|
114
|
+
resource: { attributes: [attr("service.name", resolvedAgent)] },
|
|
115
|
+
scopeSpans: [{ scope: { name: "sponsio" }, spans }],
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function listSources(source, glob) {
|
|
121
|
+
const abs = (0, node_path_1.resolve)(source);
|
|
122
|
+
const st = (0, node_fs_1.statSync)(abs);
|
|
123
|
+
if (st.isFile())
|
|
124
|
+
return [abs];
|
|
125
|
+
// Trivial glob: only support ``*.ext`` form, since OTel files are conventional.
|
|
126
|
+
const m = /^\*(\.[a-z0-9]+)$/i.exec(glob);
|
|
127
|
+
const ext = m ? m[1].toLowerCase() : ".json";
|
|
128
|
+
return (0, node_fs_1.readdirSync)(abs)
|
|
129
|
+
.filter((f) => f.toLowerCase().endsWith(ext))
|
|
130
|
+
.map((f) => (0, node_path_1.join)(abs, f))
|
|
131
|
+
.sort();
|
|
132
|
+
}
|
|
133
|
+
async function runExportCli(argv) {
|
|
134
|
+
let source;
|
|
135
|
+
let target;
|
|
136
|
+
let label = "safe";
|
|
137
|
+
let agentId;
|
|
138
|
+
let glob = "*.json";
|
|
139
|
+
for (let i = 0; i < argv.length; i++) {
|
|
140
|
+
const a = argv[i];
|
|
141
|
+
if (a === "-h" || a === "--help") {
|
|
142
|
+
process.stdout.write(HELP);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (a === "--to") {
|
|
146
|
+
target = argv[++i];
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (a === "--label") {
|
|
150
|
+
const v = argv[++i];
|
|
151
|
+
if (v !== "safe" && v !== "unsafe" && v !== "none") {
|
|
152
|
+
process.stderr.write(`--label must be safe|unsafe|none (got ${v})\n`);
|
|
153
|
+
process.exit(2);
|
|
154
|
+
}
|
|
155
|
+
label = v;
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (a === "--agent") {
|
|
159
|
+
agentId = argv[++i];
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (a === "--glob") {
|
|
163
|
+
glob = argv[++i];
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
if (a.startsWith("-")) {
|
|
167
|
+
process.stderr.write(`unknown flag: ${a}\n${HELP}`);
|
|
168
|
+
process.exit(2);
|
|
169
|
+
}
|
|
170
|
+
if (source) {
|
|
171
|
+
process.stderr.write(`extra positional argument: ${a}\n${HELP}`);
|
|
172
|
+
process.exit(2);
|
|
173
|
+
}
|
|
174
|
+
source = a;
|
|
175
|
+
}
|
|
176
|
+
if (!source) {
|
|
177
|
+
process.stderr.write(`Error: source required\n\n${HELP}`);
|
|
178
|
+
process.exit(2);
|
|
179
|
+
}
|
|
180
|
+
if (!target) {
|
|
181
|
+
process.stderr.write(`Error: --to required\n\n${HELP}`);
|
|
182
|
+
process.exit(2);
|
|
183
|
+
}
|
|
184
|
+
if (!(0, node_fs_1.existsSync)((0, node_path_1.resolve)(source))) {
|
|
185
|
+
process.stderr.write(`Error: ${source} does not exist\n`);
|
|
186
|
+
process.exit(1);
|
|
187
|
+
}
|
|
188
|
+
(0, node_fs_1.mkdirSync)((0, node_path_1.resolve)(target), { recursive: true });
|
|
189
|
+
const sources = listSources(source, glob);
|
|
190
|
+
if (sources.length === 0) {
|
|
191
|
+
process.stderr.write(`No files matched ${glob} under ${source}\n`);
|
|
192
|
+
process.exit(0);
|
|
193
|
+
}
|
|
194
|
+
let converted = 0;
|
|
195
|
+
const skipped = [];
|
|
196
|
+
for (const src of sources) {
|
|
197
|
+
let raw;
|
|
198
|
+
try {
|
|
199
|
+
raw = JSON.parse((0, node_fs_1.readFileSync)(src, "utf-8"));
|
|
200
|
+
}
|
|
201
|
+
catch (e) {
|
|
202
|
+
skipped.push({ src, reason: `parse: ${e.message}` });
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
if (!Array.isArray(raw.events)) {
|
|
206
|
+
skipped.push({ src, reason: "missing events: array" });
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
const otlp = traceToOtlp(raw, agentId);
|
|
210
|
+
const stem = (0, node_path_1.basename)(src).replace(/\.json$/i, "");
|
|
211
|
+
const outName = label === "none" ? `${stem}.json` : `${label}_${stem}.json`;
|
|
212
|
+
(0, node_fs_1.writeFileSync)((0, node_path_1.join)((0, node_path_1.resolve)(target), outName), JSON.stringify(otlp, null, 2), "utf-8");
|
|
213
|
+
converted++;
|
|
214
|
+
}
|
|
215
|
+
process.stdout.write(`✓ exported ${converted} of ${sources.length} traces to ${target}\n`);
|
|
216
|
+
if (skipped.length) {
|
|
217
|
+
process.stderr.write(`Skipped ${skipped.length}:\n`);
|
|
218
|
+
for (const s of skipped.slice(0, 10))
|
|
219
|
+
process.stderr.write(` ${s.src}: ${s.reason}\n`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=export.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"export.js","sourceRoot":"","sources":["../../src/cli/export.ts"],"names":[],"mappings":";;AA+JA,oCA0FC;AAzPD;;;;;;;;;;;;;;GAcG;AACH,qCAAoG;AACpG,yCAAoD;AAEpD,MAAM,IAAI,GACR,4DAA4D;I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uBAAa,EAAC,IAAA,gBAAI,EAAC,IAAA,mBAAO,EAAC,MAAM,CAAC,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QACtF,SAAS,EAAE,CAAC;IACd,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,SAAS,OAAO,OAAO,CAAC,MAAM,cAAc,MAAM,IAAI,CAAC,CAAC;IAC3F,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC;QACrD,KAAK,MAAM,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;YAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC;IAC1F,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helpers for the framework-specific extractors.
|
|
3
|
+
*/
|
|
4
|
+
import { CallExpression, Node, ObjectLiteralExpression, PropertyAssignment } from "ts-morph";
|
|
5
|
+
import type { OpenAITool } from "../types";
|
|
6
|
+
/**
|
|
7
|
+
* Given a call/new-expression's first argument (which should be an
|
|
8
|
+
* object literal like ``{ name, description, parameters }``), pull
|
|
9
|
+
* out the fields we need and build an OpenAITool, or return
|
|
10
|
+
* ``undefined`` when the shape doesn't look like a tool definition.
|
|
11
|
+
*/
|
|
12
|
+
export declare function objectArgToTool(obj: ObjectLiteralExpression, inferredName: string | undefined, opts: {
|
|
13
|
+
nameKey?: string;
|
|
14
|
+
descriptionKey?: string;
|
|
15
|
+
/** Fields to try for the parameter schema, in priority order. */
|
|
16
|
+
schemaKeys: string[];
|
|
17
|
+
}): OpenAITool | undefined;
|
|
18
|
+
export declare function findProperty(obj: ObjectLiteralExpression, key: string): PropertyAssignment | undefined;
|
|
19
|
+
export declare function getStringInit(prop: PropertyAssignment): string | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Walk upwards from a call/new expression to find the variable name
|
|
22
|
+
* it's being assigned to — e.g. for
|
|
23
|
+
* const lookupCustomer = tool({ ... })
|
|
24
|
+
* return ``"lookupCustomer"``.
|
|
25
|
+
*/
|
|
26
|
+
export declare function inferNameFromAssignment(call: CallExpression | Node): string | undefined;
|
|
27
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/cli/extractors/common.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,cAAc,EACd,IAAI,EACJ,uBAAuB,EACvB,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAc,UAAU,EAAE,MAAM,UAAU,CAAC;AAEvD;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,uBAAuB,EAC5B,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,IAAI,EAAE;IACJ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,iEAAiE;IACjE,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB,GACA,UAAU,GAAG,SAAS,CAiDxB;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,uBAAuB,EAC5B,GAAG,EAAE,MAAM,GACV,kBAAkB,GAAG,SAAS,CAOhC;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,kBAAkB,GAAG,MAAM,GAAG,SAAS,CAO1E;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,cAAc,GAAG,IAAI,GAC1B,MAAM,GAAG,SAAS,CAcpB"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shared helpers for the framework-specific extractors.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.objectArgToTool = objectArgToTool;
|
|
7
|
+
exports.findProperty = findProperty;
|
|
8
|
+
exports.getStringInit = getStringInit;
|
|
9
|
+
exports.inferNameFromAssignment = inferNameFromAssignment;
|
|
10
|
+
const ts_morph_1 = require("ts-morph");
|
|
11
|
+
const zod_1 = require("../zod");
|
|
12
|
+
/**
|
|
13
|
+
* Given a call/new-expression's first argument (which should be an
|
|
14
|
+
* object literal like ``{ name, description, parameters }``), pull
|
|
15
|
+
* out the fields we need and build an OpenAITool, or return
|
|
16
|
+
* ``undefined`` when the shape doesn't look like a tool definition.
|
|
17
|
+
*/
|
|
18
|
+
function objectArgToTool(obj, inferredName, opts) {
|
|
19
|
+
const nameKey = opts.nameKey ?? "name";
|
|
20
|
+
const descKey = opts.descriptionKey ?? "description";
|
|
21
|
+
const nameNode = findProperty(obj, nameKey);
|
|
22
|
+
const descNode = findProperty(obj, descKey);
|
|
23
|
+
let name = nameNode
|
|
24
|
+
? getStringInit(nameNode)
|
|
25
|
+
: inferredName;
|
|
26
|
+
if (!name)
|
|
27
|
+
return undefined;
|
|
28
|
+
const description = descNode ? getStringInit(descNode) ?? "" : "";
|
|
29
|
+
let schema = { type: "object", properties: {} };
|
|
30
|
+
for (const key of opts.schemaKeys) {
|
|
31
|
+
const prop = findProperty(obj, key);
|
|
32
|
+
if (!prop)
|
|
33
|
+
continue;
|
|
34
|
+
const init = prop.getInitializer();
|
|
35
|
+
if (!init)
|
|
36
|
+
continue;
|
|
37
|
+
// ``parameters: z.object({...})`` → full schema. We call the
|
|
38
|
+
// object-literal converter directly so we pick up the
|
|
39
|
+
// ``required`` list, which ``zodExprToJsonSchema`` drops because
|
|
40
|
+
// its return type is a *property* (no ``required`` field).
|
|
41
|
+
if (ts_morph_1.Node.isCallExpression(init)) {
|
|
42
|
+
const firstArg = init.getArguments()[0];
|
|
43
|
+
if (firstArg && ts_morph_1.Node.isObjectLiteralExpression(firstArg)) {
|
|
44
|
+
schema = (0, zod_1.objectLiteralToJsonSchema)(firstArg);
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
// Fall back to the property-level converter; we still get
|
|
48
|
+
// ``properties`` when the schema happens to be an object.
|
|
49
|
+
const derived = (0, zod_1.zodExprToJsonSchema)(init);
|
|
50
|
+
if (derived.type === "object" && derived.properties) {
|
|
51
|
+
schema = { type: "object", properties: derived.properties };
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// ``parameters: { a: z.string() }`` — plain object literal
|
|
56
|
+
if (ts_morph_1.Node.isObjectLiteralExpression(init)) {
|
|
57
|
+
schema = (0, zod_1.objectLiteralToJsonSchema)(init);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
type: "function",
|
|
63
|
+
function: { name, description, parameters: schema },
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function findProperty(obj, key) {
|
|
67
|
+
for (const p of obj.getProperties()) {
|
|
68
|
+
if (!ts_morph_1.Node.isPropertyAssignment(p))
|
|
69
|
+
continue;
|
|
70
|
+
const n = p.getName().replace(/^['"`]|['"`]$/g, "");
|
|
71
|
+
if (n === key)
|
|
72
|
+
return p;
|
|
73
|
+
}
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
function getStringInit(prop) {
|
|
77
|
+
const init = prop.getInitializer();
|
|
78
|
+
if (!init)
|
|
79
|
+
return undefined;
|
|
80
|
+
if (ts_morph_1.Node.isStringLiteral(init) || ts_morph_1.Node.isNoSubstitutionTemplateLiteral(init)) {
|
|
81
|
+
return init.getLiteralText();
|
|
82
|
+
}
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Walk upwards from a call/new expression to find the variable name
|
|
87
|
+
* it's being assigned to — e.g. for
|
|
88
|
+
* const lookupCustomer = tool({ ... })
|
|
89
|
+
* return ``"lookupCustomer"``.
|
|
90
|
+
*/
|
|
91
|
+
function inferNameFromAssignment(call) {
|
|
92
|
+
let cur = call.getParent();
|
|
93
|
+
while (cur) {
|
|
94
|
+
if (ts_morph_1.Node.isVariableDeclaration(cur)) {
|
|
95
|
+
const id = cur.getNameNode();
|
|
96
|
+
if (ts_morph_1.Node.isIdentifier(id))
|
|
97
|
+
return id.getText();
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
if (ts_morph_1.Node.isPropertyAssignment(cur)) {
|
|
101
|
+
return cur.getName().replace(/^['"`]|['"`]$/g, "");
|
|
102
|
+
}
|
|
103
|
+
cur = cur.getParent();
|
|
104
|
+
}
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/cli/extractors/common.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAiBH,0CA0DC;AAED,oCAUC;AAED,sCAOC;AAQD,0DAgBC;AAtHD,uCAKkB;AAClB,gCAAwE;AAGxE;;;;;GAKG;AACH,SAAgB,eAAe,CAC7B,GAA4B,EAC5B,YAAgC,EAChC,IAKC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,MAAM,CAAC;IACvC,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,IAAI,aAAa,CAAC;IAErD,MAAM,QAAQ,GAAG,YAAY,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC5C,MAAM,QAAQ,GAAG,YAAY,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAE5C,IAAI,IAAI,GAAuB,QAAQ;QACrC,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC;QACzB,CAAC,CAAC,YAAY,CAAC;IACjB,IAAI,CAAC,IAAI;QAAE,OAAO,S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C,OAAO,EAAE,CAAC;YAC/C,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,IAAI,eAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,EAAE,CAAC;YACnC,OAAO,GAAG,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;QACrD,CAAC;QACD,GAAG,GAAG,GAAG,CAAC,SAAS,EAAE,CAAC;IACxB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic / framework-agnostic tool extractor.
|
|
3
|
+
*
|
|
4
|
+
* Catches the long-tail of homegrown agent toolkits and lesser-known
|
|
5
|
+
* libraries that follow the same conventions as Vercel AI / LangChain
|
|
6
|
+
* but use a slightly different name. This deliberately runs *after*
|
|
7
|
+
* the framework-specific extractors so that the more-specific ones
|
|
8
|
+
* win (their provenance is more useful: ``"vercel_ai"`` vs
|
|
9
|
+
* ``"generic"``).
|
|
10
|
+
*
|
|
11
|
+
* Two patterns are recognised:
|
|
12
|
+
*
|
|
13
|
+
* 1. **Decorator** — ``@tool`` / ``@createTool`` / ``@defineTool`` /
|
|
14
|
+
* ``@registerTool`` applied to a function declaration or class
|
|
15
|
+
* method. Function name → tool name, leading JSDoc → description,
|
|
16
|
+
* first object-literal argument to the decorator (if any) carries
|
|
17
|
+
* the schema / overrides.
|
|
18
|
+
*
|
|
19
|
+
* 2. **Call expression** — ``createTool({...})``, ``defineTool({...})``,
|
|
20
|
+
* ``makeTool({...})``, ``registerTool({...})``, ``tool({...})``
|
|
21
|
+
* — anything that *looks* like a tool factory. The ``tool``
|
|
22
|
+
* identifier overlaps with Vercel AI; the dedupe layer in
|
|
23
|
+
* ``index.ts`` (keyed on name + file + line) silently discards
|
|
24
|
+
* the duplicate.
|
|
25
|
+
*
|
|
26
|
+
* The fallback is conservative: an object literal must carry at
|
|
27
|
+
* least two of ``{name, description, schema/parameters/inputSchema}``
|
|
28
|
+
* before we treat it as a tool, otherwise an unrelated function call
|
|
29
|
+
* like ``tool({ id: 5 })`` would emit garbage entries.
|
|
30
|
+
*/
|
|
31
|
+
import { SourceFile } from "ts-morph";
|
|
32
|
+
import type { OpenAITool, ToolProvenance } from "../types";
|
|
33
|
+
export declare function extractGenericTools(sourceFile: SourceFile): {
|
|
34
|
+
tool: OpenAITool;
|
|
35
|
+
provenance: ToolProvenance;
|
|
36
|
+
}[];
|
|
37
|
+
//# sourceMappingURL=generic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../../src/cli/extractors/generic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAML,UAAU,EACX,MAAM,UAAU,CAAC;AAMlB,OAAO,KAAK,EAAc,UAAU,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AA0JvE,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,UAAU,GACrB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,UAAU,EAAE,cAAc,CAAA;CAAE,EAAE,CAKpD"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Generic / framework-agnostic tool extractor.
|
|
4
|
+
*
|
|
5
|
+
* Catches the long-tail of homegrown agent toolkits and lesser-known
|
|
6
|
+
* libraries that follow the same conventions as Vercel AI / LangChain
|
|
7
|
+
* but use a slightly different name. This deliberately runs *after*
|
|
8
|
+
* the framework-specific extractors so that the more-specific ones
|
|
9
|
+
* win (their provenance is more useful: ``"vercel_ai"`` vs
|
|
10
|
+
* ``"generic"``).
|
|
11
|
+
*
|
|
12
|
+
* Two patterns are recognised:
|
|
13
|
+
*
|
|
14
|
+
* 1. **Decorator** — ``@tool`` / ``@createTool`` / ``@defineTool`` /
|
|
15
|
+
* ``@registerTool`` applied to a function declaration or class
|
|
16
|
+
* method. Function name → tool name, leading JSDoc → description,
|
|
17
|
+
* first object-literal argument to the decorator (if any) carries
|
|
18
|
+
* the schema / overrides.
|
|
19
|
+
*
|
|
20
|
+
* 2. **Call expression** — ``createTool({...})``, ``defineTool({...})``,
|
|
21
|
+
* ``makeTool({...})``, ``registerTool({...})``, ``tool({...})``
|
|
22
|
+
* — anything that *looks* like a tool factory. The ``tool``
|
|
23
|
+
* identifier overlaps with Vercel AI; the dedupe layer in
|
|
24
|
+
* ``index.ts`` (keyed on name + file + line) silently discards
|
|
25
|
+
* the duplicate.
|
|
26
|
+
*
|
|
27
|
+
* The fallback is conservative: an object literal must carry at
|
|
28
|
+
* least two of ``{name, description, schema/parameters/inputSchema}``
|
|
29
|
+
* before we treat it as a tool, otherwise an unrelated function call
|
|
30
|
+
* like ``tool({ id: 5 })`` would emit garbage entries.
|
|
31
|
+
*/
|
|
32
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
+
exports.extractGenericTools = extractGenericTools;
|
|
34
|
+
const ts_morph_1 = require("ts-morph");
|
|
35
|
+
const common_1 = require("./common");
|
|
36
|
+
/** Identifier names that look like a tool factory. */
|
|
37
|
+
const FACTORY_NAMES = new Set([
|
|
38
|
+
"tool",
|
|
39
|
+
"createTool",
|
|
40
|
+
"defineTool",
|
|
41
|
+
"makeTool",
|
|
42
|
+
"registerTool",
|
|
43
|
+
"buildTool",
|
|
44
|
+
"Tool",
|
|
45
|
+
"FunctionTool",
|
|
46
|
+
]);
|
|
47
|
+
/** Decorator names treated as a tool registration marker. */
|
|
48
|
+
const DECORATOR_NAMES = FACTORY_NAMES;
|
|
49
|
+
/** Required-fields heuristic: the object literal must carry at least
|
|
50
|
+
* two of these keys. Without this guard a benign call like
|
|
51
|
+
* ``tool({ id: 5 })`` would produce a bogus tool entry. */
|
|
52
|
+
const TOOL_SHAPE_KEYS = [
|
|
53
|
+
"name",
|
|
54
|
+
"description",
|
|
55
|
+
"parameters",
|
|
56
|
+
"schema",
|
|
57
|
+
"inputSchema",
|
|
58
|
+
];
|
|
59
|
+
function looksLikeToolObject(obj) {
|
|
60
|
+
let hits = 0;
|
|
61
|
+
for (const key of TOOL_SHAPE_KEYS) {
|
|
62
|
+
if ((0, common_1.findProperty)(obj, key))
|
|
63
|
+
hits += 1;
|
|
64
|
+
if (hits >= 2)
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
function jsdocDescription(node) {
|
|
70
|
+
// ``getJsDocs`` exists on most declaration nodes — guarded so we
|
|
71
|
+
// can call it from the union type without a ts-morph cast.
|
|
72
|
+
const getter = node.getJsDocs;
|
|
73
|
+
if (typeof getter !== "function")
|
|
74
|
+
return "";
|
|
75
|
+
const docs = getter.call(node);
|
|
76
|
+
if (!Array.isArray(docs) || docs.length === 0)
|
|
77
|
+
return "";
|
|
78
|
+
const text = docs[0].getDescription?.() ?? "";
|
|
79
|
+
return text.trim();
|
|
80
|
+
}
|
|
81
|
+
/** Extract via ``createTool({...})`` / ``tool({...})`` / ``new FunctionTool({...})`` / etc. */
|
|
82
|
+
function extractCallExpressions(sourceFile) {
|
|
83
|
+
const found = [];
|
|
84
|
+
sourceFile.forEachDescendant((node) => {
|
|
85
|
+
if (!ts_morph_1.Node.isCallExpression(node) && !ts_morph_1.Node.isNewExpression(node))
|
|
86
|
+
return;
|
|
87
|
+
const callee = node.getExpression();
|
|
88
|
+
let calleeName;
|
|
89
|
+
if (ts_morph_1.Node.isIdentifier(callee))
|
|
90
|
+
calleeName = callee.getText();
|
|
91
|
+
// Member access like ``Sponsio.tool({...})`` — use the property
|
|
92
|
+
// segment so dotted exports still get picked up.
|
|
93
|
+
else if (ts_morph_1.Node.isPropertyAccessExpression(callee))
|
|
94
|
+
calleeName = callee.getName();
|
|
95
|
+
if (!calleeName || !FACTORY_NAMES.has(calleeName))
|
|
96
|
+
return;
|
|
97
|
+
const arg = node.getArguments()[0];
|
|
98
|
+
if (!arg || !ts_morph_1.Node.isObjectLiteralExpression(arg))
|
|
99
|
+
return;
|
|
100
|
+
if (!looksLikeToolObject(arg))
|
|
101
|
+
return;
|
|
102
|
+
const name = (0, common_1.inferNameFromAssignment)(node);
|
|
103
|
+
const tool = (0, common_1.objectArgToTool)(arg, name, {
|
|
104
|
+
schemaKeys: ["parameters", "schema", "inputSchema"],
|
|
105
|
+
});
|
|
106
|
+
if (!tool)
|
|
107
|
+
return;
|
|
108
|
+
found.push({
|
|
109
|
+
tool,
|
|
110
|
+
provenance: {
|
|
111
|
+
filepath: sourceFile.getFilePath(),
|
|
112
|
+
line: node.getStartLineNumber(),
|
|
113
|
+
extractor: "generic",
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
return found;
|
|
118
|
+
}
|
|
119
|
+
/** Extract via ``@tool`` / ``@createTool`` decorators. */
|
|
120
|
+
function extractDecorators(sourceFile) {
|
|
121
|
+
const found = [];
|
|
122
|
+
sourceFile.forEachDescendant((node) => {
|
|
123
|
+
if (!ts_morph_1.Node.isDecorator(node))
|
|
124
|
+
return;
|
|
125
|
+
const dec = node;
|
|
126
|
+
// Resolve the decorator identifier: ``@tool`` or ``@tool({...})``
|
|
127
|
+
let decName;
|
|
128
|
+
const exprText = dec.getExpression();
|
|
129
|
+
if (ts_morph_1.Node.isIdentifier(exprText))
|
|
130
|
+
decName = exprText.getText();
|
|
131
|
+
else if (ts_morph_1.Node.isCallExpression(exprText)) {
|
|
132
|
+
const inner = exprText.getExpression();
|
|
133
|
+
if (ts_morph_1.Node.isIdentifier(inner))
|
|
134
|
+
decName = inner.getText();
|
|
135
|
+
}
|
|
136
|
+
if (!decName || !DECORATOR_NAMES.has(decName))
|
|
137
|
+
return;
|
|
138
|
+
const target = dec.getParent();
|
|
139
|
+
if (!ts_morph_1.Node.isFunctionDeclaration(target) &&
|
|
140
|
+
!ts_morph_1.Node.isMethodDeclaration(target)) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const fn = target;
|
|
144
|
+
const name = fn.getName();
|
|
145
|
+
if (!name)
|
|
146
|
+
return;
|
|
147
|
+
// Description: first try the decorator's config object (if it's
|
|
148
|
+
// a call), then fall back to a JSDoc comment on the function.
|
|
149
|
+
let description = "";
|
|
150
|
+
let schema = { type: "object", properties: {} };
|
|
151
|
+
if (ts_morph_1.Node.isCallExpression(exprText)) {
|
|
152
|
+
const cfg = exprText.getArguments()[0];
|
|
153
|
+
if (cfg && ts_morph_1.Node.isObjectLiteralExpression(cfg)) {
|
|
154
|
+
const built = (0, common_1.objectArgToTool)(cfg, name, {
|
|
155
|
+
schemaKeys: ["parameters", "schema", "inputSchema"],
|
|
156
|
+
});
|
|
157
|
+
if (built) {
|
|
158
|
+
description = built.function.description;
|
|
159
|
+
schema = built.function.parameters;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (!description)
|
|
164
|
+
description = jsdocDescription(fn);
|
|
165
|
+
found.push({
|
|
166
|
+
tool: {
|
|
167
|
+
type: "function",
|
|
168
|
+
function: { name, description, parameters: schema },
|
|
169
|
+
},
|
|
170
|
+
provenance: {
|
|
171
|
+
filepath: sourceFile.getFilePath(),
|
|
172
|
+
line: fn.getStartLineNumber(),
|
|
173
|
+
extractor: "generic_decorator",
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
return found;
|
|
178
|
+
}
|
|
179
|
+
function extractGenericTools(sourceFile) {
|
|
180
|
+
return [
|
|
181
|
+
...extractCallExpressions(sourceFile),
|
|
182
|
+
...extractDecorators(sourceFile),
|
|
183
|
+
];
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=generic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generic.js","sourceRoot":"","sources":["../../../src/cli/extractors/generic.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;;AAyKH,kDAOC;AA9KD,uCAOkB;AAClB,q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Chain.js tool extractor.
|
|
3
|
+
*
|
|
4
|
+
* Matches:
|
|
5
|
+
*
|
|
6
|
+
* new DynamicStructuredTool({ name, description, schema, func })
|
|
7
|
+
* new DynamicTool({ name, description, func })
|
|
8
|
+
* tool(fn, { name, description, schema }) — LangGraph.js v0.2+
|
|
9
|
+
*
|
|
10
|
+
* The ``schema`` field is a Zod object we convert via ``zod.ts``.
|
|
11
|
+
*/
|
|
12
|
+
import { SourceFile } from "ts-morph";
|
|
13
|
+
import type { OpenAITool, ToolProvenance } from "../types";
|
|
14
|
+
export declare function extractLangChainTools(sourceFile: SourceFile): {
|
|
15
|
+
tool: OpenAITool;
|
|
16
|
+
provenance: ToolProvenance;
|
|
17
|
+
}[];
|
|
18
|
+
//# sourceMappingURL=langchain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"langchain.d.ts","sourceRoot":"","sources":["../../../src/cli/extractors/langchain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAQ,UAAU,EAAE,MAAM,UAAU,CAAC;AAE5C,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAQ3D,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,UAAU,GACrB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,UAAU,EAAE,cAAc,CAAA;CAAE,EAAE,CAgEpD"}
|