Documentation
¶
Overview ¶
Package tsrender produces the TypeScript .d.ts blocks that Airlock embeds into the agent system prompt: typed signatures for registered tools, and per-server `declare const mcp_{slug}: {...}` namespaces for MCP tools.
The package is split out from agentsdk's main API surface so builders (agentsdk consumers) don't see these types in their import autocomplete or godoc — agentsdk's main package stays focused on the builder API (RegisterTool, MCPHandle, etc.). The rendering here is shared between agentsdk's tests and the airlock module's prompt template; both import this package directly.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JSToolNames ¶ added in v0.2.1
JSToolNames maps each MCP tool name to a JS-identifier-safe property name. MCP tool names commonly include hyphens (`notion-update-page`); JS parses `obj.notion-update-page(...)` as arithmetic and throws ReferenceError. The original hyphenated name stays canonical on the wire (tool/call JSON-RPC); only the JS surface is renamed.
Collision handling: when the `-` → `_` rename would clash with another tool's original name on the same server (e.g. `foo-bar` AND `foo_bar` both exist), the hyphenated tool keeps its original name — the LLM has to use bracket notation for that one, but every other tool on the server still gets the dot-friendly form. Iteration is over a sorted copy so the resulting map is stable across syncs.
func RenderMCPNamespace ¶
func RenderMCPNamespace(slug string, tools []MCPToolRender) string
RenderMCPNamespace emits a typed `declare const mcp_{slug}: { ... };` block describing each discovered MCP tool as a method on the namespace object. Mirrors the JS binding shape installed by agentsdk's vm.go so the LLM's call site and the runtime stay in lockstep.
declare const mcp_github: {
/** Search for GitHub repositories. */
search_repos(args: { query: string }): unknown;
...
};
func RenderToolDecls ¶
func RenderToolDecls(tools []ToolRender) string
RenderToolDecls emits a TypeScript .d.ts-style block describing each tool. Output is suitable for direct inclusion in an LLM prompt.
Types ¶
type MCPToolRender ¶
type MCPToolRender struct {
Name string
Description string
InputSchema json.RawMessage
}
MCPToolRender carries the bits Airlock has cached about an MCP tool. Only the input shape is typed — MCP doesn't define an output schema, so the rendered return type is always `unknown` (caller does runtime parsing).
type ToolRender ¶
type ToolRender struct {
Name string
Description string
LLMHint string
InputSchema json.RawMessage
OutputSchema json.RawMessage
InputExamples []json.RawMessage
}
ToolRender is the data RenderToolDecls consumes. Airlock builds this from the hydrated DB/sync payload; the agent assembles it from the registered-tool schemas in tests. Both paths go through the same renderer so the LLM sees one format.
LLMHint is optional model-only guidance that pairs with Description (which may also surface in member-facing UIs). When non-empty it's appended to the JSDoc block in `[brackets]` so the LLM gets the extra steer without polluting the user-visible description.