Diaphora TypeScript SDK
TypeScript client library for the Diaphora API.
Supported Node.js versions: 20.x, 22.x
Installation
Authentication
The Diaphora client needs your Diaphora credentials. You can either pass these directly to the constructor or via environment variables.
Credentials can also be provided via environment variables:
To use a custom auth scheme, extend DiaphoraAuthenticator:
Setup
| Client | Description |
|---|---|
store | Plan and result management |
router | Plan execution and MCP tools |
Quickstart
Search for plans
Show a plan
Create a plan
Search results for a plan
Run a plan
Stream a plan execution
store (FragsStoreClient)
Plans
| Method | Description |
|---|---|
searchPlans | Search plans. namespace is one of 'all', 'diaphora', 'barndoor', 'none' |
showPlan | Get plan details |
createPlan | Create a plan |
updatePlan | Update a plan |
deletePlan | Delete a plan |
listPlanLabels | List all labels used across plans |
searchPlans
Search plans visible to the authenticated user, with optional filtering and sorting.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
label | string[] | No | Filter to plans tagged with any of the given labels |
search | string | No | Full-text search string |
namespace | 'all' | 'diaphora' | 'barndoor' | 'none' | No | Scope of plans to include |
limit | number | No | Maximum number of results to return |
offset | number | No | Number of results to skip (for pagination) |
orderBy | 'name' | 'created_at' | 'updated_at' | No | Field to sort by |
orderMode | 'ASC' | 'DESC' | No | Sort direction |
Example
showPlan
Get full details for a single plan, including its text and parameter definitions.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
planId | string | Yes | UUID of the plan |
Example
createPlan
Create a new plan.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
body.name | string | Yes | Display name for the plan |
body.description | string | Yes | Human-readable description |
body.visibility | 'user' | 'organization' | 'namespace' | Yes | Who can see the plan |
body.labels | string[] | Yes | Labels to tag the plan with |
body.text | string | Yes | The plan definition (Frags syntax) |
body.namespace | string | No | Namespace to publish to (required when visibility is 'namespace') |
body.document_template | string | No | Go template for the output document |
Example
updatePlan
Replace all fields of an existing plan.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
planId | string | Yes | UUID of the plan to update |
body.name | string | Yes | Display name for the plan |
body.description | string | Yes | Human-readable description |
body.visibility | 'user' | 'organization' | 'namespace' | Yes | Who can see the plan |
body.labels | string[] | Yes | Labels to tag the plan with |
body.text | string | Yes | The plan definition (Frags syntax) |
body.namespace | string | No | Namespace to publish to |
body.document_template | string | No | Go template for the output document |
Example
deletePlan
Delete a plan by ID. Returns void.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
planId | string | Yes | UUID of the plan to delete |
Example
listPlanLabels
List all unique labels used across plans in the organization.
Example
Results
| Method | Description |
|---|---|
searchResults | Search results. status is 'success' or 'error' |
showResults | Get result details |
createResults | Create a result |
deleteResults | Delete a result |
listResultStats | Get result statistics |
searchResults
Search execution results, optionally filtering by plan, status, or date range.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
planId | string | No | Filter to results for a specific plan UUID |
search | string | No | Full-text search string |
status | 'success' | 'error' | No | Filter by execution status |
limit | number | No | Maximum number of results to return |
offset | number | No | Number of results to skip (for pagination) |
start | Date | No | Return only results created at or after this time |
end | Date | No | Return only results created at or before this time |
Example
showResults
Get full details for a single result, including the execution data.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
resultsId | string | Yes | UUID of the result |
Example
createResults
Store a result record manually, useful for persisting results generated outside the router.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
body.plan_id | string | Yes | UUID of the plan this result belongs to |
body.plan_name | string | Yes | Name of the plan at the time of execution |
body.data | object | Yes | Execution response body (result, document, warnings, etc.) |
body.id | string | No | Optional UUID to assign to this result |
Example
deleteResults
Delete a result by ID. Returns void.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
resultsId | string | Yes | UUID of the result to delete |
Example
listResultStats
Get per-result statistics, optionally filtered to a date range.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
start | Date | No | Return only stats for results created at or after this time |
end | Date | No | Return only stats for results created at or before this time |
Example
Public Links
| Method | Description |
|---|---|
listPublicLinks | List public links for a result |
createPublicLink | Create a public link. expires_in accepts values like '7d' or '24h' |
deletePublicLink | Delete a public link |
showResultPublicLink | Fetch a result via public link (no auth required) |
listPublicLinks
List all public share links for a result.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
resultsId | string | Yes | UUID of the result |
Example
createPublicLink
Create a public share link for a result with an expiry duration and a display label.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
resultsId | string | Yes | UUID of the result |
body.expires_in | string | Yes | How long until the link expires, e.g. '7d' or '24h' |
body.label | string | Yes | Human-readable label for this link |
Example
deletePublicLink
Revoke a public link. Returns void.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
resultsId | string | Yes | UUID of the result |
publicLinkId | string | Yes | UUID of the public link to revoke |
Example
showResultPublicLink
Fetch result details via a public link — no authentication required.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
publicLinkId | string | Yes | UUID of the public link |
Example
Tools & Schema
| Method | Description |
|---|---|
listTools | List available tools |
showTool | Get tool details |
showDefaultTools | Get default tools |
createTool | Create a tool |
updateTool | Update a tool |
showMcpServerDetails | Get MCP server details for a tool |
showApiCPServerDetails | Get API CP server details for a tool |
getFragsSchema | Get the Frags JSON schema |
getFragsSkill | Get the Frags skill definition |
listTools
List all tool configurations available to the organization.
Example
showTool
Get full details of a tool configuration. Facet parameters filter which MCP servers, collections, and API CPs are returned.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
toolId | string | Yes | UUID of the tool |
facetMcps | string[] | No | Only include these MCP server IDs |
facetCollections | string[] | No | Only include these collection names |
facetApiCps | string[] | No | Only include these API CP IDs |
Example
showDefaultTools
Get the default tool configuration. Facet parameters work the same as showTool.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
facetMcps | string[] | No | Only include these MCP server IDs |
facetCollections | string[] | No | Only include these collection names |
facetApiCps | string[] | No | Only include these API CP IDs |
Example
createTool
Create a new tool configuration.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
body.name | string | Yes | Display name for the tool |
body.default | boolean | Yes | Whether this is the default tool configuration |
body.mcp_servers | mcp_server[] | Yes | MCP servers to include |
body.collections | collection[] | Yes | Collections to include |
body.api_cps | apicp_config[] | Yes | API CP servers to include |
Example
updateTool
Replace all fields of an existing tool configuration.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
toolId | string | Yes | UUID of the tool to update |
body.name | string | Yes | Display name for the tool |
body.default | boolean | Yes | Whether this is the default tool configuration |
body.mcp_servers | mcp_server[] | Yes | MCP servers to include |
body.collections | collection[] | Yes | Collections to include |
body.api_cps | apicp_config[] | Yes | API CP servers to include |
Example
showMcpServerDetails
Get the configuration for a specific MCP server within a tool.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
toolId | string | Yes | UUID of the tool |
serverId | string | Yes | UUID of the MCP server |
Example
showApiCPServerDetails
Get the configuration for a specific API CP server within a tool.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
toolId | string | Yes | UUID of the tool |
serverId | string | Yes | UUID of the API CP server |
Example
getFragsSchema
Fetch the Frags JSON schema used to validate plan definitions.
Example
getFragsSkill
Fetch the Frags skill definition as a markdown string, suitable for use as an LLM system prompt.
Example
router (FragsRouterClient)
Plan Execution
| Method | Description |
|---|---|
runPlan | Execute a plan synchronously |
streamPlan | Execute a plan and receive SSE events via callback. Returns the final result. |
streamPlan delivers StreamEvent objects to the callback:
event.event | Additional fields | Description |
|---|---|---|
'start' | component, session | A component started |
'end' | component | A component finished |
'result' | content | Result payload — content.document holds the output text |
runPlan
Execute a plan synchronously and return the result once complete.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
planId | string | Yes | UUID of the plan to execute |
body.parameters | Record<string, unknown> | No | Input parameters for the plan (defaults to {}) |
body.auth_overrides | auth_override[] | No | Per-execution token overrides for MCP/API CP servers |
body.resources | Record<string, string> | No | Named resource bindings for the execution |
Example
streamPlan
Execute a plan and receive StreamEvent objects via a callback as each component starts and finishes. Returns the final result content once the stream closes, or undefined if the stream ends without a result event.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
planId | string | Yes | UUID of the plan to execute |
body.parameters | Record<string, unknown> | No | Input parameters for the plan (defaults to {}) |
body.auth_overrides | auth_override[] | No | Per-execution token overrides for MCP/API CP servers |
body.resources | Record<string, string> | No | Named resource bindings for the execution |
onEvent | (event: StreamEvent) => void | No | Callback invoked for each SSE event |
Unlike runPlan, the returned promise can resolve to undefined (the stream may end without ever emitting a result event) — always guard with ?. or a null check.
Example
MCP Tools
| Method | Description |
|---|---|
checkPlanMcpRequirements | Check which MCP servers a plan needs and their auth status |
refreshPlanMcpRequirements | Force-refresh MCP requirement status |
checkToolMcpRequirements | Check global MCP requirements |
listToolCommands | List commands on an MCP server |
callToolCommand | Execute an MCP command |
listMcpAuthCache | List cached MCP OAuth tokens |
deleteMcpAuthCache | Revoke a cached MCP token |
mcpCallback | Handle an OAuth redirect callback |
renderTemplate | Render a template |
checkPlanMcpRequirements
Check which MCP and API CP servers a plan requires and whether they are currently authenticated.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
planId | string | Yes | UUID of the plan |
Example
refreshPlanMcpRequirements
Force-refresh the MCP requirement status for a plan, clearing any cached auth state.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
planId | string | Yes | UUID of the plan |
Example
checkToolMcpRequirements
Check the MCP and API CP authentication status across all tool configurations globally.
Example
listToolCommands
List all available commands on a specific MCP server within a tool configuration.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
toolsId | string | Yes | UUID of the tool configuration |
serverId | string | Yes | UUID of the MCP server |
Example
callToolCommand
Execute a named command on an MCP server and return the result.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
toolsId | string | Yes | UUID of the tool configuration |
serverId | string | Yes | UUID of the MCP server |
commandName | string | Yes | Name of the command to execute |
body | Record<string, unknown> | Yes | Input arguments for the command |
Example
listMcpAuthCache
List currently cached MCP OAuth tokens.
Example
deleteMcpAuthCache
Revoke a cached MCP OAuth token. Returns void.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
cacheId | string | Yes | ID of the cache entry to revoke |
Example
mcpCallback
Handle the OAuth redirect callback after a user completes MCP authentication in their browser. Called automatically by the OAuth flow — you typically do not need to call this directly.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
state | string | Yes | OAuth state parameter from the redirect URL |
code | string | Yes | Authorization code from the redirect URL |
Example
renderTemplate
Render a Go template string with a provided scope object and return the result as a string.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
body.template | string | Yes | Go template string, e.g. 'Hello {{ .name }}!' |
body.scope | Record<string, unknown> | Yes | Variables available within the template |
Example