Skip to content
Logic SDK
Esc
↑↓navigate↵open⌘Jpreview
On this page

Meta

Meta supplies typed data about a definition to wrap and integrations.

Meta is app-defined data about a definition, such as a tag or an AI tool description.

meta
Data on the function
wrap
Reads the call metadata
toAITool
Reads the tool description
The same meta can give wrap a tag and give an AI tool a description.
const { 
const query: Constructor<{
    scope: {
        accountId: string;
    };
    meta: AIMeta & {
        tags?: string[];
    };
}, "query">
Reads data. Can run other queries. No writes, no events, no services.
query
,
const createRegistry: <const Mods extends Record<string, object>, T = {
    accountId: string;
}>(options: TypedOptions<{
    scope: {
        accountId: string;
    };
    meta: AIMeta & {
        tags?: string[];
    };
}, Mods, T>) => Registry<{
    accountId: string;
}, Mods, Record<string, never>, {}, AppError<`${string extends keyof Mods ? keyof Mods & string : (keyof Mods & string) | { [M in keyof Mods & string]: { [N in keyof Mods[M] & string]: Mods[M][N] extends Fn<Kind, any, any, any, any, any, infer Id extends string | undefined> ? `${M}.${Id extends string ? Id : N}` : never; }[keyof Mods[M] & string]; }[keyof Mods & string]}.forbidden`, undefined> | AppError<...> | AppError<...> | { [M in keyof Mods & string]: { [N in keyof Mods[M] & string]: Mods[M][N] extends ErrorDef<...> ? AppError<...> : never; }[keyof Mods[M] & string]; }[keyof Mods & string]>
Create the registry once at startup: `createRegistry({ modules, database, services })`.
createRegistry
} =
init<{
    scope: {
        accountId: string;
    };
    meta: AIMeta & {
        tags?: string[];
    };
}>(): {
    createRegistry: <Mods, T>(options: TypedOptions<{
        scope: {
            accountId: string;
        };
        meta: AIMeta & {
            tags?: string[];
        };
    }, Mods, T>) => Registry<{
        accountId: string;
    }, Mods, Record<string, never>, {}, AppError<`${string extends keyof Mods ? keyof Mods & string : (keyof Mods & string) | { [M in keyof Mods & string]: { [N in keyof Mods[M] & string]: Mods[M][N] extends Fn<Kind, any, any, any, any, any, infer Id extends string | undefined> ? `${M}.${Id extends string ? Id : N}` : never; }[keyof Mods[M] & string]; }[keyof Mods & string]}.forbidden`, undefined> | AppError<...> | AppError<...> | { [M in keyof Mods & string]: { [N in keyof Mods[M] & string]: Mods[M][N] extends ErrorDef<...> ? AppError<...> : never; }[keyof Mods[M] & string]; }[keyof Mods & string]>;
    ... 6 more ...;
    listener: <O>(def: {
        ...;
    }) => Listener<...>;
}
Typed constructors for your app: ```ts export const { query, mutation, action, event, listener, createRegistry } = init<Config>(); ```
init
<{
scope: {
    accountId: string;
}
scope
: { accountId: stringaccountId: string };
meta: AIMeta & {
    tags?: string[];
}
meta
:
type AIMeta = {
    ai?: {
        description?: string;
    };
}
What this integration reads from a function's `meta`. Add it to your meta shape: `init<{ meta: AIMeta & AppMeta }>()`, then `meta: { ai: { description: "Use when the customer asks to cancel an order" } }`.
AIMeta
& { tags?: string[] | undefinedtags?: string[] };
}>(); /** List the guest's bookings. */ const
const list: Fn<"query", undefined, never[], true, {
    scope: {
        accountId: string;
    };
    meta: AIMeta & {
        tags?: string[];
    };
}, undefined, undefined>
List the guest's bookings.
list
=
const query: <NoInput, undefined, never[], () => boolean, boolean, undefined>(def: Def<{
    scope: {
        accountId: string;
    };
    meta: AIMeta & {
        tags?: string[];
    };
}, "query", NoInput, undefined, never[], () => boolean, boolean, undefined>) => Fn<"query", undefined, never[], true, {
    scope: {
        accountId: string;
    };
    meta: AIMeta & {
        tags?: string[];
    };
}, undefined, undefined>
Reads data. Can run other queries. No writes, no events, no services.
query
({
authorize?: ((() => boolean) & ((scope: {
    accountId: string;
}) => boolean)) | undefined
Who may call it, on every call. A type guard narrows `ctx.scope` in `handler`. Required to publish it through an adapter: callers outside your server are untrusted. Leave it out when only your own code runs it.
authorize
: const anyone: () => booleananyone,
meta?: (AIMeta & {
    tags?: string[];
}) | undefined
meta
: { tags?: string[] | undefinedtags: ["bookings"],
ai?: {
    description?: string;
} | undefined
ai
: { description?: string | undefined
What the model reads to decide when to call it. Optional, but models pick tools better with one.
description
: "Use when asked to list bookings" } },
async
handler: (ctx: QueryCtx<{
    scope: {
        accountId: string;
    };
    meta: AIMeta & {
        tags?: string[];
    };
}, {
    accountId: string;
}>, input: undefined) => Promise<never[]>
handler
() {
return []; }, });
const createRegistry: <{
    readonly bookings: {
        readonly list: Fn<"query", undefined, never[], true, {
            scope: {
                accountId: string;
            };
            meta: AIMeta & {
                tags?: string[];
            };
        }, undefined, undefined>;
    };
}, {
    accountId: string;
}>(options: TypedOptions<{
    scope: {
        accountId: string;
    };
    meta: AIMeta & {
        tags?: string[];
    };
}, {
    readonly bookings: {
        readonly list: Fn<"query", undefined, never[], true, {
            scope: {
                accountId: string;
            };
            meta: AIMeta & {
                tags?: string[];
            };
        }, undefined, undefined>;
    };
}, {
    accountId: string;
}>) => Registry<{
    accountId: string;
}, {
    readonly bookings: {
        readonly list: Fn<"query", undefined, never[], true, {
            scope: {
                accountId: string;
            };
            meta: AIMeta & {
                tags?: string[];
            };
        }, undefined, undefined>;
    };
}, Record<...>, {}, AppError<...> | ... 1 more ... | AppError<...>>
Create the registry once at startup: `createRegistry({ modules, database, services })`.
createRegistry
({
modules: {
    readonly bookings: {
        readonly list: Fn<"query", undefined, never[], true, {
            scope: {
                accountId: string;
            };
            meta: AIMeta & {
                tags?: string[];
            };
        }, undefined, undefined>;
    };
} & OwnModules<{
    scope: {
        accountId: string;
    };
    meta: AIMeta & {
        tags?: string[];
    };
}, {
    readonly bookings: {
        readonly list: Fn<"query", undefined, never[], true, {
            scope: {
                accountId: string;
            };
            meta: AIMeta & {
                tags?: string[];
            };
        }, undefined, undefined>;
    };
}>
One entry per module: `{ bookings, availability }` with `import * as bookings from "./bookings"`.
modules
: {
bookings: {
    readonly list: Fn<"query", undefined, never[], true, {
        scope: {
            accountId: string;
        };
        meta: AIMeta & {
            tags?: string[];
        };
    }, undefined, undefined>;
} & {
    readonly list: Fn<"query", undefined, never[], true, {
        scope: {
            accountId: string;
        };
        meta: AIMeta & {
            tags?: string[];
        };
    }, undefined, undefined>;
}
bookings
: {
list: Fn<"query", undefined, never[], true, {
    scope: {
        accountId: string;
    };
    meta: AIMeta & {
        tags?: string[];
    };
}, undefined, undefined>
list
} },
wrap?: ((call: Call<AIMeta & {
    tags?: string[];
}>, next: () => Promise<unknown>) => Promise<unknown>) | undefined
Wraps every call, including ones that fail validation or authorization: logging, tracing, audit.
wrap
: async (
call: Call<AIMeta & {
    tags?: string[];
}>
call
, next: () => Promise<unknown>next) => {
var console: Consoleconsole.Console.log(...data: any[]): void
The **`console.log()`** static method outputs a message to the console. [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
log
(
call: Call<AIMeta & {
    tags?: string[];
}>
call
.Call<M = unknown>.id: stringid,
call: Call<AIMeta & {
    tags?: string[];
}>
call
.
Call<AIMeta & { tags?: string[]; }>.meta: (AIMeta & {
    tags?: string[];
}) | undefined
The function's, listener's or cron's `meta` (undefined when it has none).
meta
?.tags?: string[] | undefinedtags);
return next: () => Promise<unknown>next(); }, });
  • Shape. Declare the meta shape in init. Include the types your integrations read, such as AIMeta.
  • Tracing (1). wrap receives typed call.meta, even when validation or policy blocks the call. A job’s own call gets call.job with its ID and attempt. Nested calls omit it.
  • Integrations (2). Use one key per integration. Use JSDoc for readers and the CLI.

See also

Functions, AI, API reference

Was this page helpful?