@uniformdev/automations-sdk 20.50.2-alpha.109
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +2 -0
- package/dist/ai/index.d.mts +108 -0
- package/dist/ai/index.mjs +78 -0
- package/dist/api/index.d.mts +707 -0
- package/dist/api/index.mjs +102 -0
- package/dist/chunk-I6KKUHEY.mjs +15 -0
- package/dist/chunk-TWKWPWN3.mjs +10 -0
- package/dist/formatAutomationWebhookUrl-CD1HQmu6.d.mts +10 -0
- package/dist/index.d.mts +272 -0
- package/dist/index.mjs +55 -0
- package/dist/schemas/index.d.mts +64 -0
- package/dist/schemas/index.mjs +21 -0
- package/package.json +66 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {
|
|
2
|
+
formatAutomationWebhookUrl
|
|
3
|
+
} from "../chunk-TWKWPWN3.mjs";
|
|
4
|
+
import {
|
|
5
|
+
__privateAdd,
|
|
6
|
+
__privateGet
|
|
7
|
+
} from "../chunk-I6KKUHEY.mjs";
|
|
8
|
+
|
|
9
|
+
// src/api/AutomationsClient.ts
|
|
10
|
+
import { ApiClient } from "@uniformdev/context/api";
|
|
11
|
+
var _automationsUrl, _runsUrl, _logsUrl;
|
|
12
|
+
var _AutomationsClient = class _AutomationsClient extends ApiClient {
|
|
13
|
+
/**
|
|
14
|
+
* Lists the automations configured for a project.
|
|
15
|
+
*/
|
|
16
|
+
async list() {
|
|
17
|
+
const { projectId } = this.options;
|
|
18
|
+
return await this.apiClient(
|
|
19
|
+
this.createUrl(__privateGet(_AutomationsClient, _automationsUrl), { projectId })
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Deploys (creates or updates) a single automation.
|
|
24
|
+
*
|
|
25
|
+
* @param input - The automation definition + bundled code.
|
|
26
|
+
*/
|
|
27
|
+
async deploy(input) {
|
|
28
|
+
const { projectId } = this.options;
|
|
29
|
+
await this.apiClient(this.createUrl(__privateGet(_AutomationsClient, _automationsUrl)), {
|
|
30
|
+
method: "PUT",
|
|
31
|
+
body: JSON.stringify({ ...input, projectId }),
|
|
32
|
+
expectNoContent: true
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Toggles the enabled state of an automation.
|
|
37
|
+
*
|
|
38
|
+
* @param publicId - The automation public ID.
|
|
39
|
+
* @param enabled - The desired enabled state.
|
|
40
|
+
*/
|
|
41
|
+
async setEnabled(publicId, enabled) {
|
|
42
|
+
const { projectId } = this.options;
|
|
43
|
+
await this.apiClient(this.createUrl(__privateGet(_AutomationsClient, _automationsUrl)), {
|
|
44
|
+
method: "PATCH",
|
|
45
|
+
body: JSON.stringify({ projectId, publicId, enabled }),
|
|
46
|
+
expectNoContent: true
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Deletes an automation.
|
|
51
|
+
*
|
|
52
|
+
* @param publicId - The automation public ID.
|
|
53
|
+
*/
|
|
54
|
+
async remove(publicId) {
|
|
55
|
+
const { projectId } = this.options;
|
|
56
|
+
await this.apiClient(this.createUrl(__privateGet(_AutomationsClient, _automationsUrl)), {
|
|
57
|
+
method: "DELETE",
|
|
58
|
+
body: JSON.stringify({ projectId, publicId }),
|
|
59
|
+
expectNoContent: true
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Lists automation runs for the project, optionally filtered by automation and status.
|
|
64
|
+
*/
|
|
65
|
+
async listRuns(options) {
|
|
66
|
+
var _a;
|
|
67
|
+
const { projectId } = this.options;
|
|
68
|
+
const status = ((_a = options == null ? void 0 : options.statuses) == null ? void 0 : _a.length) ? options.statuses.join(",") : void 0;
|
|
69
|
+
return await this.apiClient(
|
|
70
|
+
this.createUrl(__privateGet(_AutomationsClient, _runsUrl), {
|
|
71
|
+
projectId,
|
|
72
|
+
publicId: options == null ? void 0 : options.publicId,
|
|
73
|
+
status,
|
|
74
|
+
offset: options == null ? void 0 : options.offset,
|
|
75
|
+
limit: options == null ? void 0 : options.limit
|
|
76
|
+
})
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Returns the log entries for a single automation run.
|
|
81
|
+
*
|
|
82
|
+
* @param runId - The automation run ID.
|
|
83
|
+
*/
|
|
84
|
+
async listRunLogs(runId) {
|
|
85
|
+
const { projectId } = this.options;
|
|
86
|
+
const { logs } = await this.apiClient(
|
|
87
|
+
this.createUrl(__privateGet(_AutomationsClient, _logsUrl), { projectId, runId })
|
|
88
|
+
);
|
|
89
|
+
return logs;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
_automationsUrl = new WeakMap();
|
|
93
|
+
_runsUrl = new WeakMap();
|
|
94
|
+
_logsUrl = new WeakMap();
|
|
95
|
+
__privateAdd(_AutomationsClient, _automationsUrl, "/api/v1/automations");
|
|
96
|
+
__privateAdd(_AutomationsClient, _runsUrl, "/api/v1/automation-runs");
|
|
97
|
+
__privateAdd(_AutomationsClient, _logsUrl, "/api/v1/automation-run-logs");
|
|
98
|
+
var AutomationsClient = _AutomationsClient;
|
|
99
|
+
export {
|
|
100
|
+
AutomationsClient,
|
|
101
|
+
formatAutomationWebhookUrl
|
|
102
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
__privateGet,
|
|
12
|
+
__privateAdd,
|
|
13
|
+
__privateSet,
|
|
14
|
+
__privateMethod
|
|
15
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/formatAutomationWebhookUrl.ts
|
|
2
|
+
function formatAutomationWebhookUrl(apiHost, projectId, publicId) {
|
|
3
|
+
const base = apiHost.replace(/\/$/, "");
|
|
4
|
+
const params = new URLSearchParams({ projectId, publicId });
|
|
5
|
+
return `${base}/api/v1/automation-webhooks?${params.toString()}`;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
formatAutomationWebhookUrl
|
|
10
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds the public URL external systems POST to for an incoming-webhook automation.
|
|
3
|
+
*
|
|
4
|
+
* @param apiHost - Uniform API host (e.g. `https://uniform.app` or `window.location.origin`).
|
|
5
|
+
* @param projectId - The project ID.
|
|
6
|
+
* @param publicId - The automation public ID.
|
|
7
|
+
*/
|
|
8
|
+
declare function formatAutomationWebhookUrl(apiHost: string, projectId: string, publicId: string): string;
|
|
9
|
+
|
|
10
|
+
export { formatAutomationWebhookUrl as f };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import { WebhookEventName, WebhookPayloadFor } from '@uniformdev/webhooks';
|
|
3
|
+
import { AutomationResult, AutomationLogEntry } from './schemas/index.mjs';
|
|
4
|
+
export { f as formatAutomationWebhookUrl } from './formatAutomationWebhookUrl-CD1HQmu6.mjs';
|
|
5
|
+
import 'zod';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Trigger configuration for a Uniform platform webhook event. The discriminator
|
|
9
|
+
* `type` is the event name itself (e.g. `entry.changed`), drawn from the
|
|
10
|
+
* `@uniformdev/webhooks` catalog.
|
|
11
|
+
*/
|
|
12
|
+
type EventTriggerConfig<TEvent extends WebhookEventName = WebhookEventName> = {
|
|
13
|
+
type: TEvent;
|
|
14
|
+
};
|
|
15
|
+
/** Trigger configuration for a schedule automation. */
|
|
16
|
+
type ScheduleTriggerConfig = {
|
|
17
|
+
type: 'schedule';
|
|
18
|
+
/** RFC-5545 recurrence rule for when the automation runs. */
|
|
19
|
+
rrule: string;
|
|
20
|
+
/** IANA timezone used to evaluate the recurrence rule. */
|
|
21
|
+
timezone: string;
|
|
22
|
+
};
|
|
23
|
+
/** Trigger configuration for an incoming webhook automation. */
|
|
24
|
+
type IncomingWebhookTriggerConfig = {
|
|
25
|
+
type: 'incomingWebhook';
|
|
26
|
+
};
|
|
27
|
+
/** Trigger configuration for an automation invocable as an AI tool by Scout. */
|
|
28
|
+
type AiToolTriggerConfig = {
|
|
29
|
+
type: 'aiTool';
|
|
30
|
+
};
|
|
31
|
+
/** Canonical authored trigger configuration. */
|
|
32
|
+
type TriggerConfig = EventTriggerConfig | ScheduleTriggerConfig | IncomingWebhookTriggerConfig | AiToolTriggerConfig;
|
|
33
|
+
/** A plain JSON Schema object (used when the argument contract is authored as JSON Schema directly). */
|
|
34
|
+
type JsonSchemaObject = Record<string, unknown>;
|
|
35
|
+
/**
|
|
36
|
+
* The argument contract for an AI-tool automation, surfaced to the LLM.
|
|
37
|
+
*
|
|
38
|
+
* Authored as either a zod schema or a JSON Schema object passed through verbatim.
|
|
39
|
+
* Note: non-zod standard schema providers are not supported.
|
|
40
|
+
*/
|
|
41
|
+
type AiToolInputSchema = StandardSchemaV1 | JsonSchemaObject;
|
|
42
|
+
/**
|
|
43
|
+
* Role grants for the automation's identity.
|
|
44
|
+
*/
|
|
45
|
+
type AutomationPermissions = {
|
|
46
|
+
/** Role grant(s), by team role public ID, on the automation's home project. */
|
|
47
|
+
role: string | string[];
|
|
48
|
+
/** Additional project role grants (use only when you need to give permissions to other projects within the same team). */
|
|
49
|
+
projects?: Record<string, string | string[]>;
|
|
50
|
+
};
|
|
51
|
+
type AutomationMetadataBase = {
|
|
52
|
+
/** Display name surfaced in the dashboard and run history. */
|
|
53
|
+
name: string;
|
|
54
|
+
description?: string;
|
|
55
|
+
/** Runtime compatibility date override (YYYY-MM-DD). */
|
|
56
|
+
compatibilityDate?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Role grants for the automation's identity. When omitted, the automation runs without
|
|
59
|
+
* Uniform API access.
|
|
60
|
+
*/
|
|
61
|
+
permissions?: AutomationPermissions;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Authored metadata for an event-triggered automation. Parameterize `TEvent`
|
|
65
|
+
* with a webhook event name; {@link defineAutomation} then infers the handler's
|
|
66
|
+
* `trigger` and `input` from the metadata.
|
|
67
|
+
*/
|
|
68
|
+
type EventAutomationMetadata<TEvent extends WebhookEventName = WebhookEventName> = AutomationMetadataBase & {
|
|
69
|
+
trigger: EventTriggerConfig<TEvent>;
|
|
70
|
+
};
|
|
71
|
+
/** Authored metadata for a schedule-triggered automation. */
|
|
72
|
+
type ScheduleAutomationMetadata = AutomationMetadataBase & {
|
|
73
|
+
trigger: ScheduleTriggerConfig;
|
|
74
|
+
};
|
|
75
|
+
/** Authored metadata for an incoming-webhook automation. */
|
|
76
|
+
type IncomingWebhookAutomationMetadata = AutomationMetadataBase & {
|
|
77
|
+
trigger: IncomingWebhookTriggerConfig;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Authored metadata for an automation exposed as an AI tool to Scout.
|
|
81
|
+
*
|
|
82
|
+
* `description` is required (it drives tool selection by the LLM) and `inputSchema`
|
|
83
|
+
* declares the tool's argument contract. When `inputSchema` is a zod schema,
|
|
84
|
+
* {@link defineAutomation} infers the handler's `input` from it.
|
|
85
|
+
*/
|
|
86
|
+
type AiToolAutomationMetadata = AutomationMetadataBase & {
|
|
87
|
+
/** Required for AI tools — the LLM uses it to decide when to call the automation. */
|
|
88
|
+
description: string;
|
|
89
|
+
trigger: AiToolTriggerConfig;
|
|
90
|
+
/**
|
|
91
|
+
* Argument contract surfaced to the LLM. A zod schema or a JSON Schema object.
|
|
92
|
+
*/
|
|
93
|
+
inputSchema: AiToolInputSchema;
|
|
94
|
+
};
|
|
95
|
+
/** Authored metadata declared via {@link defineAutomation}. */
|
|
96
|
+
type AutomationMetadata = EventAutomationMetadata | ScheduleAutomationMetadata | IncomingWebhookAutomationMetadata | AiToolAutomationMetadata;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Per-run Uniform API connection parameters.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* import { CanvasClient } from '@uniformdev/canvas';
|
|
104
|
+
*
|
|
105
|
+
* if(!context.uniformCredentials) {
|
|
106
|
+
* throw new Error('The automation does not have credentials assigned.');
|
|
107
|
+
* }
|
|
108
|
+
*
|
|
109
|
+
* const canvas = new CanvasClient(context.uniformCredentials);
|
|
110
|
+
* await canvas.updateComposition({ ... });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
interface UniformConnectionParams {
|
|
114
|
+
/**
|
|
115
|
+
* Per-run bearer token for the connection's identity. Present for machine-identity
|
|
116
|
+
* runs (event/schedule/webhook) and for AI-tool runs where the invoking caller used
|
|
117
|
+
* a bearer token.
|
|
118
|
+
*/
|
|
119
|
+
bearerToken?: string;
|
|
120
|
+
/**
|
|
121
|
+
* Per-run API key for the connection's identity. Present for AI-tool runs where the
|
|
122
|
+
* invoking caller authenticated with an `x-api-key` rather than a bearer token.
|
|
123
|
+
*/
|
|
124
|
+
apiKey?: string;
|
|
125
|
+
/** The Uniform project the automation is deployed to. */
|
|
126
|
+
projectId: string;
|
|
127
|
+
/** Uniform API host (e.g. `https://uniform.app`). */
|
|
128
|
+
apiHost?: string;
|
|
129
|
+
/** Uniform edge API host (e.g. `https://uniform.global`). */
|
|
130
|
+
edgeApiHost?: string;
|
|
131
|
+
/** Uniform AI API host where Scout runs (e.g. `https://ai.uniform.global`). */
|
|
132
|
+
aiApiHost?: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Severity levels for structured automation logs. */
|
|
136
|
+
type AutomationLogLevel = 'info' | 'warning' | 'error';
|
|
137
|
+
/**
|
|
138
|
+
* Structured logger available to automation code; entries appear in the run log.
|
|
139
|
+
* Note: for AI tool triggers, the logger defines the context added to the calling LLM.
|
|
140
|
+
*/
|
|
141
|
+
interface AutomationLogger {
|
|
142
|
+
/** Records an informational log entry. */
|
|
143
|
+
info(message: string): void;
|
|
144
|
+
/** Records a warning log entry. */
|
|
145
|
+
warning(message: string): void;
|
|
146
|
+
/** Records an error log entry. */
|
|
147
|
+
error(message: string): void;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Authoring context passed to an automation handler.
|
|
151
|
+
*
|
|
152
|
+
* The shape is intentionally minimal (`{ trigger, input, log }`) and stable so
|
|
153
|
+
* future SDK versions can add capabilities without breaking already-authored
|
|
154
|
+
* functions — do not rely on the absence of other properties.
|
|
155
|
+
*
|
|
156
|
+
* @typeParam TInput - The run input type
|
|
157
|
+
* @typeParam TTrigger - The authored trigger configuration.
|
|
158
|
+
*/
|
|
159
|
+
interface AutomationContext<TInput = unknown, TTrigger extends TriggerConfig = TriggerConfig> {
|
|
160
|
+
/** The automation's trigger definition. */
|
|
161
|
+
trigger: TTrigger;
|
|
162
|
+
/** The input payload for this run (event payload, incoming webhook request, or none for schedule). */
|
|
163
|
+
input: TInput;
|
|
164
|
+
/** Structured logger; entries appear in the run log. */
|
|
165
|
+
log: AutomationLogger;
|
|
166
|
+
/**
|
|
167
|
+
* Per-run credentials for Uniform API clients. Present when the automation has an
|
|
168
|
+
* assigned role (event/schedule/webhook) or, for the `aiTool` trigger, carrying the
|
|
169
|
+
* invoking caller's own credential so the run acts as that user.
|
|
170
|
+
*/
|
|
171
|
+
uniformCredentials?: UniformConnectionParams;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Handler function passed to {@link defineAutomation}.
|
|
175
|
+
*
|
|
176
|
+
* Return an {@link AutomationResult} to record the run's outcome, or
|
|
177
|
+
* return void to signal implicit success. Unhandled exceptions signal implicit failure.
|
|
178
|
+
*
|
|
179
|
+
* @typeParam TInput - The input payload type.
|
|
180
|
+
* @typeParam TTrigger - The trigger configuration.
|
|
181
|
+
*/
|
|
182
|
+
type AutomationHandler<TInput = unknown, TTrigger extends TriggerConfig = TriggerConfig> = (context: AutomationContext<TInput, TTrigger>) => Promise<AutomationResult | void> | AutomationResult | void;
|
|
183
|
+
|
|
184
|
+
/** HTTP request details passed to an incoming-webhook automation handler. */
|
|
185
|
+
type IncomingWebhookInput = {
|
|
186
|
+
/** HTTP method of the incoming request (e.g. `POST`). */
|
|
187
|
+
method: string;
|
|
188
|
+
/** Normalized request headers (lower-cased keys). */
|
|
189
|
+
headers: Record<string, string>;
|
|
190
|
+
/** Parsed query-string parameters. */
|
|
191
|
+
query: Record<string, string>;
|
|
192
|
+
/** Raw request body as received (UTF-8 string). */
|
|
193
|
+
rawBody: string;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Payload Uniform passes when invoking a deployed automation's default export.
|
|
198
|
+
* {@link defineAutomation} wraps a handler to accept this shape.
|
|
199
|
+
*/
|
|
200
|
+
interface AutomationInvokePayload {
|
|
201
|
+
/** The automation's declared trigger configuration. */
|
|
202
|
+
trigger: TriggerConfig;
|
|
203
|
+
/** Input for this run. */
|
|
204
|
+
input: unknown;
|
|
205
|
+
/**
|
|
206
|
+
* Per-run Uniform API credentials. Present when the automation has an assigned role,
|
|
207
|
+
* or for the `aiTool` trigger (credentials of the caller).
|
|
208
|
+
*/
|
|
209
|
+
uniformCredentials?: UniformConnectionParams;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Callable shape of a default-exported automation module. Uniform invokes it with
|
|
214
|
+
* {@link AutomationInvokePayload}; use {@link defineAutomation} rather than
|
|
215
|
+
* implementing this directly.
|
|
216
|
+
*/
|
|
217
|
+
type AutomationInvoker = (payload: AutomationInvokePayload) => Promise<AutomationResult & {
|
|
218
|
+
logs: AutomationLogEntry[];
|
|
219
|
+
}>;
|
|
220
|
+
/**
|
|
221
|
+
* Resolves the handler input type from authored metadata: AI-tool arguments (from
|
|
222
|
+
* the declared `inputSchema`), event payload, incoming-webhook request details, or
|
|
223
|
+
* `unknown` for schedule triggers.
|
|
224
|
+
*/
|
|
225
|
+
type InputFromAutomationMetadata<M extends AutomationMetadata> = M extends {
|
|
226
|
+
trigger: {
|
|
227
|
+
type: 'aiTool';
|
|
228
|
+
};
|
|
229
|
+
inputSchema: infer S;
|
|
230
|
+
} ? S extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<S> : unknown : M extends {
|
|
231
|
+
trigger: infer TTrigger;
|
|
232
|
+
} ? TTrigger extends {
|
|
233
|
+
type: infer TType;
|
|
234
|
+
} ? TType extends WebhookEventName ? WebhookPayloadFor<TType> : TType extends 'incomingWebhook' ? IncomingWebhookInput : unknown : unknown : unknown;
|
|
235
|
+
/**
|
|
236
|
+
* Resolves the handler trigger type from authored metadata (the literal
|
|
237
|
+
* `metadata.trigger` object).
|
|
238
|
+
*/
|
|
239
|
+
type TriggerFromAutomationMetadata<M extends AutomationMetadata> = M extends {
|
|
240
|
+
trigger: infer TTrigger;
|
|
241
|
+
} ? TTrigger : TriggerConfig;
|
|
242
|
+
/** A fully defined automation module: a callable invoke function with authored metadata attached. */
|
|
243
|
+
type AutomationDefinition<M extends AutomationMetadata = AutomationMetadata> = AutomationInvoker & {
|
|
244
|
+
metadata: M;
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* Defines an automation from authored metadata and a handler. Default-export the
|
|
248
|
+
* return value from the module:
|
|
249
|
+
*
|
|
250
|
+
* ```ts
|
|
251
|
+
* import { defineAutomation } from '@uniformdev/automations-sdk';
|
|
252
|
+
*
|
|
253
|
+
* export default defineAutomation({
|
|
254
|
+
* metadata: {
|
|
255
|
+
* name: 'On entry save',
|
|
256
|
+
* trigger: { type: 'entry.changed' },
|
|
257
|
+
* },
|
|
258
|
+
* handler: async ({ trigger, input, log }) => {
|
|
259
|
+
* // trigger.type is 'entry.changed'; input is that event's payload
|
|
260
|
+
* },
|
|
261
|
+
* });
|
|
262
|
+
* ```
|
|
263
|
+
*
|
|
264
|
+
* @param config - Authored metadata and handler implementation.
|
|
265
|
+
* @returns A callable default export with a `metadata` property.
|
|
266
|
+
*/
|
|
267
|
+
declare function defineAutomation<const M extends AutomationMetadata>(config: {
|
|
268
|
+
metadata: M;
|
|
269
|
+
handler: AutomationHandler<InputFromAutomationMetadata<M>, TriggerFromAutomationMetadata<M>>;
|
|
270
|
+
}): AutomationDefinition<M>;
|
|
271
|
+
|
|
272
|
+
export { type AiToolAutomationMetadata, type AiToolInputSchema, type AiToolTriggerConfig, type AutomationContext, type AutomationDefinition, type AutomationHandler, type AutomationInvokePayload, type AutomationInvoker, AutomationLogEntry, type AutomationLogLevel, type AutomationLogger, type AutomationMetadata, type AutomationPermissions, AutomationResult, type EventAutomationMetadata, type EventTriggerConfig, type IncomingWebhookAutomationMetadata, type IncomingWebhookInput, type IncomingWebhookTriggerConfig, type InputFromAutomationMetadata, type JsonSchemaObject, type ScheduleAutomationMetadata, type ScheduleTriggerConfig, type TriggerConfig, type TriggerFromAutomationMetadata, type UniformConnectionParams, defineAutomation };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
formatAutomationWebhookUrl
|
|
3
|
+
} from "./chunk-TWKWPWN3.mjs";
|
|
4
|
+
import "./chunk-I6KKUHEY.mjs";
|
|
5
|
+
|
|
6
|
+
// src/runtime.ts
|
|
7
|
+
function captureLog(logs, level, message) {
|
|
8
|
+
logs.push({ level, message, createdAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
9
|
+
switch (level) {
|
|
10
|
+
case "info":
|
|
11
|
+
console.info(message);
|
|
12
|
+
break;
|
|
13
|
+
case "warning":
|
|
14
|
+
console.warn(message);
|
|
15
|
+
break;
|
|
16
|
+
case "error":
|
|
17
|
+
console.error(message);
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async function runAutomationHandler(handler, payload) {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
const logs = [];
|
|
24
|
+
const log = {
|
|
25
|
+
info: (message) => captureLog(logs, "info", message),
|
|
26
|
+
warning: (message) => captureLog(logs, "warning", message),
|
|
27
|
+
error: (message) => captureLog(logs, "error", message)
|
|
28
|
+
};
|
|
29
|
+
const context = {
|
|
30
|
+
trigger: payload.trigger,
|
|
31
|
+
input: payload.input,
|
|
32
|
+
log
|
|
33
|
+
};
|
|
34
|
+
if (payload.uniformCredentials) {
|
|
35
|
+
context.uniformCredentials = payload.uniformCredentials;
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const result = await handler(context);
|
|
39
|
+
return { outcome: (_a = result == null ? void 0 : result.outcome) != null ? _a : "success", logs };
|
|
40
|
+
} catch (e) {
|
|
41
|
+
const message = e instanceof Error ? (_b = e.stack) != null ? _b : e.message : String(e);
|
|
42
|
+
captureLog(logs, "error", message);
|
|
43
|
+
return { outcome: "failure", logs };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/defineAutomation.ts
|
|
48
|
+
function defineAutomation(config) {
|
|
49
|
+
const invoker = (payload) => runAutomationHandler(config.handler, payload);
|
|
50
|
+
return Object.assign(invoker, { metadata: config.metadata });
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
defineAutomation,
|
|
54
|
+
formatAutomationWebhookUrl
|
|
55
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Zod schema for a structured automation log entry. Import from
|
|
5
|
+
* `@uniformdev/automations-sdk/schemas` when validating run logs.
|
|
6
|
+
*/
|
|
7
|
+
declare const automationLogEntrySchema: z.ZodObject<{
|
|
8
|
+
level: z.ZodEnum<{
|
|
9
|
+
info: "info";
|
|
10
|
+
warning: "warning";
|
|
11
|
+
error: "error";
|
|
12
|
+
}>;
|
|
13
|
+
message: z.ZodString;
|
|
14
|
+
createdAt: z.ZodString;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
/**
|
|
17
|
+
* A single structured log entry captured during a run. Authored automation code
|
|
18
|
+
* produces these via the run `log`; they appear in the run log.
|
|
19
|
+
*/
|
|
20
|
+
type AutomationLogEntry = z.infer<typeof automationLogEntrySchema>;
|
|
21
|
+
/**
|
|
22
|
+
* Zod schema for an automation handler result. Import from
|
|
23
|
+
* `@uniformdev/automations-sdk/schemas` when validating handler outcomes.
|
|
24
|
+
*/
|
|
25
|
+
declare const automationResultSchema: z.ZodObject<{
|
|
26
|
+
outcome: z.ZodEnum<{
|
|
27
|
+
success: "success";
|
|
28
|
+
rejected: "rejected";
|
|
29
|
+
unauthorized: "unauthorized";
|
|
30
|
+
failure: "failure";
|
|
31
|
+
}>;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
/**
|
|
34
|
+
* The final result an automation handler returns — its `outcome`. This is a
|
|
35
|
+
* terminal value (not a mutable status), so returning one ends the run:
|
|
36
|
+
*
|
|
37
|
+
* - `success` — the run succeeded.
|
|
38
|
+
* - `rejected` — the automation deliberately declined to act on the input (eg not an event it need run for).
|
|
39
|
+
* - `unauthorized` — the automation's own logic determined the caller was not
|
|
40
|
+
* authorized to trigger this run (ex: incoming webhook validation failed).
|
|
41
|
+
* - `failure` — the run failed. Unhandled exceptions are also equivalent to this outcome.
|
|
42
|
+
*/
|
|
43
|
+
type AutomationResult = z.infer<typeof automationResultSchema>;
|
|
44
|
+
declare const automationInvokeResultSchema: z.ZodObject<{
|
|
45
|
+
outcome: z.ZodEnum<{
|
|
46
|
+
success: "success";
|
|
47
|
+
rejected: "rejected";
|
|
48
|
+
unauthorized: "unauthorized";
|
|
49
|
+
failure: "failure";
|
|
50
|
+
}>;
|
|
51
|
+
logs: z.ZodArray<z.ZodObject<{
|
|
52
|
+
level: z.ZodEnum<{
|
|
53
|
+
info: "info";
|
|
54
|
+
warning: "warning";
|
|
55
|
+
error: "error";
|
|
56
|
+
}>;
|
|
57
|
+
message: z.ZodString;
|
|
58
|
+
createdAt: z.ZodString;
|
|
59
|
+
}, z.core.$strip>>;
|
|
60
|
+
}, z.core.$strip>;
|
|
61
|
+
type AutomationInvokeResult = z.infer<typeof automationInvokeResultSchema>;
|
|
62
|
+
type AutomationRunOutcome = AutomationResult['outcome'] | 'timeout';
|
|
63
|
+
|
|
64
|
+
export { type AutomationInvokeResult, type AutomationLogEntry, type AutomationResult, type AutomationRunOutcome, automationInvokeResultSchema, automationLogEntrySchema, automationResultSchema };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import "../chunk-I6KKUHEY.mjs";
|
|
2
|
+
|
|
3
|
+
// src/schemas/index.ts
|
|
4
|
+
import * as z from "zod";
|
|
5
|
+
var automationLogEntrySchema = z.object({
|
|
6
|
+
level: z.enum(["info", "warning", "error"]),
|
|
7
|
+
message: z.string(),
|
|
8
|
+
/** ISO-8601 timestamp when this entry was logged. */
|
|
9
|
+
createdAt: z.string()
|
|
10
|
+
});
|
|
11
|
+
var automationResultSchema = z.object({
|
|
12
|
+
outcome: z.enum(["success", "rejected", "unauthorized", "failure"])
|
|
13
|
+
});
|
|
14
|
+
var automationInvokeResultSchema = automationResultSchema.extend({
|
|
15
|
+
logs: z.array(automationLogEntrySchema)
|
|
16
|
+
});
|
|
17
|
+
export {
|
|
18
|
+
automationInvokeResultSchema,
|
|
19
|
+
automationLogEntrySchema,
|
|
20
|
+
automationResultSchema
|
|
21
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@uniformdev/automations-sdk",
|
|
3
|
+
"version": "20.50.2-alpha.109+846837c66a",
|
|
4
|
+
"description": "Uniform Automations SDK",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.mts",
|
|
9
|
+
"import": "./dist/index.mjs"
|
|
10
|
+
},
|
|
11
|
+
"./api": {
|
|
12
|
+
"types": "./dist/api/index.d.mts",
|
|
13
|
+
"import": "./dist/api/index.mjs"
|
|
14
|
+
},
|
|
15
|
+
"./schemas": {
|
|
16
|
+
"types": "./dist/schemas/index.d.mts",
|
|
17
|
+
"import": "./dist/schemas/index.mjs"
|
|
18
|
+
},
|
|
19
|
+
"./ai": {
|
|
20
|
+
"types": "./dist/ai/index.d.mts",
|
|
21
|
+
"import": "./dist/ai/index.mjs"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"types": "./dist/index.d.mts",
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "run-s update-openapi build:ts",
|
|
28
|
+
"build:ts": "tsup",
|
|
29
|
+
"dev": "run-s update-openapi dev:ts",
|
|
30
|
+
"dev:ts": "tsup --watch",
|
|
31
|
+
"clean": "rimraf dist src/openapi-types",
|
|
32
|
+
"test": "vitest run",
|
|
33
|
+
"lint": "eslint \"src/**/*.{js,ts,tsx}\"",
|
|
34
|
+
"format": "prettier --write \"src/**/*.{js,ts,tsx}\"",
|
|
35
|
+
"update-openapi": "tsx ./scripts/update-openapi.cts",
|
|
36
|
+
"document:prebuild": "api-extractor run --local"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"/dist"
|
|
40
|
+
],
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@standard-schema/spec": "^1.1.0",
|
|
43
|
+
"@uniformdev/context": "20.50.2-alpha.109+846837c66a",
|
|
44
|
+
"@uniformdev/webhooks": "20.50.2-alpha.109+846837c66a"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"ai": "^6.0.0",
|
|
48
|
+
"zod": "^4.3.0"
|
|
49
|
+
},
|
|
50
|
+
"peerDependenciesMeta": {
|
|
51
|
+
"ai": {
|
|
52
|
+
"optional": true
|
|
53
|
+
},
|
|
54
|
+
"zod": {
|
|
55
|
+
"optional": true
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"ai": "6.0.168",
|
|
60
|
+
"zod": "4.3.6"
|
|
61
|
+
},
|
|
62
|
+
"publishConfig": {
|
|
63
|
+
"access": "public"
|
|
64
|
+
},
|
|
65
|
+
"gitHead": "846837c66ad0f518683c100615b59b27f91498ba"
|
|
66
|
+
}
|