@ztimson/momentum
Version:
Client library for momentum
110 lines • 3.29 kB
TypeScript
import { HttpRequestOptions } from '@ztimson/utils';
import { AssetController } from './asset-controller';
import { Meta } from './core';
import { Momentum } from './momentum';
export type ToolArgs = {
[key: string]: {
/** Argument type */
type: 'array' | 'boolean' | 'number' | 'object' | 'string';
/** Argument description */
description: string;
/** Required argument */
required?: boolean;
/** Default value */
default?: any;
/** Options */
enum?: string[];
/** Minimum value or length */
min?: number;
/** Maximum value or length */
max?: number;
/** Match pattern */
pattern?: string;
/** Child arguments */
items?: {
[key: string]: ToolArgs;
};
};
};
/** Action model */
export type Action = Meta & {
/** Action name */
name: string;
/** Disable action */
disabled?: boolean;
/** Trigger with AI call, CRON, CRUD or Event */
trigger: {
type: ActionType;
value: string | ToolArgs;
};
/** Run as system or with triggering user permissions */
system?: boolean | null;
/** Action code */
fn: string;
/** User nodes */
notes?: string | null;
/** Last execution timestamp */
readonly lastRun?: null | Date;
/** Last execution duration */
readonly lastRunDuration?: number | null;
/** Next scheduled run time (CRON only) */
readonly nextRun?: null | Date;
/** Last execution results */
readonly response?: ActionResult | null;
};
/** Action execution result */
export type ActionResult = {
/** ID of associated action */
readonly action: string;
/** Runtime */
readonly duration: number;
/** Start timestamp */
readonly start: Date;
/** Console output */
readonly stdout: any[];
/** Console errors */
readonly stderr: any[];
/** HTTP Response */
readonly response?: any;
/** Action return value */
readonly return?: any;
};
/** Action triggers - Ordered to optimize filtering */
export declare enum ActionType {
/** HTTP DELETE request */
'DELETE' = 0,
/** HTTP POST request */
'POST' = 1,
/** HTTP PATCH request */
'PATCH' = 2,
/** HTTP PUT request */
'PUT' = 3,
/** HTTP GET request */
'GET' = 4,
/** Internal Event */
'EVENT' = 6,
/** CRON Job */
'CRON' = 5,
/** AI tool call */
'AI' = 7
}
/** Run cloud functions & custom code */
export declare class Actions extends AssetController<Action> {
protected momentum: Momentum;
constructor(momentum: Momentum);
/**
* Manually trigger an actions execution
* @param {string} id Action ID
* @param {HttpRequestOptions} opts Additional arguments
* @return {Promise<ActionResult>} All action output including console logs & return
*/
debug(id: string, opts?: HttpRequestOptions): Promise<ActionResult>;
/**
* Run an HTTP action
* @param {string} path HTTP path excluding `/api/actions/run`
* @param {HttpRequestOptions} opts HTTP options
* @return {Promise<T>} HTTP response
*/
run<T>(path: string, opts?: HttpRequestOptions): Promise<T>;
}
//# sourceMappingURL=actions.d.ts.map