Project Structure
A Trik is a self-contained directory with a manifest and implementation.
Minimal Structure
my-trik/
├── manifest.json # Contract and configuration
├── graph.ts # Implementation
└── package.json # Dependencies (optional)Full Structure
For a production trik:
my-trik/
├── manifest.json
├── graph.ts
├── package.json
├── tsconfig.json
├── dist/
│ └── graph.js # Compiled output
├── src/
│ ├── graph.ts # Main implementation
│ ├── utils.ts # Helper functions
│ └── types.ts # Type definitions
└── tests/
└── graph.test.tsFile Descriptions
manifest.json
The contract that defines your Trik. Required.
{
"id": "@yourname/my-trik",
"name": "My Trik",
"description": "What this trik does",
"version": "1.0.0",
"actions": { ... },
"entry": {
"module": "./dist/graph.js",
"export": "default",
"runtime": "node"
}
}See Writing the Manifest for details.
Graph Implementation
Your implementation. Exports an object with an invoke function:
graph.ts:
interface TrikInput {
action: string;
input: unknown;
session?: {
sessionId: string;
history: Array<{ action: string; input: unknown; agentData?: unknown }>;
};
}
interface TrikOutput {
responseMode: 'template' | 'passthrough';
agentData?: Record<string, unknown>;
userContent?: {
contentType: string;
content: string;
metadata?: Record<string, unknown>;
};
}
export default {
async invoke(input: TrikInput): Promise<TrikOutput> {
// Your logic here
}
}Dependencies File
Optional. Use if your trik has dependencies:
package.json:
{
"name": "@yourname/my-trik",
"version": "1.0.0",
"type": "module",
"main": "dist/graph.js",
"scripts": {
"build": "tsc",
"test": "vitest"
},
"dependencies": {
"@anthropic-ai/sdk": "^0.20.0"
},
"devDependencies": {
"typescript": "^5.0.0",
"vitest": "^1.0.0"
}
}TypeScript Configuration
For TypeScript triks:
{
"compilerOptions": {
"target": "ES2020",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"outDir": "./dist",
"strict": true
},
"include": ["src/**/*", "graph.ts"]
}Entry Point
The entry field in your manifest tells the gateway how to load your trik:
{
"entry": {
"module": "./dist/graph.js",
"export": "default",
"runtime": "node"
}
}| Field | Description |
|---|---|
module | Path to compiled JavaScript file |
export | Named export or "default" |
runtime | "node" (default) |
Example exports:
// Default export (recommended)
export default { invoke }
// Named export
export const graph = { invoke }
// manifest: { "entry": { "module": "./graph.js", "export": "graph" } }Organization Tips
Single-file Triks
For simple triks, put everything in one file:
simple-trik/
├── manifest.json
└── graph.tsMulti-file Triks
For complex triks, organize by feature:
complex-trik/
├── manifest.json
├── src/
│ ├── index.ts # Entry point
│ ├── actions/
│ │ ├── search.ts
│ │ └── details.ts
│ ├── services/
│ │ └── api.ts
│ └── types.ts
└── dist/Monorepo Structure
For publishing multiple triks:
my-triks/
├── packages/
│ ├── weather/
│ │ ├── manifest.json
│ │ └── src/
│ └── stocks/
│ ├── manifest.json
│ └── src/
└── package.json # or pyproject.tomlNext: Learn about Writing the Manifest.