Trigger API Reference
Reference for repository trigger descriptors, event envelopes, condition matching, retry controls, and declarative app-tool actions.
CLI v0.23.1
Repository triggers use the generated
ansight/triggers/ansight-automation.d.ts contract. That file is authoritative
for the installed Ansight version; this page provides a navigable reference.
Module shape
Every trigger exports a JSON-compatible descriptor and one default function:
import type {
TriggerContext,
TriggerDefinition
} from "./ansight-automation.d.ts";
type Payload = {
priority: string;
message?: string;
};
export const trigger = {
schemaVersion: 1,
eventKind: "session.log.received",
conditions: [
{
field: "payload.priority",
operator: "equals",
value: "Error"
}
]
} satisfies TriggerDefinition<"session.log.received">;
export default function run({ event, app }: TriggerContext<Payload>) {
return app.artifacts.request({
providerId: "example.diagnostics",
artifactId: "state",
arguments: { message: event.payload.message ?? "" }
});
}
The function returns nothing or exactly one declarative app-tool action. It does not execute the action itself.
TriggerDefinition<TEventKind>
| Field | Type | Required | Contract |
|---|---|---|---|
schemaVersion | 1 | No | Defaults to version 1. |
appId | string | Sometimes | Optional in a selected Studio workspace; required for embedded-host repository paths. |
eventKind | EventKind | Yes | Exact normalized event kind. |
eventSchema | JsonSchema | No | Describes event.payload; version 1 does not use it for matching. |
functionTimeoutMs | number | No | TypeScript function bound: 10–1,000 ms; default 100. |
actionTimeoutSeconds | number | No | Separate app action bound: 1–300 seconds; default 30. |
retry | RetryPolicy | No | Host-owned policy with 1–5 total attempts. |
conditions | Condition[] | No | At most 16 C#-evaluated conditions; every condition is ANDed. |
The descriptor is extracted without importing the module. Keep it a static object literal without variables, functions, spreads, or computed values.
TriggerContext<TPayload, TEventKind>
| Property | Type | Meaning |
|---|---|---|
run | Readonly<TriggerRun> | Host-owned identity, attempt number, queue time, and effective limits. |
event | Readonly<EventEnvelope<TPayload, TEventKind>> | Immutable normalized event that matched. |
app | AppContext | Factories for the one optional app-tool action. |
TriggerRun
| Property | Type | Meaning |
|---|---|---|
runId | string | Stable across retry attempts. |
triggerId | string | Repository-relative trigger ID. |
repositoryRootPath | string | Absolute connected repository root. |
enqueuedAtUtc | string | ISO-8601 queue timestamp. |
functionTimeoutMs | number | Effective TypeScript function bound. |
actionTimeoutSeconds | number | Effective returned-action bound. |
attemptNumber | number | One-based current attempt. |
maximumAttempts | number | Total attempts permitted. |
EventEnvelope<TPayload, TEventKind>
| Property | Type | Meaning |
|---|---|---|
eventId | string | Stable source-event identity. |
kind | TEventKind | Normalized event kind. |
occurredAtUtc | string | ISO-8601 occurrence time. |
appId | string | App scope used for matching. |
sessionId | string | null | Live or captured session when present. |
correlationId | string | Propagated into a returned app action. |
causationId | string | null | Optional causing event or operation. |
payload | TPayload | Event-specific normalized data. |
EventKind
| Family | Values |
|---|---|
| Application | app.event, app.lifecycle.changed |
| Pairing | app.pairing.discoveryReceived, app.pairing.accepted, app.pairing.rejected, app.pairing.unknown |
| Capture lifecycle | session.capture.started, session.capture.updated, session.capture.stopped, session.capture.finalized, session.capture.unknown |
| Session transfer | session.transfer.telemetry, session.transfer.log, session.transfer.appEvent, session.transfer.appProfile, session.transfer.screenshot, session.transfer.visualTree, session.transfer.touchInput, session.transfer.annotatedFeedback, session.transfer.unknown |
| Captured logs | session.log.received |
| Quality | quality.check.failed, quality.trend.regressed, quality.trend.recovered, quality.unknown |
Condition
Conditions are evaluated by the host before Node starts.
interface Condition {
field: ConditionField;
operator: ConditionOperator;
value?: unknown;
ignoreCase?: boolean;
}
Top-level field values are eventId, kind, occurredAtUtc, appId,
sessionId, correlationId, and causationId. Nested payload fields use
payload.<path>.
| Operator | Needs value | Behavior |
|---|---|---|
equals | Yes | Exact equality. |
notEquals | Yes | Exact inequality. |
contains | Yes | String or supported collection containment. |
startsWith | Yes | String prefix. |
endsWith | Yes | String suffix. |
exists | No | Field is present. |
notExists | No | Field is absent. |
ignoreCase enables ordinal case-insensitive string comparison. Every condition
must pass; there is no executable predicate or OR group in contract version 1.
RetryPolicy
| Field | Range | Default |
|---|---|---|
maxAttempts | 1–5, including the first | 1 |
initialDelayMs | 10–60,000 ms | 250 when retries are enabled |
backoffMultiplier | 1–10 | 2 |
maxDelayMs | At least the initial delay; at most 60,000 ms | Eight times initial delay, capped at 60,000 |
Only failed and timed-out attempts retry. Each attempt starts a new process but keeps the same run, event, and correlation identity.
app: action factories
These methods return an AppToolAction; they do not return a promise and do not
call the app inside TypeScript. Return one action from the function so the C#
host can validate, authorize, audit, and dispatch it.
| Namespace | Methods |
|---|---|
app.artifacts | query(args?), request(args) |
app.ui | getVisualTree(args?), getScreenshot(args?), inspectNode(args?), showOverlay(args?), getOverlay(args?), queryOverlays(args?), updateOverlay(args?), removeOverlay(args?), clearOverlays(args?) |
app.files | listDirectory(args?), readFile(args?), getChecksum(args?), download(args?), beginBinaryDownload(args?), push(args?), copy(args?), move(args?), delete(args?) |
app.fileDescriptors | listOpen(args?), countOpen(args?), inspect(args?), getUsage(args?) |
app.jniReferences | captureGraph(args?) |
app.preferences | listKeys(args?), get(args?), set(args?), remove(args?) |
app.secureStorage | get(args?), set(args?), remove(args?) |
app.data | listDatabases(args?), describeSchema(args?), query(args?) |
app.reflection | listRoots(args?), inspectObject(args?), describeType(args?), setMemberValue(args?), invokeMethod(args?) |
app.maui | getCurrentPage(args?), getVisualTree(args?), findElements(args?), getElement(args?), getBindableProperty(args?), setBindableProperty(args?), clearBindableProperty(args?), inflateXaml(args?), addElement(args?), removeElement(args?), setAppTheme(args?), getBindingContext(args?), getBindings(args?), getResourceState(args?), getNavigationState(args?), invokeElementAction(args?), waitForUi(args?), getLayoutDiagnostics(args?), getHandlerDiagnostics(args?), invokeBindingContextCommand(args?), setBindingContextProperty(args?) |
app.react | getComponentTree(args?), getShadowTree(args?), findComponents(args?), getComponent(args?), getNavigationState(args?), invokeComponentAction(args?) |
app.flutter | getWidgetTree(args?), inspectWidget(args?), findWidgets(args?), getNavigationState(args?) |
app.capacitor | getDocument(args?), inspectNode(args?), querySelector(args?), invokeAction(args?) |
app | callTool(toolId, args?) for an app-defined tool |
AppToolAction<TArguments>
Every factory produces the same declarative shape:
interface AppToolAction<TArguments extends AppToolArguments> {
type: "appTool";
toolId: string;
arguments: TArguments;
}
The host preserves the matched event’s session and correlation identity. The action is rejected if no live session is available, the tool is absent, its arguments are invalid, or the app’s guard denies it.
Return contract
type TriggerFunction<TPayload, TEventKind> = (
invocation: TriggerContext<TPayload, TEventKind>
) =>
| AppToolAction
| null
| void
| Promise<AppToolAction | null | void>;
Return null or nothing for a match that needs local computation only. A
trigger cannot execute Studio-owned host APIs, dispatch multiple app actions,
register new event sources, or supply an executable predicate.
Execution rules
- The exact App ID, event kind, and every condition are matched before Node starts.
- The function timeout and action timeout are separate.
- Repository trigger code is trusted local code, not a filesystem or network sandbox.
- App actions retain the connected app’s grants and critical-tool policy.
- Trigger catalogs must be explicitly connected before they receive events.
- A repository can define up to 256 triggers; each module is limited to 1 MiB.