Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ export interface CommonTriggerDefinition<EventSchema extends z.ZodType = z.ZodTy
/**
* Short human-readable name for this trigger (UI and agent catalog label).
*/
title?: string;
title: string;
/**
* User-facing description of when this trigger is emitted.
*/
description?: string;
description: string;
/**
* Documentation (details + YAML examples), aligned with step definitions.
*/
documentation?: TriggerDocumentation;
documentation: TriggerDocumentation;
/**
* Pre-filled values for snippet insertion (e.g. on.condition).
*/
snippets?: TriggerSnippets;
snippets: TriggerSnippets;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ Trigger IDs use the following convention:
- ⚠️ Allowed: Inherited forms from OpenAPI/connectors/platform-owned contracts
- ❌ Bad: `"my_trigger"` (no namespace), `"custom_trigger"` (event not camelCase)

### Step 1: Define common trigger (id + eventSchema)
### Step 1: Define common trigger (id, eventSchema, title, description, documentation and snippets)

Create a shared definition (e.g. `common/triggers/my_trigger.ts`) in your plugin:
Create a shared definition (e.g. `common/triggers/my_trigger.ts`) in your plugin. Put **title**, **description**, **documentation** (details + YAML examples), and **snippets** here so the server registry, YAML editor, and agent tools share one source of truth (aligned with custom steps):

```typescript
import { i18n } from '@kbn/i18n';
import { z } from '@kbn/zod/v4';
import type { CommonTriggerDefinition } from '@kbn/workflows-extensions/common';

Expand All @@ -42,15 +43,27 @@ export type MyTriggerEvent = z.infer<typeof myTriggerEventSchema>;
export const commonMyTriggerDefinition: CommonTriggerDefinition = {
id: MY_TRIGGER_ID,
eventSchema: myTriggerEventSchema,
title: i18n.translate('myPlugin.myTrigger.title', { defaultMessage: 'My trigger' }),
description: i18n.translate('myPlugin.myTrigger.description', {
defaultMessage: 'Emitted when something happens.',
}),
documentation: {
details: 'Filter when this workflow runs using KQL on event properties (e.g. event.category, event.message).',
examples: [
`## Match by category\n\`\`\`yaml\ntriggers:\n - type: ${MY_TRIGGER_ID}\n on:\n condition: 'event.category: "alerts"'\n\`\`\``,
],
},
snippets: { condition: 'event.category: "alerts"' },
};
```

- Use `.describe()` on schema fields so the UI and docs show helpful text.
- `eventSchema` must be a Zod object schema; payloads are validated at emit time.
- Examples must only reference fields present on `eventSchema` (agents pattern-match YAML examples).

### Step 2: Register on server

In your plugin's server `setup()`, register the common definition (id + eventSchema only):
In your plugin's server `setup()`, register the **same** common definition:

```typescript
import type { WorkflowsExtensionsServerPluginSetup } from '@kbn/workflows-extensions/server';
Expand All @@ -68,30 +81,18 @@ Reference: `examples/workflows_extensions_example/server/triggers/index.ts`.

### Step 3: Register on public

Create a public definition with UI metadata and register it in your plugin's public `setup()`:
Spread the common definition and add **icon** only (browser-only UI):

```typescript
import type { PublicTriggerDefinition } from '@kbn/workflows-extensions/public';
import { i18n } from '@kbn/i18n';
import React from 'react';
import { MY_TRIGGER_ID, commonMyTriggerDefinition } from '../common/triggers/my_trigger';
import { commonMyTriggerDefinition } from '../common/triggers/my_trigger';

export const myTriggerPublicDefinition: PublicTriggerDefinition = {
...commonMyTriggerDefinition,
title: i18n.translate('myPlugin.myTrigger.title', { defaultMessage: 'My trigger' }),
description: i18n.translate('myPlugin.myTrigger.description', {
defaultMessage: 'Emitted when something happens. Use in workflow triggers to run on this event.',
}),
icon: React.lazy(() =>
import('@elastic/eui/es/components/icon/assets/star').then(({ icon }) => ({ default: icon }))
),
documentation: {
details: 'Filter when this workflow runs using KQL on event properties (e.g. event.category, event.message).',
examples: [
`## Match by category\n\`\`\`yaml\ntriggers:\n - type: ${MY_TRIGGER_ID}\n on:\n condition: 'event.category: "alerts"'\n\`\`\``,
],
},
snippets: { condition: 'event.category: "alerts"' },
};

// In public plugin setup():
Expand Down
Loading