🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@workflowai/workflowai

Package Overview
Dependencies
Maintainers
0
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@workflowai/workflowai - npm Package Compare versions

Comparing version

to
1.5.0-alpha1

dist/cjs/api/api.d.ts

5

dist/cjs/index.d.ts

@@ -1,3 +0,4 @@

export type { TaskInput, TaskOutput } from './Task.js';
export type { TaskInput, TaskOutput } from './task.js';
export * from './WorkflowAI.js';
export { z } from '@workflowai/schema';
export * as z from './schema/zod/zod.js';
export { WorkflowAIError } from './api/error.js';

19

dist/cjs/index.js

@@ -13,9 +13,22 @@ "use strict";

}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.z = void 0;
exports.WorkflowAIError = exports.z = void 0;
__exportStar(require("./WorkflowAI.js"), exports);
var schema_1 = require("@workflowai/schema");
Object.defineProperty(exports, "z", { enumerable: true, get: function () { return schema_1.z; } });
exports.z = __importStar(require("./schema/zod/zod.js"));
var error_js_1 = require("./api/error.js");
Object.defineProperty(exports, "WorkflowAIError", { enumerable: true, get: function () { return error_js_1.WorkflowAIError; } });

@@ -1,4 +0,4 @@

import { type FetchOptions, InitWorkflowAIApiConfig, Schemas, type WorkflowAIApi } from '@workflowai/api';
import { GroupReference } from './Group.js';
import type { InputSchema, OutputSchema, TaskDefinition, TaskRunResult, TaskRunStreamResult, UseTaskResult } from './Task.js';
import { InitWorkflowAIApiConfig, type WorkflowAIApi } from './api/api.js';
import { FetchOptions, RunRequest, VersionReference } from './api/types.js';
import type { InputSchema, OutputSchema, TaskDefinition, TaskRunResult, TaskRunStreamResult, UseTaskResult } from './task.js';
export type WorkflowAIConfig = {

@@ -8,53 +8,15 @@ api?: WorkflowAIApi | InitWorkflowAIApiConfig;

export type RunTaskOptions<Stream extends true | false = false> = {
group: GroupReference;
useCache?: Schemas['RunRequest']['use_cache'];
labels?: Schemas['RunRequest']['labels'];
metadata?: Schemas['RunRequest']['metadata'];
version: VersionReference;
useCache?: RunRequest['use_cache'];
metadata?: RunRequest['metadata'];
stream?: Stream;
fetch?: FetchOptions;
privateFields?: ('task_input' | 'task_output' | string)[];
};
export type ImportTaskRunOptions = Omit<Schemas['CreateTaskRunRequest'], 'task_input' | 'task_output' | 'group'> & {
group: GroupReference;
};
export declare class WorkflowAI {
protected api: WorkflowAIApi;
constructor(config?: WorkflowAIConfig);
protected upsertTask<IS extends InputSchema, OS extends OutputSchema>(taskDef: TaskDefinition<IS, OS>): Promise<TaskDefinition<IS, OS>>;
protected runTask<IS extends InputSchema, OS extends OutputSchema>(taskDef: TaskDefinition<IS, OS>, input: IS, options: RunTaskOptions<false>): Promise<TaskRunResult<OS>>;
protected runTask<IS extends InputSchema, OS extends OutputSchema>(taskDef: TaskDefinition<IS, OS>, input: IS, options: RunTaskOptions<true>): Promise<TaskRunStreamResult<OS>>;
protected importTaskRun<IS extends InputSchema, OS extends OutputSchema>(taskDef: TaskDefinition<IS, OS>, input: IS, output: OS, options: ImportTaskRunOptions): Promise<{
data: {
id: string;
task_id: string;
task_schema_id: number;
task_input: Record<string, never>;
task_input_hash: string;
task_input_preview?: string;
task_output: Record<string, never>;
task_output_hash: string;
task_output_preview?: string;
group: import("@workflowai/api/dist/types/generated/openapi.js").components["schemas"]["core__domain__tasks__task_group__TaskGroup"];
status?: "success" | "failure";
error?: import("@workflowai/api/dist/types/generated/openapi.js").components["schemas"]["core__domain__error_response__ErrorResponse__Error"] | null;
start_time?: string | null;
end_time?: string | null;
duration_seconds?: number | null;
cost_usd?: number | null;
created_at?: string;
updated_at?: string;
example_id?: string | null;
corrections?: Record<string, never> | null;
parent_task_ids?: string[] | null;
scores?: import("@workflowai/api/dist/types/generated/openapi.js").components["schemas"]["TaskEvaluation"][] | null;
labels?: string[] | null;
metadata?: Record<string, never> | null;
llm_completions?: import("@workflowai/api/dist/types/generated/openapi.js").components["schemas"]["LLMCompletion"][] | null;
config_id?: string | null;
dataset_benchmark_ids?: string[] | null;
is_free?: boolean | null;
author_tenant?: string | null;
};
response: Response;
}>;
useTask<IS extends InputSchema, OS extends OutputSchema>(taskDef: TaskDefinition<IS, OS>, defaultOptions?: Partial<RunTaskOptions>): UseTaskResult<IS, OS>;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WorkflowAI = void 0;
const api_1 = require("@workflowai/api");
const api_2 = require("@workflowai/api");
const schema_1 = require("@workflowai/schema");
const Group_js_1 = require("./Group.js");
const api_js_1 = require("./api/api.js");
const error_js_1 = require("./api/error.js");
const errorResponse_js_1 = require("./api/errorResponse.js");
const wrapAsyncIterator_js_1 = require("./api/utils/wrapAsyncIterator.js");
const zod_js_1 = require("./schema/zod/zod.js");
function optionsToRunRequest(input, options) {
const { version, stream, metadata, useCache, privateFields } = options;
return {
task_input: input,
version,
stream,
metadata,
use_cache: useCache || 'when_available',
private_fields: privateFields,
};
}
function paramsFromTaskDefinition(taskDef) {
return {
path: {
tenant: '_',
task_id: taskDef.taskId.toLowerCase(),
task_schema_id: taskDef.schema.id,
},
};
}
class WorkflowAI {

@@ -17,3 +38,3 @@ constructor(config) {

else {
this.api = (0, api_1.initWorkflowAIApi)({
this.api = (0, api_js_1.initWorkflowAIApi)({
...apiConfig,

@@ -23,113 +44,81 @@ });

}
// TODO: this is deprecated and no longer needed
async upsertTask(taskDef) {
const { data, error, response } = await this.api.tasks.upsert({
body: {
task_id: taskDef.taskId,
name: taskDef.taskId,
// @ts-expect-error The generated API types are messed up
input_schema: await (0, schema_1.inputZodToSchema)(taskDef.schema.input),
// @ts-expect-error The generated API types are messed up
output_schema: await (0, schema_1.outputZodToSchema)(taskDef.schema.output),
},
});
if (!data) {
throw new api_1.WorkflowAIApiRequestError(response, (0, api_2.extractError)(error));
}
return {
...taskDef,
taskId: data.task_id,
schema: {
...taskDef.schema,
id: data.task_schema_id,
},
};
}
async runTask(taskDef, input, { group, stream, labels, metadata, useCache, fetch }) {
async runTask(taskDef, input, options) {
// TODO: surround with try catch to print pretty error
const validatedInput = await taskDef.schema.input.parseAsync(input);
const body = optionsToRunRequest(validatedInput, options);
// Prepare a run call, but nothing is executed yet
const run = this.api.tasks.schemas.run({
params: {
path: {
task_id: taskDef.taskId.toLowerCase(),
task_schema_id: taskDef.schema.id,
},
},
body: {
task_input: await taskDef.schema.input.parseAsync(input),
group: (0, Group_js_1.sanitizeGroupReference)(group),
stream,
labels,
metadata,
use_cache: useCache || 'when_available',
},
...fetch,
params: paramsFromTaskDefinition(taskDef),
body,
...options.fetch,
});
if (stream) {
// Streaming response, we receive partial results
const { response, stream: rawStream } = await run.stream();
return {
response,
// Return an async iterator for easy consumption
stream: (0, api_1.wrapAsyncIterator)(rawStream,
// Transform the server-sent events data to the expected outputs
// conforming to the schema (as best as possible)
async ({ data }) => {
var _a;
// Allows us to make a deep partial version of the schema, whatever the schema looks like
const partialWrap = schema_1.z.object({ partial: taskDef.schema.output });
const [parsed, partialParsed] = await Promise.all([
// We do a `safeParse` to avoid throwing, since it's expected that during
// streaming of partial results we'll have data that does not conform to schema
data && taskDef.schema.output.safeParseAsync(data.task_output),
data &&
partialWrap.deepPartial().safeParseAsync({
partial: data.task_output,
}),
]);
return {
data,
output: parsed === null || parsed === void 0 ? void 0 : parsed.data,
partialOutput: (_a = partialParsed === null || partialParsed === void 0 ? void 0 : partialParsed.data) === null || _a === void 0 ? void 0 : _a.partial,
};
}),
};
}
else {
// Non-streaming version, await the run to actually send the request
if (!options.stream) {
const { data, error, response } = await run;
if (!data) {
throw new api_1.WorkflowAIApiRequestError(response, (0, api_2.extractError)(error));
throw new error_js_1.WorkflowAIError(response, (0, errorResponse_js_1.extractError)(error));
}
const output = await taskDef.schema.output.parseAsync(data.task_output);
return {
data: data,
response,
output,
};
return { data: data, response, output };
}
// Streaming response, we receive partial results
const { response, stream: rawStream } = await run.stream();
return {
response,
// Return an async iterator for easy consumption
stream: (0, wrapAsyncIterator_js_1.wrapAsyncIterator)(rawStream,
// Transform the server-sent events data to the expected outputs
// conforming to the schema (as best as possible)
async ({ data }) => {
var _a;
// Allows us to make a deep partial version of the schema, whatever the schema looks like
const partialWrap = zod_js_1.z.object({ partial: taskDef.schema.output });
const [parsed, partialParsed] = await Promise.all([
// We do a `safeParse` to avoid throwing, since it's expected that during
// streaming of partial results we'll have data that does not conform to schema
data && taskDef.schema.output.safeParseAsync(data.task_output),
data &&
partialWrap.deepPartial().safeParseAsync({
partial: data.task_output,
}),
]);
return {
data,
output: parsed === null || parsed === void 0 ? void 0 : parsed.data,
partialOutput: (_a = partialParsed === null || partialParsed === void 0 ? void 0 : partialParsed.data) === null || _a === void 0 ? void 0 : _a.partial,
};
}),
};
}
async importTaskRun(taskDef, input, output, options) {
const [task_input, task_output] = await Promise.all([
taskDef.schema.input.parseAsync(input),
taskDef.schema.output.parseAsync(output),
]);
const { data, response, error } = await this.api.tasks.schemas.runs.import({
params: {
path: {
task_id: taskDef.taskId.toLowerCase(),
task_schema_id: taskDef.schema.id,
},
},
body: {
...options,
group: (0, Group_js_1.sanitizeGroupReference)(options.group),
task_input,
task_output,
},
});
if (!data) {
throw new api_1.WorkflowAIApiRequestError(response, (0, api_2.extractError)(error));
}
return { data, response };
}
// protected async importTaskRun<
// IS extends InputSchema,
// OS extends OutputSchema,
// >(
// taskDef: TaskDefinition<IS, OS>,
// input: IS,
// output: OS,
// options: ImportTaskRunOptions
// ) {
// const [task_input, task_output] = await Promise.all([
// taskDef.schema.input.parseAsync(input),
// taskDef.schema.output.parseAsync(output),
// ]);
// const { data, response, error } = await this.api.tasks.schemas.runs.import({
// params: {
// path: {
// task_id: taskDef.taskId.toLowerCase(),
// task_schema_id: taskDef.schema.id,
// },
// },
// body: {
// ...options,
// group: sanitizeGroupReference(options.group),
// task_input,
// task_output,
// },
// });
// if (!data) {
// throw new WorkflowAIError(response, extractError(error));
// }
// return { data, response };
// }
useTask(taskDef, defaultOptions) {

@@ -172,15 +161,4 @@ // Make sure we have a schema ID and it's not 0

};
const importRun = async (input, output, overrideOptions) => {
const { group, ...options } = {
...defaultOptions,
...overrideOptions,
};
if (!(0, Group_js_1.isGroupReference)(group)) {
throw new Error('Group configuration is required to import a task run');
}
return this.importTaskRun(taskDef, input, output, { ...options, group });
};
return {
run,
importRun,
};

@@ -187,0 +165,0 @@ }

export * from './WorkflowAI.js';
export { z } from '@workflowai/schema';
export * as z from './schema/zod/zod.js';
export { WorkflowAIError } from './api/error.js';

@@ -1,5 +0,26 @@

import { WorkflowAIApiRequestError, initWorkflowAIApi, wrapAsyncIterator, } from '@workflowai/api';
import { extractError } from '@workflowai/api';
import { inputZodToSchema, outputZodToSchema, z } from '@workflowai/schema';
import { isGroupReference, sanitizeGroupReference, } from './Group.js';
import { initWorkflowAIApi, } from './api/api.js';
import { WorkflowAIError } from './api/error.js';
import { extractError } from './api/errorResponse.js';
import { wrapAsyncIterator } from './api/utils/wrapAsyncIterator.js';
import { z } from './schema/zod/zod.js';
function optionsToRunRequest(input, options) {
const { version, stream, metadata, useCache, privateFields } = options;
return {
task_input: input,
version,
stream,
metadata,
use_cache: useCache || 'when_available',
private_fields: privateFields,
};
}
function paramsFromTaskDefinition(taskDef) {
return {
path: {
tenant: '_',
task_id: taskDef.taskId.toLowerCase(),
task_schema_id: taskDef.schema.id,
},
};
}
export class WorkflowAI {

@@ -19,112 +40,80 @@ constructor(config) {

}
// TODO: this is deprecated and no longer needed
async upsertTask(taskDef) {
const { data, error, response } = await this.api.tasks.upsert({
body: {
task_id: taskDef.taskId,
name: taskDef.taskId,
// @ts-expect-error The generated API types are messed up
input_schema: await inputZodToSchema(taskDef.schema.input),
// @ts-expect-error The generated API types are messed up
output_schema: await outputZodToSchema(taskDef.schema.output),
},
});
if (!data) {
throw new WorkflowAIApiRequestError(response, extractError(error));
}
return {
...taskDef,
taskId: data.task_id,
schema: {
...taskDef.schema,
id: data.task_schema_id,
},
};
}
async runTask(taskDef, input, { group, stream, labels, metadata, useCache, fetch }) {
async runTask(taskDef, input, options) {
// TODO: surround with try catch to print pretty error
const validatedInput = await taskDef.schema.input.parseAsync(input);
const body = optionsToRunRequest(validatedInput, options);
// Prepare a run call, but nothing is executed yet
const run = this.api.tasks.schemas.run({
params: {
path: {
task_id: taskDef.taskId.toLowerCase(),
task_schema_id: taskDef.schema.id,
},
},
body: {
task_input: await taskDef.schema.input.parseAsync(input),
group: sanitizeGroupReference(group),
stream,
labels,
metadata,
use_cache: useCache || 'when_available',
},
...fetch,
params: paramsFromTaskDefinition(taskDef),
body,
...options.fetch,
});
if (stream) {
// Streaming response, we receive partial results
const { response, stream: rawStream } = await run.stream();
return {
response,
// Return an async iterator for easy consumption
stream: wrapAsyncIterator(rawStream,
// Transform the server-sent events data to the expected outputs
// conforming to the schema (as best as possible)
async ({ data }) => {
// Allows us to make a deep partial version of the schema, whatever the schema looks like
const partialWrap = z.object({ partial: taskDef.schema.output });
const [parsed, partialParsed] = await Promise.all([
// We do a `safeParse` to avoid throwing, since it's expected that during
// streaming of partial results we'll have data that does not conform to schema
data && taskDef.schema.output.safeParseAsync(data.task_output),
data &&
partialWrap.deepPartial().safeParseAsync({
partial: data.task_output,
}),
]);
return {
data,
output: parsed?.data,
partialOutput: partialParsed?.data?.partial,
};
}),
};
}
else {
// Non-streaming version, await the run to actually send the request
if (!options.stream) {
const { data, error, response } = await run;
if (!data) {
throw new WorkflowAIApiRequestError(response, extractError(error));
throw new WorkflowAIError(response, extractError(error));
}
const output = await taskDef.schema.output.parseAsync(data.task_output);
return {
data: data,
response,
output,
};
return { data: data, response, output };
}
// Streaming response, we receive partial results
const { response, stream: rawStream } = await run.stream();
return {
response,
// Return an async iterator for easy consumption
stream: wrapAsyncIterator(rawStream,
// Transform the server-sent events data to the expected outputs
// conforming to the schema (as best as possible)
async ({ data }) => {
// Allows us to make a deep partial version of the schema, whatever the schema looks like
const partialWrap = z.object({ partial: taskDef.schema.output });
const [parsed, partialParsed] = await Promise.all([
// We do a `safeParse` to avoid throwing, since it's expected that during
// streaming of partial results we'll have data that does not conform to schema
data && taskDef.schema.output.safeParseAsync(data.task_output),
data &&
partialWrap.deepPartial().safeParseAsync({
partial: data.task_output,
}),
]);
return {
data,
output: parsed?.data,
partialOutput: partialParsed?.data?.partial,
};
}),
};
}
async importTaskRun(taskDef, input, output, options) {
const [task_input, task_output] = await Promise.all([
taskDef.schema.input.parseAsync(input),
taskDef.schema.output.parseAsync(output),
]);
const { data, response, error } = await this.api.tasks.schemas.runs.import({
params: {
path: {
task_id: taskDef.taskId.toLowerCase(),
task_schema_id: taskDef.schema.id,
},
},
body: {
...options,
group: sanitizeGroupReference(options.group),
task_input,
task_output,
},
});
if (!data) {
throw new WorkflowAIApiRequestError(response, extractError(error));
}
return { data, response };
}
// protected async importTaskRun<
// IS extends InputSchema,
// OS extends OutputSchema,
// >(
// taskDef: TaskDefinition<IS, OS>,
// input: IS,
// output: OS,
// options: ImportTaskRunOptions
// ) {
// const [task_input, task_output] = await Promise.all([
// taskDef.schema.input.parseAsync(input),
// taskDef.schema.output.parseAsync(output),
// ]);
// const { data, response, error } = await this.api.tasks.schemas.runs.import({
// params: {
// path: {
// task_id: taskDef.taskId.toLowerCase(),
// task_schema_id: taskDef.schema.id,
// },
// },
// body: {
// ...options,
// group: sanitizeGroupReference(options.group),
// task_input,
// task_output,
// },
// });
// if (!data) {
// throw new WorkflowAIError(response, extractError(error));
// }
// return { data, response };
// }
useTask(taskDef, defaultOptions) {

@@ -167,17 +156,6 @@ // Make sure we have a schema ID and it's not 0

};
const importRun = async (input, output, overrideOptions) => {
const { group, ...options } = {
...defaultOptions,
...overrideOptions,
};
if (!isGroupReference(group)) {
throw new Error('Group configuration is required to import a task run');
}
return this.importTaskRun(taskDef, input, output, { ...options, group });
};
return {
run,
importRun,
};
}
}

@@ -1,4 +0,5 @@

export type { TaskInput, TaskOutput } from './Task.js';
export type { TaskInput, TaskOutput } from './task.js';
export * from './WorkflowAI.js';
export { z } from '@workflowai/schema';
export * as z from './schema/zod/zod.js';
export { WorkflowAIError } from './api/error.js';
//# sourceMappingURL=index.d.ts.map

@@ -1,4 +0,4 @@

import { type FetchOptions, InitWorkflowAIApiConfig, Schemas, type WorkflowAIApi } from '@workflowai/api';
import { GroupReference } from './Group.js';
import type { InputSchema, OutputSchema, TaskDefinition, TaskRunResult, TaskRunStreamResult, UseTaskResult } from './Task.js';
import { InitWorkflowAIApiConfig, type WorkflowAIApi } from './api/api.js';
import { FetchOptions, RunRequest, VersionReference } from './api/types.js';
import type { InputSchema, OutputSchema, TaskDefinition, TaskRunResult, TaskRunStreamResult, UseTaskResult } from './task.js';
export type WorkflowAIConfig = {

@@ -8,54 +8,16 @@ api?: WorkflowAIApi | InitWorkflowAIApiConfig;

export type RunTaskOptions<Stream extends true | false = false> = {
group: GroupReference;
useCache?: Schemas['RunRequest']['use_cache'];
labels?: Schemas['RunRequest']['labels'];
metadata?: Schemas['RunRequest']['metadata'];
version: VersionReference;
useCache?: RunRequest['use_cache'];
metadata?: RunRequest['metadata'];
stream?: Stream;
fetch?: FetchOptions;
privateFields?: ('task_input' | 'task_output' | string)[];
};
export type ImportTaskRunOptions = Omit<Schemas['CreateTaskRunRequest'], 'task_input' | 'task_output' | 'group'> & {
group: GroupReference;
};
export declare class WorkflowAI {
protected api: WorkflowAIApi;
constructor(config?: WorkflowAIConfig);
protected upsertTask<IS extends InputSchema, OS extends OutputSchema>(taskDef: TaskDefinition<IS, OS>): Promise<TaskDefinition<IS, OS>>;
protected runTask<IS extends InputSchema, OS extends OutputSchema>(taskDef: TaskDefinition<IS, OS>, input: IS, options: RunTaskOptions<false>): Promise<TaskRunResult<OS>>;
protected runTask<IS extends InputSchema, OS extends OutputSchema>(taskDef: TaskDefinition<IS, OS>, input: IS, options: RunTaskOptions<true>): Promise<TaskRunStreamResult<OS>>;
protected importTaskRun<IS extends InputSchema, OS extends OutputSchema>(taskDef: TaskDefinition<IS, OS>, input: IS, output: OS, options: ImportTaskRunOptions): Promise<{
data: {
id: string;
task_id: string;
task_schema_id: number;
task_input: Record<string, never>;
task_input_hash: string;
task_input_preview?: string;
task_output: Record<string, never>;
task_output_hash: string;
task_output_preview?: string;
group: import("@workflowai/api/dist/types/generated/openapi.js").components["schemas"]["core__domain__tasks__task_group__TaskGroup"];
status?: "success" | "failure";
error?: import("@workflowai/api/dist/types/generated/openapi.js").components["schemas"]["core__domain__error_response__ErrorResponse__Error"] | null;
start_time?: string | null;
end_time?: string | null;
duration_seconds?: number | null;
cost_usd?: number | null;
created_at?: string;
updated_at?: string;
example_id?: string | null;
corrections?: Record<string, never> | null;
parent_task_ids?: string[] | null;
scores?: import("@workflowai/api/dist/types/generated/openapi.js").components["schemas"]["TaskEvaluation"][] | null;
labels?: string[] | null;
metadata?: Record<string, never> | null;
llm_completions?: import("@workflowai/api/dist/types/generated/openapi.js").components["schemas"]["LLMCompletion"][] | null;
config_id?: string | null;
dataset_benchmark_ids?: string[] | null;
is_free?: boolean | null;
author_tenant?: string | null;
};
response: Response;
}>;
useTask<IS extends InputSchema, OS extends OutputSchema>(taskDef: TaskDefinition<IS, OS>, defaultOptions?: Partial<RunTaskOptions>): UseTaskResult<IS, OS>;
}
//# sourceMappingURL=WorkflowAI.d.ts.map
{
"name": "@workflowai/workflowai",
"version": "1.4.3",
"description": "workflowAI client",
"author": "workflowAI",
"homepage": "https://workflowai.ai",
"version": "1.5.0-alpha1",
"description": "WorkflowAI TS SDK",
"author": "WorkflowAI",
"homepage": "https://workflowai.com",
"keywords": [

@@ -28,3 +28,42 @@ "workflowai",

},
"dependencies": {
"fetch-event-stream": "^0.1.5",
"fetch-retry": "^6.0.0",
"openapi-fetch": "^0.9.8",
"zod": "^3.23.8",
"zod-to-json-schema": "^3.23.1"
},
"devDependencies": {
"@actions/core": "^1.10.1",
"@jest/globals": "^29.4.3",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/jest": "^29.2.2",
"@types/json-schema": "^7.0.15",
"@types/minimist": "^1.2.5",
"@types/node": "^18",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-require-extensions": "^0.1.3",
"eslint-plugin-unused-imports": "^3.2.0",
"husky": "^9.1.6",
"jest": "^29.3.1",
"jest-fetch-mock": "^3.0.3",
"lint-staged": "^15.2.10",
"minimist": "^1.2.8",
"nodemon": "^3.1.4",
"openapi-typescript": "^6.7.6",
"prettier": "^3.3.2",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"ts-xor": "^1.3.0",
"tsx": "^4.1.2",
"typescript": "^5.5.2"
},
"scripts": {
"-------- CODEGEN": "",
"codegen:openapi": "openapi-typescript ${WORKFLOWAI_API_URL:-https://run.workflowai.dev}/openapi.json -o ./src/api/generated/openapi.ts",
"codegen": "npm run codegen:openapi && npm run fix",
"-------- LINTING": "",

@@ -37,17 +76,22 @@ "prettier:check": "prettier --check src/**/*.ts src/*.ts src/**/*.js src/*.js *.md --no-error-on-unmatched-pattern",

"fix": "npm run lint:fix && npm run prettier:fix",
"test": "jest",
"lint-staged": "lint-staged",
"-------- BUILD": "",
"clean": "rm -rf dist/*",
"build:types": "tsc -p ./configs/tsconfig.types.json",
"build:cjs": "tsc -p ./configs/tsconfig.cjs.json && tsx ../../configs/postcjs.ts",
"build:esm": "tsc -p ./configs/tsconfig.esm.json && tsx ../../configs/postesm.ts",
"build:cjs": "tsc -p ./configs/tsconfig.cjs.json && tsx ./configs/postcjs.ts",
"build:esm": "tsc -p ./configs/tsconfig.esm.json && tsx ./configs/postesm.ts",
"build:test": "tsc -p ./configs/tsconfig.test.json",
"build": "npm run clean && npm run build:types && npm run build:cjs && npm run build:esm",
"dry": "npm run build && npm pub --dry-run",
"prepublishOnly--DISABLED": "npm run test && npm run build",
"prepublishOnly": "npm run build"
},
"dependencies": {
"@workflowai/api": "1.4.3",
"@workflowai/schema": "1.4.3"
"lint-staged": {
"**/*.{js,jsx,ts,tsx}": [
"eslint"
],
"**/*.{json,md,yml,yaml,css,scss,html,js,jsx,ts,tsx}": [
"prettier --check"
]
}
}

@@ -1,86 +0,12 @@

# workflowAI client
# WorkflowAI TS/JS libraries
## Install workflowAI
This repo hosts the different TS/JS libraries for workflowAI.
```
npm install --save @workflowai/workflowai
```
## Usage
## Initialize client
### Deployment
```ts
import { WorkflowAI } from '@workflowai/workflowai';
const workflowAI = new WorkflowAI({
apiKey: '...', // optional, defaults to process.env.WORKFLOWAI_API_KEY
});
```sh
# Setting a version
npm run set-version 1.4.0-alpha.0
```
## Compile your task
```ts
import { z } from '@workflowai/workflowai';
const checkTextFollowInstructions = await workflowAI.compileTask(
{
taskId: 'CheckTextFollowInstructions',
schema: {
id: 5,
input: z.object({
text: z
.string()
.describe(
'The text to check if it follows the instructions in "instructions"'
),
instructions: z
.string()
.describe('The instructions to check if the text follows'),
}),
output: z.object({
isFollowingInstructions: z
.bool()
.describe('Whether the "text" follows all the instructions or not'),
reason: z
.string()
.describe('The reason why the text follows or not the instructions'),
}),
},
},
{
// Default run configuration is optional if passed when runs are created
group: {
id: '...', // Find group IDs in the playground
},
}
);
```
## Prepare your task input
Use the `TaskInput` TypeScript helper to infer the type of a task input.
Another helper, `TaskOutput`, can infer the type of what you can expect as result of a task run.
```ts
import { TaskInput } from '@workflowai/workflowai';
const input: TaskInput<typeof checkTextFollowInstructions> = {
text: 'The capital of France is Barcelona',
instructions: 'The text must be written in English',
};
```
## Run your task
```ts
const output = await checkTextFollowInstructions(input, {
// Run configuration is optional if defaults were given at task compilation
group: {
id: '2',
},
});
// `output` is of type `TaskOutput<typeof checkTextFollowInstructions>`
console.log(output.isFollowingInstructions); // Boolean, true
console.log(output.reason); // String, "The text is written in English"
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet