@botbotgo/kit 1.0.106
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/README.md +65 -0
- package/config/build/build.sh +182 -0
- package/config/build/tsconfig.dts.json +34 -0
- package/config/build/tsup.config.ts +19 -0
- package/config/build/vitest.config.ts +29 -0
- package/config/tool.yaml +11 -0
- package/dist/agent-context.d.ts +3 -0
- package/dist/agent-context.d.ts.map +1 -0
- package/dist/api/adapters/LangChainToolsHub.d.ts +35 -0
- package/dist/api/adapters/LangChainToolsHub.d.ts.map +1 -0
- package/dist/api/createAgentTools.d.ts +52 -0
- package/dist/api/createAgentTools.d.ts.map +1 -0
- package/dist/api/expose/extension-init/index.d.ts +3 -0
- package/dist/api/expose/extension-init/index.d.ts.map +1 -0
- package/dist/api/expose/extension-init/initExtension.d.ts +21 -0
- package/dist/api/expose/extension-init/initExtension.d.ts.map +1 -0
- package/dist/api/expose/index.d.ts +16 -0
- package/dist/api/expose/index.d.ts.map +1 -0
- package/dist/api/expose/mcp-build/build.d.ts +21 -0
- package/dist/api/expose/mcp-build/build.d.ts.map +1 -0
- package/dist/api/expose/mcp-build/generator.d.ts +15 -0
- package/dist/api/expose/mcp-build/generator.d.ts.map +1 -0
- package/dist/api/expose/mcp-build/index.d.ts +8 -0
- package/dist/api/expose/mcp-build/index.d.ts.map +1 -0
- package/dist/api/expose/mcp-build/init.d.ts +17 -0
- package/dist/api/expose/mcp-build/init.d.ts.map +1 -0
- package/dist/api/expose/mcp-build/run.d.ts +17 -0
- package/dist/api/expose/mcp-build/run.d.ts.map +1 -0
- package/dist/api/expose/mcp-build/types.d.ts +25 -0
- package/dist/api/expose/mcp-build/types.d.ts.map +1 -0
- package/dist/api/expose/mcpServer.d.ts +74 -0
- package/dist/api/expose/mcpServer.d.ts.map +1 -0
- package/dist/api/expose/openapi.d.ts +23 -0
- package/dist/api/expose/openapi.d.ts.map +1 -0
- package/dist/api/expose/openapiHttp.d.ts +51 -0
- package/dist/api/expose/openapiHttp.d.ts.map +1 -0
- package/dist/api/extension/contextRunner.d.ts +10 -0
- package/dist/api/extension/contextRunner.d.ts.map +1 -0
- package/dist/api/extension/createExtension.d.ts +38 -0
- package/dist/api/extension/createExtension.d.ts.map +1 -0
- package/dist/api/extension/dynamicImportAdapter.d.ts +25 -0
- package/dist/api/extension/dynamicImportAdapter.d.ts.map +1 -0
- package/dist/api/extension/generateExtensionManifest.d.ts +29 -0
- package/dist/api/extension/generateExtensionManifest.d.ts.map +1 -0
- package/dist/api/extension/index.d.ts +23 -0
- package/dist/api/extension/index.d.ts.map +1 -0
- package/dist/api/extension/loadToolYaml.d.ts +7 -0
- package/dist/api/extension/loadToolYaml.d.ts.map +1 -0
- package/dist/api/extension/overrideWithConfig.d.ts +2 -0
- package/dist/api/extension/overrideWithConfig.d.ts.map +1 -0
- package/dist/api/extension/registerExtension.d.ts +32 -0
- package/dist/api/extension/registerExtension.d.ts.map +1 -0
- package/dist/api/extension/registerFromManifest.d.ts +43 -0
- package/dist/api/extension/registerFromManifest.d.ts.map +1 -0
- package/dist/api/extension/resolvePackageRoot.d.ts +2 -0
- package/dist/api/extension/resolvePackageRoot.d.ts.map +1 -0
- package/dist/api/extension/support/groupPrefix.d.ts +21 -0
- package/dist/api/extension/support/groupPrefix.d.ts.map +1 -0
- package/dist/api/extension/support/types.d.ts +15 -0
- package/dist/api/extension/support/types.d.ts.map +1 -0
- package/dist/api/register-tools.d.ts +17 -0
- package/dist/api/register-tools.d.ts.map +1 -0
- package/dist/api/resolveAgentSkillRoots.d.ts +7 -0
- package/dist/api/resolveAgentSkillRoots.d.ts.map +1 -0
- package/dist/api/runtimeFromConfig.d.ts +20 -0
- package/dist/api/runtimeFromConfig.d.ts.map +1 -0
- package/dist/api/runtimeFromConfig.helpers.d.ts +12 -0
- package/dist/api/runtimeFromConfig.helpers.d.ts.map +1 -0
- package/dist/api/runtimeFromConfig.types.d.ts +37 -0
- package/dist/api/runtimeFromConfig.types.d.ts.map +1 -0
- package/dist/build.cjs +30 -0
- package/dist/build.cjs.map +1 -0
- package/dist/build.d.ts +13 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +5 -0
- package/dist/build.js.map +1 -0
- package/dist/canonicalCoreSchemas-PHGTNPN5.js +3 -0
- package/dist/canonicalCoreSchemas-PHGTNPN5.js.map +1 -0
- package/dist/canonicalCoreSchemas-TY7NCWCC.cjs +16 -0
- package/dist/canonicalCoreSchemas-TY7NCWCC.cjs.map +1 -0
- package/dist/chunk-4OOTCNR7.js +324 -0
- package/dist/chunk-4OOTCNR7.js.map +1 -0
- package/dist/chunk-4VKCWJHF.cjs +3043 -0
- package/dist/chunk-4VKCWJHF.cjs.map +1 -0
- package/dist/chunk-AGLGFQUW.cjs +259 -0
- package/dist/chunk-AGLGFQUW.cjs.map +1 -0
- package/dist/chunk-AZUXVVGV.cjs +1073 -0
- package/dist/chunk-AZUXVVGV.cjs.map +1 -0
- package/dist/chunk-BDUSB6GT.js +520 -0
- package/dist/chunk-BDUSB6GT.js.map +1 -0
- package/dist/chunk-BNIE2IKZ.cjs +100 -0
- package/dist/chunk-BNIE2IKZ.cjs.map +1 -0
- package/dist/chunk-BTHDNP3C.cjs +350 -0
- package/dist/chunk-BTHDNP3C.cjs.map +1 -0
- package/dist/chunk-GGFAGLDC.js +1049 -0
- package/dist/chunk-GGFAGLDC.js.map +1 -0
- package/dist/chunk-ITX6A2BT.js +92 -0
- package/dist/chunk-ITX6A2BT.js.map +1 -0
- package/dist/chunk-IVL4TBFB.js +248 -0
- package/dist/chunk-IVL4TBFB.js.map +1 -0
- package/dist/chunk-JH4ZF3FN.js +3013 -0
- package/dist/chunk-JH4ZF3FN.js.map +1 -0
- package/dist/chunk-JW4EMVTE.cjs +553 -0
- package/dist/chunk-JW4EMVTE.cjs.map +1 -0
- package/dist/chunk-NTWOVFEY.js +16 -0
- package/dist/chunk-NTWOVFEY.js.map +1 -0
- package/dist/chunk-UUNG3GL3.cjs +19 -0
- package/dist/chunk-UUNG3GL3.cjs.map +1 -0
- package/dist/core/registry/ToolRegistry.d.ts +68 -0
- package/dist/core/registry/ToolRegistry.d.ts.map +1 -0
- package/dist/core/runtime/Budget.d.ts +63 -0
- package/dist/core/runtime/Budget.d.ts.map +1 -0
- package/dist/core/runtime/Evidence.d.ts +19 -0
- package/dist/core/runtime/Evidence.d.ts.map +1 -0
- package/dist/core/runtime/PTCRuntime.d.ts +124 -0
- package/dist/core/runtime/PTCRuntime.d.ts.map +1 -0
- package/dist/core/runtime/PTCRuntimeObservability.d.ts +26 -0
- package/dist/core/runtime/PTCRuntimeObservability.d.ts.map +1 -0
- package/dist/core/runtime/PTCRuntimePipeline.d.ts +69 -0
- package/dist/core/runtime/PTCRuntimePipeline.d.ts.map +1 -0
- package/dist/core/runtime/PolicyEngine.d.ts +67 -0
- package/dist/core/runtime/PolicyEngine.d.ts.map +1 -0
- package/dist/core/runtime/Retry.d.ts +33 -0
- package/dist/core/runtime/Retry.d.ts.map +1 -0
- package/dist/core/runtime/SchemaValidator.d.ts +42 -0
- package/dist/core/runtime/SchemaValidator.d.ts.map +1 -0
- package/dist/core/runtime/toolObservation.d.ts +7 -0
- package/dist/core/runtime/toolObservation.d.ts.map +1 -0
- package/dist/core/types/Events.d.ts +99 -0
- package/dist/core/types/Events.d.ts.map +1 -0
- package/dist/core/types/ToolIntent.d.ts +40 -0
- package/dist/core/types/ToolIntent.d.ts.map +1 -0
- package/dist/core/types/ToolResult.d.ts +44 -0
- package/dist/core/types/ToolResult.d.ts.map +1 -0
- package/dist/core/types/ToolSpec.d.ts +116 -0
- package/dist/core/types/ToolSpec.d.ts.map +1 -0
- package/dist/core/types/ToolTypeHandler.d.ts +88 -0
- package/dist/core/types/ToolTypeHandler.d.ts.map +1 -0
- package/dist/core/types/index.d.ts +7 -0
- package/dist/core/types/index.d.ts.map +1 -0
- package/dist/index.cjs +399 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +394 -0
- package/dist/index.js.map +1 -0
- package/dist/observability/EventLog.d.ts +60 -0
- package/dist/observability/EventLog.d.ts.map +1 -0
- package/dist/observability/Logger.d.ts +33 -0
- package/dist/observability/Logger.d.ts.map +1 -0
- package/dist/observability/Metrics.d.ts +70 -0
- package/dist/observability/Metrics.d.ts.map +1 -0
- package/dist/observability/Tracing.d.ts +69 -0
- package/dist/observability/Tracing.d.ts.map +1 -0
- package/dist/sdk.cjs +493 -0
- package/dist/sdk.cjs.map +1 -0
- package/dist/sdk.d.ts +17 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/sdk.js +443 -0
- package/dist/sdk.js.map +1 -0
- package/dist/security/sandbox.d.ts +10 -0
- package/dist/security/sandbox.d.ts.map +1 -0
- package/dist/security/ssrf.d.ts +24 -0
- package/dist/security/ssrf.d.ts.map +1 -0
- package/dist/templates/mcp-server.js +48 -0
- package/dist/templates/n8n-invoker.js +11 -0
- package/dist/templates/skill-invoker.js +11 -0
- package/dist/templates/tool-index.js +9 -0
- package/dist/tools/discoveryFactory.d.ts +117 -0
- package/dist/tools/discoveryFactory.d.ts.map +1 -0
- package/dist/tools/function/index.d.ts +10 -0
- package/dist/tools/function/index.d.ts.map +1 -0
- package/dist/tools/function/scanner.d.ts +29 -0
- package/dist/tools/function/scanner.d.ts.map +1 -0
- package/dist/tools/function/schemaFromTs.d.ts +16 -0
- package/dist/tools/function/schemaFromTs.d.ts.map +1 -0
- package/dist/tools/function/types.d.ts +20 -0
- package/dist/tools/function/types.d.ts.map +1 -0
- package/dist/tools/index.d.ts +13 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/langchain/LangChainLoader.d.ts +7 -0
- package/dist/tools/langchain/LangChainLoader.d.ts.map +1 -0
- package/dist/tools/langchain/directoryApply.d.ts +5 -0
- package/dist/tools/langchain/directoryApply.d.ts.map +1 -0
- package/dist/tools/langchain/directoryLoad.d.ts +13 -0
- package/dist/tools/langchain/directoryLoad.d.ts.map +1 -0
- package/dist/tools/langchain/index.d.ts +3 -0
- package/dist/tools/langchain/index.d.ts.map +1 -0
- package/dist/tools/langchain/scanner.d.ts +8 -0
- package/dist/tools/langchain/scanner.d.ts.map +1 -0
- package/dist/tools/langchain/types.d.ts +5 -0
- package/dist/tools/langchain/types.d.ts.map +1 -0
- package/dist/tools/mcp/MCPClientAdapter.d.ts +34 -0
- package/dist/tools/mcp/MCPClientAdapter.d.ts.map +1 -0
- package/dist/tools/mcp/MCPLoader.d.ts +8 -0
- package/dist/tools/mcp/MCPLoader.d.ts.map +1 -0
- package/dist/tools/mcp/MCPProcessManager.d.ts +29 -0
- package/dist/tools/mcp/MCPProcessManager.d.ts.map +1 -0
- package/dist/tools/mcp/connectMCP.d.ts +47 -0
- package/dist/tools/mcp/connectMCP.d.ts.map +1 -0
- package/dist/tools/mcp/directoryApply.d.ts +10 -0
- package/dist/tools/mcp/directoryApply.d.ts.map +1 -0
- package/dist/tools/mcp/index.d.ts +16 -0
- package/dist/tools/mcp/index.d.ts.map +1 -0
- package/dist/tools/mcp/mcpSpecToToolSpec.d.ts +8 -0
- package/dist/tools/mcp/mcpSpecToToolSpec.d.ts.map +1 -0
- package/dist/tools/mcp/registerMCPTools.d.ts +24 -0
- package/dist/tools/mcp/registerMCPTools.d.ts.map +1 -0
- package/dist/tools/mcp/scanner.d.ts +8 -0
- package/dist/tools/mcp/scanner.d.ts.map +1 -0
- package/dist/tools/mcp/support/types.d.ts +3 -0
- package/dist/tools/mcp/support/types.d.ts.map +1 -0
- package/dist/tools/n8n/N8nLoader.d.ts +25 -0
- package/dist/tools/n8n/N8nLoader.d.ts.map +1 -0
- package/dist/tools/n8n/directoryApply.d.ts +10 -0
- package/dist/tools/n8n/directoryApply.d.ts.map +1 -0
- package/dist/tools/n8n/index.d.ts +6 -0
- package/dist/tools/n8n/index.d.ts.map +1 -0
- package/dist/tools/n8n/scanN8n.d.ts +20 -0
- package/dist/tools/n8n/scanN8n.d.ts.map +1 -0
- package/dist/tools/n8n/types.d.ts +18 -0
- package/dist/tools/n8n/types.d.ts.map +1 -0
- package/dist/tools/scanPackage.d.ts +42 -0
- package/dist/tools/scanPackage.d.ts.map +1 -0
- package/dist/tools/skill/SkillLoader.d.ts +20 -0
- package/dist/tools/skill/SkillLoader.d.ts.map +1 -0
- package/dist/tools/skill/SkillManifest.d.ts +79 -0
- package/dist/tools/skill/SkillManifest.d.ts.map +1 -0
- package/dist/tools/skill/SkillMdParser.d.ts +31 -0
- package/dist/tools/skill/SkillMdParser.d.ts.map +1 -0
- package/dist/tools/skill/directoryApply.d.ts +10 -0
- package/dist/tools/skill/directoryApply.d.ts.map +1 -0
- package/dist/tools/skill/index.d.ts +8 -0
- package/dist/tools/skill/index.d.ts.map +1 -0
- package/dist/tools/skill/scanSkill.d.ts +20 -0
- package/dist/tools/skill/scanSkill.d.ts.map +1 -0
- package/dist/tools/skill/types.d.ts +19 -0
- package/dist/tools/skill/types.d.ts.map +1 -0
- package/dist/tools/util/canonicalCoreSchemas.d.ts +15 -0
- package/dist/tools/util/canonicalCoreSchemas.d.ts.map +1 -0
- package/dist/tools/util/index.d.ts +13 -0
- package/dist/tools/util/index.d.ts.map +1 -0
- package/dist/tools/util/resolveEntry.d.ts +6 -0
- package/dist/tools/util/resolveEntry.d.ts.map +1 -0
- package/dist/tools/util/scanUtil.d.ts +9 -0
- package/dist/tools/util/scanUtil.d.ts.map +1 -0
- package/dist/tools/util/toolConfig.d.ts +38 -0
- package/dist/tools/util/toolConfig.d.ts.map +1 -0
- package/dist/tools/util/toolDescriptor.d.ts +117 -0
- package/dist/tools/util/toolDescriptor.d.ts.map +1 -0
- package/dist/utils/cli/help.d.ts +2 -0
- package/dist/utils/cli/help.d.ts.map +1 -0
- package/dist/utils/cli/index.cjs +700 -0
- package/dist/utils/cli/index.cjs.map +1 -0
- package/dist/utils/cli/index.d.ts +9 -0
- package/dist/utils/cli/index.d.ts.map +1 -0
- package/dist/utils/cli/index.js +677 -0
- package/dist/utils/cli/index.js.map +1 -0
- package/dist/utils/cli/toolRuntime.d.ts +19 -0
- package/dist/utils/cli/toolRuntime.d.ts.map +1 -0
- package/dist/utils/log.d.ts +2 -0
- package/dist/utils/log.d.ts.map +1 -0
- package/dist/utils/npmCache.d.ts +11 -0
- package/dist/utils/npmCache.d.ts.map +1 -0
- package/dist/utils/npmVersion.d.ts +10 -0
- package/dist/utils/npmVersion.d.ts.map +1 -0
- package/dist/utils/overrideWithConfig.d.ts +2 -0
- package/dist/utils/overrideWithConfig.d.ts.map +1 -0
- package/package.json +125 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple counter metric.
|
|
3
|
+
*/
|
|
4
|
+
export interface CounterValue {
|
|
5
|
+
name: string;
|
|
6
|
+
labels: Record<string, string>;
|
|
7
|
+
value: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Histogram bucket.
|
|
11
|
+
*/
|
|
12
|
+
export interface HistogramValue {
|
|
13
|
+
name: string;
|
|
14
|
+
labels: Record<string, string>;
|
|
15
|
+
count: number;
|
|
16
|
+
sum: number;
|
|
17
|
+
buckets: Map<number, number>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Lightweight metrics collector for tool invocations.
|
|
21
|
+
* Provides counters and histograms with label support.
|
|
22
|
+
*/
|
|
23
|
+
export declare class Metrics {
|
|
24
|
+
private readonly counters;
|
|
25
|
+
private readonly histograms;
|
|
26
|
+
private readonly defaultBuckets;
|
|
27
|
+
/**
|
|
28
|
+
* Increment a counter.
|
|
29
|
+
*/
|
|
30
|
+
increment(name: string, labels?: Record<string, string>, value?: number): void;
|
|
31
|
+
/**
|
|
32
|
+
* Record a value in a histogram.
|
|
33
|
+
*/
|
|
34
|
+
observe(name: string, labels: Record<string, string>, value: number): void;
|
|
35
|
+
/**
|
|
36
|
+
* Get a counter value.
|
|
37
|
+
*/
|
|
38
|
+
getCounter(name: string, labels?: Record<string, string>): number;
|
|
39
|
+
/**
|
|
40
|
+
* Get histogram stats.
|
|
41
|
+
*/
|
|
42
|
+
getHistogram(name: string, labels: Record<string, string>): HistogramValue | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Get all counter values.
|
|
45
|
+
*/
|
|
46
|
+
getAllCounters(): CounterValue[];
|
|
47
|
+
/**
|
|
48
|
+
* Get all histogram values.
|
|
49
|
+
*/
|
|
50
|
+
getAllHistograms(): HistogramValue[];
|
|
51
|
+
/**
|
|
52
|
+
* Record standard tool invocation metrics.
|
|
53
|
+
*/
|
|
54
|
+
recordInvocation(toolName: string, ok: boolean, durationMs: number): void;
|
|
55
|
+
/**
|
|
56
|
+
* Record a retry event.
|
|
57
|
+
*/
|
|
58
|
+
recordRetry(toolName: string): void;
|
|
59
|
+
/**
|
|
60
|
+
* Record a policy denial.
|
|
61
|
+
*/
|
|
62
|
+
recordPolicyDenied(toolName: string, reason: string): void;
|
|
63
|
+
/**
|
|
64
|
+
* Reset all metrics (for testing).
|
|
65
|
+
*/
|
|
66
|
+
reset(): void;
|
|
67
|
+
private makeKey;
|
|
68
|
+
private parseKey;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=Metrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Metrics.d.ts","sourceRoot":"","sources":["../../src/observability/Metrics.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAED;;;GAGG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA6B;IACtD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAGvB;IAEJ,OAAO,CAAC,QAAQ,CAAC,cAAc,CAE7B;IAEF;;OAEG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EAAE,KAAK,SAAI,GAAG,IAAI;IAK7E;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAY1E;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAAG,MAAM;IAIrE;;OAEG;IACH,YAAY,CACV,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC7B,cAAc,GAAG,SAAS;IAa7B;;OAEG;IACH,cAAc,IAAI,YAAY,EAAE;IAShC;;OAEG;IACH,gBAAgB,IAAI,cAAc,EAAE;IAapC;;OAEG;IACH,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;IAQzE;;OAEG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAInC;;OAEG;IACH,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAI1D;;OAEG;IACH,KAAK,IAAI,IAAI;IAKb,OAAO,CAAC,OAAO;IAQf,OAAO,CAAC,QAAQ;CAejB"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A trace span representing a unit of work.
|
|
3
|
+
*/
|
|
4
|
+
export interface Span {
|
|
5
|
+
spanId: string;
|
|
6
|
+
traceId: string;
|
|
7
|
+
parentSpanId?: string;
|
|
8
|
+
name: string;
|
|
9
|
+
startTime: number;
|
|
10
|
+
endTime?: number;
|
|
11
|
+
durationMs?: number;
|
|
12
|
+
status: "ok" | "error" | "in_progress";
|
|
13
|
+
attributes: Record<string, string | number | boolean>;
|
|
14
|
+
events: SpanEvent[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* An event within a span.
|
|
18
|
+
*/
|
|
19
|
+
export interface SpanEvent {
|
|
20
|
+
name: string;
|
|
21
|
+
timestamp: number;
|
|
22
|
+
attributes?: Record<string, string | number | boolean>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Lightweight tracing system for tool invocation spans.
|
|
26
|
+
* Compatible with OpenTelemetry trace/span ID format.
|
|
27
|
+
*/
|
|
28
|
+
export declare class Tracing {
|
|
29
|
+
private readonly spans;
|
|
30
|
+
private readonly traceSpans;
|
|
31
|
+
/**
|
|
32
|
+
* Start a new span.
|
|
33
|
+
*/
|
|
34
|
+
startSpan(options: {
|
|
35
|
+
name: string;
|
|
36
|
+
traceId?: string;
|
|
37
|
+
parentSpanId?: string;
|
|
38
|
+
attributes?: Record<string, string | number | boolean>;
|
|
39
|
+
}): Span;
|
|
40
|
+
/**
|
|
41
|
+
* End a span and calculate duration.
|
|
42
|
+
*/
|
|
43
|
+
endSpan(spanId: string, status?: "ok" | "error"): Span | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Add an event to a span.
|
|
46
|
+
*/
|
|
47
|
+
addEvent(spanId: string, name: string, attributes?: Record<string, string | number | boolean>): void;
|
|
48
|
+
/**
|
|
49
|
+
* Set attributes on a span.
|
|
50
|
+
*/
|
|
51
|
+
setAttributes(spanId: string, attributes: Record<string, string | number | boolean>): void;
|
|
52
|
+
/**
|
|
53
|
+
* Get a span by ID.
|
|
54
|
+
*/
|
|
55
|
+
getSpan(spanId: string): Span | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Get all spans for a trace.
|
|
58
|
+
*/
|
|
59
|
+
getTrace(traceId: string): Span[];
|
|
60
|
+
/**
|
|
61
|
+
* Create a child span from a parent.
|
|
62
|
+
*/
|
|
63
|
+
createChildSpan(parentSpanId: string, name: string, attributes?: Record<string, string | number | boolean>): Span | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Clear all traces (for testing).
|
|
66
|
+
*/
|
|
67
|
+
clear(): void;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=Tracing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tracing.d.ts","sourceRoot":"","sources":["../../src/observability/Tracing.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,IAAI;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,IAAI,GAAG,OAAO,GAAG,aAAa,CAAC;IACvC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;IACtD,MAAM,EAAE,SAAS,EAAE,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;CACxD;AAED;;;GAGG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA2B;IACjD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA+B;IAE1D;;OAEG;IACH,SAAS,CAAC,OAAO,EAAE;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;KACxD,GAAG,IAAI;IAqBR;;OAEG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,IAAI,GAAG,OAAc,GAAG,IAAI,GAAG,SAAS;IAUxE;;OAEG;IACH,QAAQ,CACN,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,GACrD,IAAI;IAMP;;OAEG;IACH,aAAa,CACX,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,GACpD,IAAI;IAMP;;OAEG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAIzC;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,EAAE;IAOjC;;OAEG;IACH,eAAe,CACb,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,GACrD,IAAI,GAAG,SAAS;IAWnB;;OAEG;IACH,KAAK,IAAI,IAAI;CAId"}
|
package/dist/sdk.cjs
ADDED
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkBNIE2IKZ_cjs = require('./chunk-BNIE2IKZ.cjs');
|
|
4
|
+
var chunkAGLGFQUW_cjs = require('./chunk-AGLGFQUW.cjs');
|
|
5
|
+
var chunkJW4EMVTE_cjs = require('./chunk-JW4EMVTE.cjs');
|
|
6
|
+
var promises = require('dns/promises');
|
|
7
|
+
var async_hooks = require('async_hooks');
|
|
8
|
+
var path4 = require('path');
|
|
9
|
+
var url = require('url');
|
|
10
|
+
var fs = require('fs');
|
|
11
|
+
|
|
12
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
|
|
14
|
+
var path4__default = /*#__PURE__*/_interopDefault(path4);
|
|
15
|
+
|
|
16
|
+
async function validateUrl(url, options) {
|
|
17
|
+
let parsed;
|
|
18
|
+
try {
|
|
19
|
+
parsed = new URL(url);
|
|
20
|
+
} catch {
|
|
21
|
+
throw chunkAGLGFQUW_cjs.createTaggedError(
|
|
22
|
+
"HTTP_DISALLOWED_HOST",
|
|
23
|
+
`Invalid URL: ${url}`,
|
|
24
|
+
{ url }
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
28
|
+
throw chunkAGLGFQUW_cjs.createTaggedError(
|
|
29
|
+
"HTTP_DISALLOWED_HOST",
|
|
30
|
+
`Protocol not allowed: ${parsed.protocol}. Only http: and https: are supported.`,
|
|
31
|
+
{ url, protocol: parsed.protocol }
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
const hostname = parsed.hostname;
|
|
35
|
+
if (!isHostAllowed(hostname, options.allowedHosts)) {
|
|
36
|
+
throw chunkAGLGFQUW_cjs.createTaggedError(
|
|
37
|
+
"HTTP_DISALLOWED_HOST",
|
|
38
|
+
`Host "${hostname}" is not in the allowed hosts list`,
|
|
39
|
+
{ url, hostname, allowedHosts: options.allowedHosts }
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
if (isHostBlocked(hostname, options.blockedHosts)) {
|
|
43
|
+
throw chunkAGLGFQUW_cjs.createTaggedError(
|
|
44
|
+
"HTTP_DISALLOWED_HOST",
|
|
45
|
+
`Host "${hostname}" is in the blocked hosts list`,
|
|
46
|
+
{ url, hostname, blockedHosts: options.blockedHosts }
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const { address } = await promises.lookup(hostname);
|
|
51
|
+
if (isIpInBlockedCidrs(address, options.blockedCidrs)) {
|
|
52
|
+
throw chunkAGLGFQUW_cjs.createTaggedError(
|
|
53
|
+
"HTTP_DISALLOWED_HOST",
|
|
54
|
+
`Host "${hostname}" resolves to blocked IP: ${address}`,
|
|
55
|
+
{ url, hostname, resolvedIp: address }
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
} catch (err) {
|
|
59
|
+
if (err instanceof Error && err.kind === "HTTP_DISALLOWED_HOST") {
|
|
60
|
+
throw err;
|
|
61
|
+
}
|
|
62
|
+
throw chunkAGLGFQUW_cjs.createTaggedError(
|
|
63
|
+
"HTTP_DISALLOWED_HOST",
|
|
64
|
+
`DNS resolution failed for host "${hostname}": ${err instanceof Error ? err.message : String(err)}`,
|
|
65
|
+
{ url, hostname }
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
return parsed;
|
|
69
|
+
}
|
|
70
|
+
function isHostAllowed(hostname, allowedHosts) {
|
|
71
|
+
for (const pattern of allowedHosts) {
|
|
72
|
+
if (pattern === "*") {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
if (pattern.startsWith("*.")) {
|
|
76
|
+
const suffix = pattern.slice(1);
|
|
77
|
+
if (hostname.endsWith(suffix) || hostname === pattern.slice(2)) {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
} else if (hostname === pattern) {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
function isHostBlocked(hostname, blockedHosts) {
|
|
87
|
+
for (const pattern of blockedHosts) {
|
|
88
|
+
if (pattern === "*") {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
if (pattern.startsWith("*.")) {
|
|
92
|
+
const suffix = pattern.slice(1);
|
|
93
|
+
if (hostname.endsWith(suffix) || hostname === pattern.slice(2)) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
} else if (hostname === pattern) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
function isIpInBlockedCidrs(ip, cidrs) {
|
|
103
|
+
const normalizedIp = normalizeIp(ip);
|
|
104
|
+
if (!normalizedIp) return false;
|
|
105
|
+
for (const cidr of cidrs) {
|
|
106
|
+
if (cidr.includes(":")) {
|
|
107
|
+
if (!ip.includes(":")) continue;
|
|
108
|
+
if (isIpv6InCidr(ip, cidr)) return true;
|
|
109
|
+
} else {
|
|
110
|
+
if (isIpv4InCidr(normalizedIp, cidr)) return true;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
function normalizeIp(ip) {
|
|
116
|
+
if (ip.startsWith("::ffff:")) {
|
|
117
|
+
return ip.slice(7);
|
|
118
|
+
}
|
|
119
|
+
if (/^\d+\.\d+\.\d+\.\d+$/.test(ip)) {
|
|
120
|
+
return ip;
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
function isIpv4InCidr(ip, cidr) {
|
|
125
|
+
const [cidrIp, prefixStr] = cidr.split("/");
|
|
126
|
+
if (!cidrIp || !prefixStr) return false;
|
|
127
|
+
const prefix = parseInt(prefixStr, 10);
|
|
128
|
+
if (isNaN(prefix) || prefix < 0 || prefix > 32) return false;
|
|
129
|
+
const ipNum = ipv4ToNum(ip);
|
|
130
|
+
const cidrNum = ipv4ToNum(cidrIp);
|
|
131
|
+
if (ipNum === null || cidrNum === null) return false;
|
|
132
|
+
const mask = prefix === 0 ? 0 : -1 << 32 - prefix >>> 0;
|
|
133
|
+
return (ipNum & mask) === (cidrNum & mask);
|
|
134
|
+
}
|
|
135
|
+
function ipv4ToNum(ip) {
|
|
136
|
+
const parts = ip.split(".");
|
|
137
|
+
if (parts.length !== 4) return null;
|
|
138
|
+
let num = 0;
|
|
139
|
+
for (const part of parts) {
|
|
140
|
+
const n = parseInt(part, 10);
|
|
141
|
+
if (isNaN(n) || n < 0 || n > 255) return null;
|
|
142
|
+
num = num << 8 | n;
|
|
143
|
+
}
|
|
144
|
+
return num >>> 0;
|
|
145
|
+
}
|
|
146
|
+
function isIpv6InCidr(ip, cidr) {
|
|
147
|
+
const [cidrIp, prefixStr] = cidr.split("/");
|
|
148
|
+
if (!cidrIp || !prefixStr) return false;
|
|
149
|
+
const prefix = parseInt(prefixStr, 10);
|
|
150
|
+
if (isNaN(prefix)) return false;
|
|
151
|
+
const ipBytes = expandIpv6(ip);
|
|
152
|
+
const cidrBytes = expandIpv6(cidrIp);
|
|
153
|
+
if (!ipBytes || !cidrBytes) return false;
|
|
154
|
+
const fullBytes = Math.floor(prefix / 8);
|
|
155
|
+
for (let i = 0; i < fullBytes && i < 16; i++) {
|
|
156
|
+
if (ipBytes[i] !== cidrBytes[i]) return false;
|
|
157
|
+
}
|
|
158
|
+
const remainingBits = prefix % 8;
|
|
159
|
+
if (remainingBits > 0 && fullBytes < 16) {
|
|
160
|
+
const mask = -1 << 8 - remainingBits & 255;
|
|
161
|
+
if ((ipBytes[fullBytes] & mask) !== (cidrBytes[fullBytes] & mask)) return false;
|
|
162
|
+
}
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
function expandIpv6(ip) {
|
|
166
|
+
const zoneIdx = ip.indexOf("%");
|
|
167
|
+
if (zoneIdx !== -1) ip = ip.slice(0, zoneIdx);
|
|
168
|
+
const parts = ip.split("::");
|
|
169
|
+
if (parts.length > 2) return null;
|
|
170
|
+
const bytes = new Array(16).fill(0);
|
|
171
|
+
const expandGroup = (group) => {
|
|
172
|
+
if (!group) return [];
|
|
173
|
+
return group.split(":").flatMap((hex) => {
|
|
174
|
+
const val = parseInt(hex || "0", 16);
|
|
175
|
+
return [val >> 8 & 255, val & 255];
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
if (parts.length === 1) {
|
|
179
|
+
const expanded = expandGroup(parts[0]);
|
|
180
|
+
if (expanded.length !== 16) return null;
|
|
181
|
+
return expanded;
|
|
182
|
+
}
|
|
183
|
+
const left = expandGroup(parts[0]);
|
|
184
|
+
const right = expandGroup(parts[1]);
|
|
185
|
+
if (left.length + right.length > 16) return null;
|
|
186
|
+
for (let i = 0; i < left.length; i++) bytes[i] = left[i];
|
|
187
|
+
for (let i = 0; i < right.length; i++) bytes[16 - right.length + i] = right[i];
|
|
188
|
+
return bytes;
|
|
189
|
+
}
|
|
190
|
+
function createContextRunner() {
|
|
191
|
+
const storage = new async_hooks.AsyncLocalStorage();
|
|
192
|
+
return {
|
|
193
|
+
runWith(ctx, fn) {
|
|
194
|
+
return storage.run(ctx, fn);
|
|
195
|
+
},
|
|
196
|
+
getContext() {
|
|
197
|
+
const ctx = storage.getStore();
|
|
198
|
+
if (ctx === void 0) {
|
|
199
|
+
throw new Error("Extension context not set; invoke only through the extension adapter.");
|
|
200
|
+
}
|
|
201
|
+
return ctx;
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
function unwrapArgsForHandler(spec, args) {
|
|
206
|
+
if (args == null || typeof args !== "object" || Array.isArray(args)) return args;
|
|
207
|
+
const s = spec.inputSchema;
|
|
208
|
+
if (s?.type !== "object" || !s.properties || typeof s.properties !== "object") return args;
|
|
209
|
+
const props = s.properties;
|
|
210
|
+
const argsProp = props.args;
|
|
211
|
+
if (argsProp != null && typeof argsProp === "object" && argsProp.type === "object" && argsProp.properties != null) {
|
|
212
|
+
const obj = args;
|
|
213
|
+
if (Object.keys(obj).length === 1 && "args" in obj && typeof obj.args === "object" && obj.args !== null) {
|
|
214
|
+
return obj.args;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return args;
|
|
218
|
+
}
|
|
219
|
+
function createDynamicImportAdapter(options) {
|
|
220
|
+
const { kind, packageRoot, getExtensionContext, contextRunner } = options;
|
|
221
|
+
return {
|
|
222
|
+
kind,
|
|
223
|
+
async invoke(spec, args, execCtx) {
|
|
224
|
+
const meta = spec._meta;
|
|
225
|
+
const sourcePath = meta?.sourcePath;
|
|
226
|
+
const exportName = meta?.exportName;
|
|
227
|
+
if (!sourcePath || !exportName) {
|
|
228
|
+
throw new Error(`Extension tool ${spec.name} missing _meta.sourcePath or _meta.exportName`);
|
|
229
|
+
}
|
|
230
|
+
const defaultArgs = meta?.defaultArgs ?? {};
|
|
231
|
+
const mergedArgs = Object.keys(defaultArgs).length === 0 ? args : { ...defaultArgs, ...args };
|
|
232
|
+
const handlerArgs = unwrapArgsForHandler(spec, mergedArgs);
|
|
233
|
+
const resolvedPackageRoot = meta?.packageRoot ?? packageRoot;
|
|
234
|
+
const modulePath = path4__default.default.join(resolvedPackageRoot, `${sourcePath}.js`);
|
|
235
|
+
const mod = await import(url.pathToFileURL(modulePath).href);
|
|
236
|
+
const handler = mod[exportName];
|
|
237
|
+
if (typeof handler !== "function") {
|
|
238
|
+
throw new Error(
|
|
239
|
+
`Extension tool ${spec.name}: export "${exportName}" from ${sourcePath} is not a function`
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
const ctx = getExtensionContext(execCtx, spec, mergedArgs);
|
|
243
|
+
const output = await contextRunner.runWith(ctx, () => handler(handlerArgs));
|
|
244
|
+
return {
|
|
245
|
+
result: { result: output.result, evidence: output.evidence },
|
|
246
|
+
raw: { evidence: output.evidence }
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
function resolveExtensionPackageRoot(metaUrlOrPath) {
|
|
252
|
+
const dir = metaUrlOrPath.startsWith("file:") ? path4__default.default.dirname(url.fileURLToPath(metaUrlOrPath)) : path4__default.default.resolve(metaUrlOrPath);
|
|
253
|
+
const dist = path4__default.default.join(dir, "dist");
|
|
254
|
+
return fs.existsSync(dist) ? dist : dir;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// src/api/extension/registerExtension.ts
|
|
258
|
+
function deriveConfigPrefixCandidates(prefixWithVersion) {
|
|
259
|
+
if (!prefixWithVersion) return [];
|
|
260
|
+
const candidates = /* @__PURE__ */ new Set([prefixWithVersion]);
|
|
261
|
+
if (prefixWithVersion.startsWith("npm.")) {
|
|
262
|
+
const versionless = prefixWithVersion.replace(/(?:\.\d+)+$/, "");
|
|
263
|
+
if (versionless && versionless !== prefixWithVersion) {
|
|
264
|
+
candidates.add(versionless);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return [...candidates];
|
|
268
|
+
}
|
|
269
|
+
function registerExtension(registry, options) {
|
|
270
|
+
const { packagePath, kind: kindOpt, config, getContextRunner, only, namePrefixes } = options;
|
|
271
|
+
const packageRoot = resolveExtensionPackageRoot(packagePath);
|
|
272
|
+
const contextRunner = getContextRunner();
|
|
273
|
+
const loaded = chunkBNIE2IKZ_cjs.loadExtensionManifest(packagePath);
|
|
274
|
+
const kind = kindOpt ?? loaded.kind ?? "extension";
|
|
275
|
+
chunkBNIE2IKZ_cjs.registerToolsFromManifest(registry, {
|
|
276
|
+
manifestPathOrDir: packagePath,
|
|
277
|
+
kind,
|
|
278
|
+
only,
|
|
279
|
+
namePrefixes,
|
|
280
|
+
packageRoot
|
|
281
|
+
});
|
|
282
|
+
const adapter = createDynamicImportAdapter({
|
|
283
|
+
kind,
|
|
284
|
+
packageRoot,
|
|
285
|
+
getExtensionContext: (execCtx, spec, mergedArgs) => {
|
|
286
|
+
const defaultArgs = spec._meta?.defaultArgs ?? {};
|
|
287
|
+
const baseConfig = config !== void 0 ? config : {};
|
|
288
|
+
const toolOverrides = baseConfig?.toolOverrides;
|
|
289
|
+
const shortName = spec._meta?.shortName ?? spec.name;
|
|
290
|
+
const prefixWithVersion = shortName && spec.name.endsWith(shortName) && spec.name.length > shortName.length ? spec.name.slice(0, spec.name.length - shortName.length - 1) : "";
|
|
291
|
+
const prefixCandidates = deriveConfigPrefixCandidates(prefixWithVersion);
|
|
292
|
+
const packageScopedKeys = prefixCandidates.map((prefix) => `${prefix}::${shortName}`);
|
|
293
|
+
const perTool = toolOverrides?.[spec.name] ?? packageScopedKeys.map((key) => toolOverrides?.[key]).find((value) => value !== void 0) ?? toolOverrides?.[shortName] ?? {};
|
|
294
|
+
const packageDefaults = baseConfig?.packageDefaults;
|
|
295
|
+
const packageDefaultsForPkg = prefixCandidates.map((prefix) => packageDefaults?.[prefix]).find((value) => value !== void 0) ?? {};
|
|
296
|
+
const baseWithoutOverrides = { ...baseConfig };
|
|
297
|
+
delete baseWithoutOverrides.toolOverrides;
|
|
298
|
+
delete baseWithoutOverrides.packageDefaults;
|
|
299
|
+
const resolvedConfig = {
|
|
300
|
+
...defaultArgs,
|
|
301
|
+
...baseWithoutOverrides,
|
|
302
|
+
...packageDefaultsForPkg,
|
|
303
|
+
...perTool,
|
|
304
|
+
...mergedArgs ?? {}
|
|
305
|
+
};
|
|
306
|
+
return { execCtx, config: resolvedConfig };
|
|
307
|
+
},
|
|
308
|
+
contextRunner: {
|
|
309
|
+
runWith(ctx, fn) {
|
|
310
|
+
return contextRunner.runWith(ctx, fn);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
return adapter;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// src/api/extension/createExtension.ts
|
|
318
|
+
function resolvePackagePath(options) {
|
|
319
|
+
if (options.packagePath != null && options.packagePath !== "") return options.packagePath;
|
|
320
|
+
if (options.importMeta?.url) return path4__default.default.dirname(url.fileURLToPath(options.importMeta.url));
|
|
321
|
+
throw new Error("createExtension: provide packagePath or importMeta");
|
|
322
|
+
}
|
|
323
|
+
function createExtension(options) {
|
|
324
|
+
const packagePath = resolvePackagePath(options);
|
|
325
|
+
const kind = options.kind;
|
|
326
|
+
const buildConfig = "buildConfig" in options ? options.buildConfig : void 0;
|
|
327
|
+
const contextRunner = createContextRunner();
|
|
328
|
+
return {
|
|
329
|
+
register(registry, userConfigOrOpts, opts) {
|
|
330
|
+
const config = buildConfig ? buildConfig(userConfigOrOpts) : userConfigOrOpts;
|
|
331
|
+
return registerExtension(registry, {
|
|
332
|
+
packagePath,
|
|
333
|
+
kind,
|
|
334
|
+
config,
|
|
335
|
+
getContextRunner: () => contextRunner,
|
|
336
|
+
only: opts?.only ?? userConfigOrOpts?.only,
|
|
337
|
+
namePrefixes: opts?.namePrefixes ?? userConfigOrOpts?.namePrefixes
|
|
338
|
+
});
|
|
339
|
+
},
|
|
340
|
+
getContext() {
|
|
341
|
+
return contextRunner.getContext();
|
|
342
|
+
},
|
|
343
|
+
runWith(ctx, fn) {
|
|
344
|
+
return contextRunner.runWith(ctx, fn);
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
function copyToolYamlRecursive(srcDir, destDir) {
|
|
349
|
+
if (!fs.existsSync(srcDir)) return 0;
|
|
350
|
+
let copied = 0;
|
|
351
|
+
for (const e of fs.readdirSync(srcDir, { withFileTypes: true })) {
|
|
352
|
+
const srcPath = path4__default.default.join(srcDir, e.name);
|
|
353
|
+
const destPath = path4__default.default.join(destDir, e.name);
|
|
354
|
+
if (e.isFile() && (e.name.endsWith(".tool.yaml") || e.name.endsWith(".example.yaml"))) {
|
|
355
|
+
if (!fs.existsSync(destDir)) fs.mkdirSync(destDir, { recursive: true });
|
|
356
|
+
fs.copyFileSync(srcPath, destPath);
|
|
357
|
+
copied++;
|
|
358
|
+
} else if (e.isDirectory()) {
|
|
359
|
+
copied += copyToolYamlRecursive(srcPath, destPath);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return copied;
|
|
363
|
+
}
|
|
364
|
+
function generateExtensionManifest(projectRoot = process.cwd(), options = {}) {
|
|
365
|
+
const root = path4__default.default.resolve(projectRoot);
|
|
366
|
+
const outDir = path4__default.default.resolve(options.outDir ?? path4__default.default.join(root, "dist"));
|
|
367
|
+
const kind = options.kind ?? "core";
|
|
368
|
+
const { specs, errors } = chunkJW4EMVTE_cjs.scanForTools({
|
|
369
|
+
projectPath: root,
|
|
370
|
+
include: options.include ?? ["**/*.ts"],
|
|
371
|
+
tsconfigPath: options.tsconfigPath
|
|
372
|
+
});
|
|
373
|
+
if (errors.length > 0) {
|
|
374
|
+
console.warn("generateExtensionManifest: scan errors", errors);
|
|
375
|
+
}
|
|
376
|
+
const entries = specs.map((spec) => {
|
|
377
|
+
const sourcePathNoExt = (spec.sourcePath ?? "").replace(/\.(ts|tsx)$/i, "");
|
|
378
|
+
const pathBasedName = sourcePathNoExt.replace(/^src\//, "").replace(/\//g, ".");
|
|
379
|
+
const name = spec.exportName ?? pathBasedName;
|
|
380
|
+
const sideEffect = spec._meta?.hitl?.sideEffect ?? "none";
|
|
381
|
+
return {
|
|
382
|
+
name,
|
|
383
|
+
description: spec.description ?? sourcePathNoExt,
|
|
384
|
+
inputSchema: spec.inputSchema ?? { type: "object", additionalProperties: true },
|
|
385
|
+
outputSchema: spec.outputSchema ?? { type: "object", additionalProperties: true },
|
|
386
|
+
sourcePath: sourcePathNoExt,
|
|
387
|
+
exportName: spec.exportName ?? "",
|
|
388
|
+
sideEffect
|
|
389
|
+
};
|
|
390
|
+
});
|
|
391
|
+
if (!fs.existsSync(outDir)) fs.mkdirSync(outDir, { recursive: true });
|
|
392
|
+
const manifestPath = path4__default.default.join(outDir, "core-tools-manifest.json");
|
|
393
|
+
fs.writeFileSync(
|
|
394
|
+
manifestPath,
|
|
395
|
+
JSON.stringify({ kind, tools: entries }, null, 2),
|
|
396
|
+
"utf-8"
|
|
397
|
+
);
|
|
398
|
+
let toolYamlCopied = 0;
|
|
399
|
+
const copyDirs = options.copyToolYamlDirs;
|
|
400
|
+
if (copyDirs?.length) {
|
|
401
|
+
for (const d of copyDirs) {
|
|
402
|
+
const srcDir = path4__default.default.join(root, d);
|
|
403
|
+
const destDir = path4__default.default.join(outDir, d);
|
|
404
|
+
try {
|
|
405
|
+
toolYamlCopied += copyToolYamlRecursive(srcDir, destDir);
|
|
406
|
+
} catch {
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
return { manifestPath, toolsCount: entries.length, toolYamlCopied };
|
|
411
|
+
}
|
|
412
|
+
function generateManifest(projectRoot = process.cwd(), options = {}) {
|
|
413
|
+
const { manifestPath, toolsCount, toolYamlCopied } = generateExtensionManifest(projectRoot, {
|
|
414
|
+
include: ["src/**/*.ts"],
|
|
415
|
+
copyToolYamlDirs: ["src"],
|
|
416
|
+
...options
|
|
417
|
+
});
|
|
418
|
+
console.log(`Wrote ${toolsCount} tools to ${path4__default.default.relative(projectRoot, manifestPath)}`);
|
|
419
|
+
if (toolYamlCopied > 0) console.log(`Copied ${toolYamlCopied} .tool.yaml/.example.yaml file(s) to dist`);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// src/utils/overrideWithConfig.ts
|
|
423
|
+
function overrideWithConfig(defaults, config) {
|
|
424
|
+
const source = config != null && typeof config === "object" && !Array.isArray(config) ? config : {};
|
|
425
|
+
const output = { ...defaults };
|
|
426
|
+
for (const key of Object.keys(defaults)) {
|
|
427
|
+
if (key in source && source[key] !== void 0) {
|
|
428
|
+
output[key] = source[key];
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
return output;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// src/api/extension/support/groupPrefix.ts
|
|
435
|
+
function getGroupNamePrefixes(options) {
|
|
436
|
+
const { groups, only, groupPrefixMap } = options;
|
|
437
|
+
const onlySet = only?.length ? new Set(only) : null;
|
|
438
|
+
const namePrefixes = !onlySet && groups?.length ? groups.map((g) => groupPrefixMap[g]).filter((x) => x != null) : void 0;
|
|
439
|
+
return {
|
|
440
|
+
...onlySet ? { only: Array.from(onlySet) } : {},
|
|
441
|
+
...namePrefixes?.length ? { namePrefixes } : {}
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
Object.defineProperty(exports, "loadExtensionManifest", {
|
|
446
|
+
enumerable: true,
|
|
447
|
+
get: function () { return chunkBNIE2IKZ_cjs.loadExtensionManifest; }
|
|
448
|
+
});
|
|
449
|
+
Object.defineProperty(exports, "loadToolYaml", {
|
|
450
|
+
enumerable: true,
|
|
451
|
+
get: function () { return chunkBNIE2IKZ_cjs.loadToolYaml; }
|
|
452
|
+
});
|
|
453
|
+
Object.defineProperty(exports, "registerToolsFromManifest", {
|
|
454
|
+
enumerable: true,
|
|
455
|
+
get: function () { return chunkBNIE2IKZ_cjs.registerToolsFromManifest; }
|
|
456
|
+
});
|
|
457
|
+
Object.defineProperty(exports, "ToolRegistry", {
|
|
458
|
+
enumerable: true,
|
|
459
|
+
get: function () { return chunkAGLGFQUW_cjs.ToolRegistry; }
|
|
460
|
+
});
|
|
461
|
+
Object.defineProperty(exports, "createTaggedError", {
|
|
462
|
+
enumerable: true,
|
|
463
|
+
get: function () { return chunkAGLGFQUW_cjs.createTaggedError; }
|
|
464
|
+
});
|
|
465
|
+
Object.defineProperty(exports, "isRetryable", {
|
|
466
|
+
enumerable: true,
|
|
467
|
+
get: function () { return chunkAGLGFQUW_cjs.isRetryable; }
|
|
468
|
+
});
|
|
469
|
+
Object.defineProperty(exports, "resolveSandboxedPath", {
|
|
470
|
+
enumerable: true,
|
|
471
|
+
get: function () { return chunkAGLGFQUW_cjs.resolveSandboxedPath; }
|
|
472
|
+
});
|
|
473
|
+
Object.defineProperty(exports, "setSandboxValidationEnabled", {
|
|
474
|
+
enumerable: true,
|
|
475
|
+
get: function () { return chunkAGLGFQUW_cjs.setSandboxValidationEnabled; }
|
|
476
|
+
});
|
|
477
|
+
Object.defineProperty(exports, "withRetry", {
|
|
478
|
+
enumerable: true,
|
|
479
|
+
get: function () { return chunkAGLGFQUW_cjs.withRetry; }
|
|
480
|
+
});
|
|
481
|
+
exports.createContextRunner = createContextRunner;
|
|
482
|
+
exports.createDynamicImportAdapter = createDynamicImportAdapter;
|
|
483
|
+
exports.createExtension = createExtension;
|
|
484
|
+
exports.generateExtensionManifest = generateExtensionManifest;
|
|
485
|
+
exports.generateManifest = generateManifest;
|
|
486
|
+
exports.getGroupNamePrefixes = getGroupNamePrefixes;
|
|
487
|
+
exports.isIpInBlockedCidrs = isIpInBlockedCidrs;
|
|
488
|
+
exports.overrideWithConfig = overrideWithConfig;
|
|
489
|
+
exports.registerExtension = registerExtension;
|
|
490
|
+
exports.resolveExtensionPackageRoot = resolveExtensionPackageRoot;
|
|
491
|
+
exports.validateUrl = validateUrl;
|
|
492
|
+
//# sourceMappingURL=sdk.cjs.map
|
|
493
|
+
//# sourceMappingURL=sdk.cjs.map
|