@caplets/core 0.11.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/dist/native.js ADDED
@@ -0,0 +1,92 @@
1
+ import { E as errorResult, S as resolveProjectConfigPath, a as OpenApiManager, b as resolveConfigPath, c as DownstreamManager, h as loadConfig, i as capabilityDescription, m as CliToolsManager, n as handleServerTool, o as HttpActionManager, r as ServerRegistry, s as GraphQLManager, t as generatedToolInputSchema } from "./tools-BlFF20vE.js";
2
+ import { generatedToolInputJsonSchema } from "./generated-tool-input-schema.js";
3
+ //#region src/native/tools.ts
4
+ function nativeCapletToolName(capletId) {
5
+ return `caplets_${capletId.replace(/_/g, "__").replace(/-/g, "_dash_")}`;
6
+ }
7
+ function nativeCapletsSystemGuidance(toolNames) {
8
+ return [
9
+ "## Caplets Native Tools",
10
+ "",
11
+ "Caplets tools are native wrappers around configured Caplet backends. Each tool is named `caplets_<id>` and represents one capability domain.",
12
+ "",
13
+ "Available Caplets native tools:",
14
+ toolNames.length > 0 ? toolNames.map((tool) => `- ${tool}`).join("\n") : "- none",
15
+ "",
16
+ "Recommended flow:",
17
+ "1. Call the relevant `caplets_<id>` tool with `operation: \"get_caplet\"` to read the full Caplet card.",
18
+ "2. Call `check_backend` or `check_mcp_server` only when availability is uncertain.",
19
+ "3. Use `search_tools` or `list_tools` to discover the selected Caplet's downstream operations.",
20
+ "4. Use `get_tool` before `call_tool` when argument or output schema is unclear.",
21
+ "5. For `call_tool`, put downstream inputs only inside the top-level `arguments` object.",
22
+ "6. Do not invent downstream tool names; execute only exact names returned by `list_tools`, `search_tools`, or `get_tool`."
23
+ ].join("\n");
24
+ }
25
+ function nativeCapletPromptGuidance(toolName, caplet) {
26
+ const checkOperation = caplet.backend === "mcp" ? "check_mcp_server" : "check_backend";
27
+ return [
28
+ `Use ${toolName} for the ${caplet.name} Caplet capability domain.`,
29
+ `Call ${toolName} with operation get_caplet before using unfamiliar downstream tools.`,
30
+ `Call ${toolName} with operation ${checkOperation} only when backend availability is uncertain.`,
31
+ `Call ${toolName} with operation search_tools or list_tools to discover exact downstream tool names.`,
32
+ `Call ${toolName} with operation call_tool only with exact downstream tool names and put downstream inputs in arguments.`
33
+ ];
34
+ }
35
+ function nativeCapletToolDescription(toolName, caplet) {
36
+ return [
37
+ capabilityDescription(caplet),
38
+ "",
39
+ `Native tool name: ${toolName}`,
40
+ `Original Caplet ID: ${caplet.server}`
41
+ ].join("\n");
42
+ }
43
+ //#endregion
44
+ //#region src/native/service.ts
45
+ function createNativeCapletsService(options = {}) {
46
+ return new DefaultNativeCapletsService(options);
47
+ }
48
+ var DefaultNativeCapletsService = class {
49
+ config;
50
+ registry;
51
+ downstream;
52
+ openapi;
53
+ graphql;
54
+ http;
55
+ cli;
56
+ constructor(options) {
57
+ const configPath = resolveConfigPath(options.configPath);
58
+ const projectConfigPath = options.projectConfigPath ?? resolveProjectConfigPath();
59
+ this.config = loadConfig(configPath, projectConfigPath);
60
+ this.registry = new ServerRegistry(this.config);
61
+ const authOptions = options.authDir ? { authDir: options.authDir } : void 0;
62
+ this.downstream = new DownstreamManager(this.registry, authOptions);
63
+ this.openapi = new OpenApiManager(this.registry, authOptions);
64
+ this.graphql = new GraphQLManager(this.registry, authOptions);
65
+ this.http = new HttpActionManager(this.registry, authOptions);
66
+ this.cli = new CliToolsManager(this.registry);
67
+ }
68
+ listTools() {
69
+ return this.registry.enabledServers().map((caplet) => {
70
+ const toolName = nativeCapletToolName(caplet.server);
71
+ return {
72
+ caplet: caplet.server,
73
+ toolName,
74
+ title: caplet.name,
75
+ description: nativeCapletToolDescription(toolName, caplet),
76
+ promptGuidance: nativeCapletPromptGuidance(toolName, caplet)
77
+ };
78
+ });
79
+ }
80
+ async execute(capletId, request) {
81
+ try {
82
+ return await handleServerTool(this.registry.require(capletId), request, this.registry, this.downstream, this.openapi, this.graphql, this.http, this.cli);
83
+ } catch (error) {
84
+ return errorResult(error);
85
+ }
86
+ }
87
+ async close() {
88
+ await this.downstream.close();
89
+ }
90
+ };
91
+ //#endregion
92
+ export { createNativeCapletsService, generatedToolInputJsonSchema, generatedToolInputSchema, nativeCapletPromptGuidance, nativeCapletToolDescription, nativeCapletToolName, nativeCapletsSystemGuidance };