Interface: FusionInstance<TContext>
Defined in: packages/core/src/core/initFusion.ts:68
The initialized Fusion instance.
Provides context-typed factory methods for tools, presenters, prompts, middleware, and registry. Every method automatically inherits the TContext defined in initFusion<TContext>().
Type Parameters
| Type Parameter | Description |
|---|---|
TContext | The application context type |
Properties
serializer
readonly serializer: JsonSerializer;Defined in: packages/core/src/core/initFusion.ts:291
AOT JSON serializer.
Compile Zod schemas into hyper-fast stringify functions at boot time. Used internally by Presenters; exposed here for advanced use cases.
Example
const stringify = f.serializer.compile(myZodSchema);
if (stringify) {
return success(data, stringify); // 2-5x faster
}Methods
action()
action(name): FluentToolBuilder<TContext>;Defined in: packages/core/src/core/initFusion.ts:127
Create a neutral action tool (no defaults applied).
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Tool name in domain.action format |
Returns
FluentToolBuilder<TContext>
A type-chaining FluentToolBuilder
Example
const updateUser = f.action('users.update')
.describe('Update user profile')
.idempotent()
.withString('id', 'User ID')
.withOptionalString('name', 'New display name')
.handle(async (input, ctx) => {
return ctx.db.user.update({ where: { id: input.id }, data: input });
});error()
error(code, message): ErrorBuilder;Defined in: packages/core/src/core/initFusion.ts:234
Create a fluent, self-healing error builder.
Parameters
| Parameter | Type | Description |
|---|---|---|
code | ErrorCode | Canonical error code |
message | string | Human-readable error message |
Returns
ErrorBuilder
A chaining ErrorBuilder
Example
return f.error('NOT_FOUND', `Project "${id}" not found`)
.suggest('Check the list for valid IDs')
.actions('projects.list');fsm()
fsm(config): StateMachineGate;Defined in: packages/core/src/core/initFusion.ts:318
Create a Finite State Machine gate for temporal anti-hallucination.
Tools bound to FSM states (via .bindState()) are dynamically filtered from tools/list based on the current workflow state.
Parameters
| Parameter | Type | Description |
|---|---|---|
config | FsmConfig | FSM definition (states, transitions, initial state) |
Returns
A new StateMachineGate instance
Example
const gate = f.fsm({
id: 'checkout',
initial: 'empty',
states: {
empty: { on: { ADD_ITEM: 'has_items' } },
has_items: { on: { CHECKOUT: 'payment' } },
payment: { on: { PAY: 'confirmed' } },
confirmed: { type: 'final' },
},
});middleware()
middleware<TDerived>(derive): MiddlewareDefinition<TContext, TDerived>;Defined in: packages/core/src/core/initFusion.ts:180
Define a context-derivation middleware.
Type Parameters
| Type Parameter |
|---|
TDerived extends Record<string, unknown> |
Parameters
| Parameter | Type |
|---|---|
derive | (ctx) => TDerived | Promise<TDerived> |
Returns
MiddlewareDefinition<TContext, TDerived>
Example
const withUser = f.middleware(async (ctx) => ({
user: await ctx.db.users.findUnique(ctx.userId),
}));mutation()
mutation(name): FluentToolBuilder<TContext>;Defined in: packages/core/src/core/initFusion.ts:107
Create a destructive mutation tool (destructive: true by default).
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Tool name in domain.action format |
Returns
FluentToolBuilder<TContext>
A type-chaining FluentToolBuilder
Example
const deleteUser = f.mutation('users.delete')
.describe('Delete a user permanently')
.withString('id', 'User ID to delete')
.handle(async (input, ctx) => {
await ctx.db.user.delete({ where: { id: input.id } });
});presenter()
presenter<TSchema>(config): Presenter<TSchema["_output"]>;Defined in: packages/core/src/core/initFusion.ts:144
Define a Presenter with the standard object-config API.
Type Parameters
| Type Parameter |
|---|
TSchema extends ZodType<any, any, any> |
Parameters
| Parameter | Type |
|---|---|
config | Omit<PresenterConfig<TSchema["_output"]>, "schema"> & { schema: TSchema; } |
Returns
Presenter<TSchema["_output"]>
Example
const InvoicePresenter = f.presenter({
name: 'Invoice',
schema: invoiceSchema,
rules: ['CRITICAL: amount_cents is in CENTS.'],
ui: (inv) => [ui.echarts({ ... })],
});prompt()
Call Signature
prompt(name): FluentPromptBuilder<TContext>;Defined in: packages/core/src/core/initFusion.ts:163
Define a prompt — fluent builder.
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
FluentPromptBuilder<TContext>
Example
const greet = f.prompt('greet')
.describe('Greet a user')
.withString('name', 'User name')
.handler(async (ctx, { name }) => ({
messages: [PromptMessage.user(`Hello ${name}!`)],
}));Call Signature
prompt(name, config): PromptBuilder<TContext>;Defined in: packages/core/src/core/initFusion.ts:164
Parameters
| Parameter | Type |
|---|---|
name | string |
config | Omit<PromptConfig<TContext, Record<string, unknown>>, "handler"> & { handler: (ctx, args) => Promise<PromptResult>; } |
Returns
PromptBuilder<TContext>
query()
query(name): FluentToolBuilder<TContext>;Defined in: packages/core/src/core/initFusion.ts:89
Create a read-only query tool (readOnly: true by default).
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Tool name in domain.action format |
Returns
FluentToolBuilder<TContext>
A type-chaining FluentToolBuilder
Example
const listUsers = f.query('users.list')
.describe('List users from the database')
.withNumber('limit', 'Max results to return')
.withOptionalEnum('status', ['active', 'inactive'], 'Filter by status')
.handle(async (input, ctx) => {
return ctx.db.user.findMany({ take: input.limit });
});registry()
registry(): ToolRegistry<TContext>;Defined in: packages/core/src/core/initFusion.ts:195
Create a pre-typed ToolRegistry ready for registration.
Returns
ToolRegistry<TContext>
Example
const registry = f.registry();
registry.register(listUsers);router()
router(prefix): FluentRouter<TContext>;Defined in: packages/core/src/core/initFusion.ts:216
Create a router that shares prefix, middleware, and tags.
Parameters
| Parameter | Type | Description |
|---|---|---|
prefix | string | Common prefix for all tools (e.g. 'users') |
Returns
FluentRouter<TContext>
A FluentRouter for creating child tools
Example
const users = f.router('users')
.describe('User management')
.use(requireAuth);
const listUsers = users.query('list')
.withNumber('limit', 'Max results')
.handle(async (input) => { ... });sandbox()
sandbox(config?): SandboxEngine;Defined in: packages/core/src/core/initFusion.ts:273
Create a standalone SandboxEngine for advanced use cases.
Use when you need direct control over the sandbox lifecycle, or when calling it from custom middleware/handlers.
Parameters
| Parameter | Type | Description |
|---|---|---|
config? | SandboxConfig | Optional sandbox configuration |
Returns
A new SandboxEngine instance
Example
const sandbox = f.sandbox({ timeout: 3000, memoryLimit: 64 });
const result = await sandbox.execute(
'(data) => data.filter(d => d.risk > 90)',
records,
);
sandbox.dispose();stateSync()
stateSync(): StateSyncBuilder;Defined in: packages/core/src/core/initFusion.ts:241
Create a fluent builder for centralized State Sync policies.
Returns
StateSyncBuilder