📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP →

@workflowai/workflowai

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.6.0

@@ -18,15 +18,4 @@ "use strict";

exports.customHeaders = void 0;
const fs_1 = require("fs");
const version_js_1 = require("../../version.js");
__exportStar(require("./throwError.js"), exports);
function getPackageVersion() {
try {
const packageJson = JSON.parse((0, fs_1.readFileSync)('package.json', 'utf8'));
return packageJson === null || packageJson === void 0 ? void 0 : packageJson.version;
}
catch (error) {
console.error('Error reading package.json:', error);
return undefined;
}
}
const packageVersion = getPackageVersion();
const customHeaders = {

@@ -36,3 +25,3 @@ onRequest: (req) => {

req.headers.set('x-workflowai-language', 'typescript');
req.headers.set('x-workflowai-version', packageVersion);
req.headers.set('x-workflowai-version', version_js_1.PACKAGE_VERSION);
return req;

@@ -39,0 +28,0 @@ },

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

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

@@ -13,22 +13,9 @@ "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.WorkflowAIError = exports.z = void 0;
exports.WorkflowAIError = void 0;
__exportStar(require("./WorkflowAI.js"), exports);
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; } });
import type { RunTaskOptions } from './WorkflowAI.js';
import type { WorkflowAIApi } from './api/api.js';
import type { RunResponse } from './api/types.js';
import type { z } from './schema/zod/zod.js';
import type { AsyncIteratorValue, DeepPartial } from './utils.js';
type TaskId = string;
export type InputSchema = z.ZodTypeAny;
export type OutputSchema = z.ZodTypeAny;
type TaskSchema<IS extends InputSchema, OS extends OutputSchema> = {
input: IS;
output: OS;
id: number;
};
export type TaskDefinition<IS extends InputSchema, OS extends OutputSchema> = {
type SchemaId = number;
export type InputSchema = Record<string, unknown>;
export type OutputSchema = Record<string, unknown>;
export type TaskInput = object;
export type TaskOutput = object;
export type TaskDefinition = {
taskId: TaskId;
schema: TaskSchema<IS, OS>;
schemaId: SchemaId;
};
export type TaskRunResult<OS extends OutputSchema> = {
export type TaskRunResult<O extends TaskOutput> = {
data: RunResponse;
response: Response;
output: TaskOutput<OS>;
output: O;
};
type RawTaskRunStreamResult = Awaited<ReturnType<Awaited<ReturnType<WorkflowAIApi['tasks']['schemas']['run']>['stream']>>>;
export type TaskRunStreamEvent<OS extends OutputSchema> = AsyncIteratorValue<RawTaskRunStreamResult['stream']> & {
output: TaskOutput<OS> | undefined;
partialOutput: DeepPartial<TaskOutput<OS>> | undefined;
export type TaskRunStreamEvent<O extends TaskOutput> = AsyncIteratorValue<RawTaskRunStreamResult['stream']> & {
output: DeepPartial<O> | undefined;
};
export type TaskRunStreamResult<OS extends OutputSchema> = Pick<RawTaskRunStreamResult, 'response'> & {
stream: AsyncIterableIterator<TaskRunStreamEvent<OS>>;
export type TaskRunStreamResult<O extends TaskOutput> = Pick<RawTaskRunStreamResult, 'response'> & {
stream: AsyncIterableIterator<TaskRunStreamEvent<O>>;
};
export type RunFn<IS extends InputSchema, OS extends OutputSchema, Stream extends true | false = false> = (input: TaskInput<IS>, options?: Partial<RunTaskOptions<Stream>>) => Promise<TaskRunResult<OS>> & {
stream: () => Promise<TaskRunStreamResult<OS>>;
export type RunFn<I extends TaskInput, O extends TaskOutput, Stream extends true | false = false> = (input: I, options?: Partial<RunTaskOptions<Stream>>) => Promise<TaskRunResult<O>> & {
stream: () => Promise<TaskRunStreamResult<O>>;
};
export type UseTaskResult<IS extends InputSchema, OS extends OutputSchema, Stream extends true | false = false> = {
run: RunFn<IS, OS, Stream>;
export type UseTaskResult<I extends TaskInput, O extends TaskOutput, Stream extends true | false = false> = {
run: RunFn<I, O, Stream>;
};
export type TaskInput<T> = T extends InputSchema ? z.input<T> : T extends TaskDefinition<infer IS, infer _OS> ? TaskInput<IS> : T extends UseTaskResult<infer IS, infer _OS> ? TaskInput<IS> : T extends RunFn<infer IS, infer _OS> ? TaskInput<IS> : T extends UseTaskResult<infer IS, infer _OS>['run'] ? TaskInput<IS> : never;
export type TaskOutput<T> = T extends OutputSchema ? z.output<T> : T extends TaskDefinition<infer _IS, infer OS> ? TaskOutput<OS> : T extends UseTaskResult<infer _IS, infer OS> ? TaskOutput<OS> : T extends RunFn<infer _IS, infer OS> ? TaskOutput<OS> : T extends UseTaskResult<infer _IS, infer OS>['run'] ? TaskOutput<OS> : never;
export {};
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 = {
api?: WorkflowAIApi | InitWorkflowAIApiConfig;
};
import type { TaskDefinition, TaskInput, TaskOutput, TaskRunResult, TaskRunStreamResult, UseTaskResult } from './task.js';
export type WorkflowAIConfig = InitWorkflowAIApiConfig;
export type RunTaskOptions<Stream extends true | false = false> = {

@@ -17,6 +15,6 @@ version: VersionReference;

protected api: WorkflowAIApi;
constructor(config?: WorkflowAIConfig);
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>>;
useTask<IS extends InputSchema, OS extends OutputSchema>(taskDef: TaskDefinition<IS, OS>, defaultOptions?: Partial<RunTaskOptions>): UseTaskResult<IS, OS>;
constructor(apiConfig?: WorkflowAIConfig);
protected runTask<I extends TaskInput, O extends TaskOutput>(taskDef: TaskDefinition, input: I, options: RunTaskOptions<false>): Promise<TaskRunResult<O>>;
protected runTask<I extends TaskInput, O extends TaskOutput>(taskDef: TaskDefinition, input: I, options: RunTaskOptions<true>): Promise<TaskRunStreamResult<O>>;
useTask<I extends TaskInput, O extends TaskOutput>(taskDef: TaskDefinition & Partial<RunTaskOptions>): UseTaskResult<I, O>;
}

@@ -8,3 +8,2 @@ "use strict";

const wrapAsyncIterator_js_1 = require("./api/utils/wrapAsyncIterator.js");
const zod_js_1 = require("./schema/zod/zod.js");
function optionsToRunRequest(input, options) {

@@ -26,3 +25,3 @@ const { version, stream, metadata, useCache, privateFields } = options;

task_id: taskDef.taskId.toLowerCase(),
task_schema_id: taskDef.schema.id,
task_schema_id: taskDef.schemaId,
},

@@ -32,19 +31,9 @@ };

class WorkflowAI {
constructor(config) {
const { api: apiConfig } = {
...config,
};
if (apiConfig && 'tasks' in apiConfig) {
this.api = apiConfig;
}
else {
this.api = (0, api_js_1.initWorkflowAIApi)({
...apiConfig,
});
}
constructor(apiConfig) {
this.api = (0, api_js_1.initWorkflowAIApi)({
...apiConfig,
});
}
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);
const body = optionsToRunRequest(input, options);
// Prepare a run call, but nothing is executed yet

@@ -61,3 +50,3 @@ const run = this.api.tasks.schemas.run({

}
const output = await taskDef.schema.output.parseAsync(data.task_output);
const output = data.task_output;
return { data: data, response, output };

@@ -74,18 +63,5 @@ }

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,
output: data === null || data === void 0 ? void 0 : data.task_output,
};

@@ -127,7 +103,8 @@ }),

// }
useTask(taskDef, defaultOptions) {
useTask(taskDef) {
// Make sure we have a schema ID and it's not 0
if (!taskDef.schema.id) {
if (!taskDef.schemaId) {
throw new Error('Invalid task definition to compile: missing task schema id or task name');
}
const { taskId, schemaId, ...defaultOptions } = taskDef;
const run = (input, overrideOptions) => {

@@ -134,0 +111,0 @@ const options = {

@@ -1,14 +0,3 @@

import { readFileSync } from 'fs';
import { PACKAGE_VERSION } from '../../version.js';
export * from './throwError.js';
function getPackageVersion() {
try {
const packageJson = JSON.parse(readFileSync('package.json', 'utf8'));
return packageJson?.version;
}
catch (error) {
console.error('Error reading package.json:', error);
return undefined;
}
}
const packageVersion = getPackageVersion();
const customHeaders = {

@@ -18,3 +7,3 @@ onRequest: (req) => {

req.headers.set('x-workflowai-language', 'typescript');
req.headers.set('x-workflowai-version', packageVersion);
req.headers.set('x-workflowai-version', PACKAGE_VERSION);
return req;

@@ -21,0 +10,0 @@ },

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

@@ -5,3 +5,2 @@ import { initWorkflowAIApi, } from './api/api.js';

import { wrapAsyncIterator } from './api/utils/wrapAsyncIterator.js';
import { z } from './schema/zod/zod.js';
function optionsToRunRequest(input, options) {

@@ -23,3 +22,3 @@ const { version, stream, metadata, useCache, privateFields } = options;

task_id: taskDef.taskId.toLowerCase(),
task_schema_id: taskDef.schema.id,
task_schema_id: taskDef.schemaId,
},

@@ -29,19 +28,9 @@ };

export class WorkflowAI {
constructor(config) {
const { api: apiConfig } = {
...config,
};
if (apiConfig && 'tasks' in apiConfig) {
this.api = apiConfig;
}
else {
this.api = initWorkflowAIApi({
...apiConfig,
});
}
constructor(apiConfig) {
this.api = initWorkflowAIApi({
...apiConfig,
});
}
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);
const body = optionsToRunRequest(input, options);
// Prepare a run call, but nothing is executed yet

@@ -58,3 +47,3 @@ const run = this.api.tasks.schemas.run({

}
const output = await taskDef.schema.output.parseAsync(data.task_output);
const output = data.task_output;
return { data: data, response, output };

@@ -71,17 +60,5 @@ }

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,
output: data?.task_output,
};

@@ -123,7 +100,8 @@ }),

// }
useTask(taskDef, defaultOptions) {
useTask(taskDef) {
// Make sure we have a schema ID and it's not 0
if (!taskDef.schema.id) {
if (!taskDef.schemaId) {
throw new Error('Invalid task definition to compile: missing task schema id or task name');
}
const { taskId, schemaId, ...defaultOptions } = taskDef;
const run = (input, overrideOptions) => {

@@ -130,0 +108,0 @@ const options = {

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

export * from './WorkflowAI.js';
export type * from './types.js';
export type { TaskInput, TaskOutput } from './task.js';
export * from './WorkflowAI.js';
export * as z from './schema/zod/zod.js';
export { WorkflowAIError } from './api/error.js';
//# sourceMappingURL=index.d.ts.map
import type { RunTaskOptions } from './WorkflowAI.js';
import type { WorkflowAIApi } from './api/api.js';
import type { RunResponse } from './api/types.js';
import type { z } from './schema/zod/zod.js';
import type { AsyncIteratorValue, DeepPartial } from './utils.js';
type TaskId = string;
export type InputSchema = z.ZodTypeAny;
export type OutputSchema = z.ZodTypeAny;
type TaskSchema<IS extends InputSchema, OS extends OutputSchema> = {
input: IS;
output: OS;
id: number;
};
export type TaskDefinition<IS extends InputSchema, OS extends OutputSchema> = {
type SchemaId = number;
export type InputSchema = Record<string, unknown>;
export type OutputSchema = Record<string, unknown>;
export type TaskInput = object;
export type TaskOutput = object;
export type TaskDefinition = {
taskId: TaskId;
schema: TaskSchema<IS, OS>;
schemaId: SchemaId;
};
export type TaskRunResult<OS extends OutputSchema> = {
export type TaskRunResult<O extends TaskOutput> = {
data: RunResponse;
response: Response;
output: TaskOutput<OS>;
output: O;
};
type RawTaskRunStreamResult = Awaited<ReturnType<Awaited<ReturnType<WorkflowAIApi['tasks']['schemas']['run']>['stream']>>>;
export type TaskRunStreamEvent<OS extends OutputSchema> = AsyncIteratorValue<RawTaskRunStreamResult['stream']> & {
output: TaskOutput<OS> | undefined;
partialOutput: DeepPartial<TaskOutput<OS>> | undefined;
export type TaskRunStreamEvent<O extends TaskOutput> = AsyncIteratorValue<RawTaskRunStreamResult['stream']> & {
output: DeepPartial<O> | undefined;
};
export type TaskRunStreamResult<OS extends OutputSchema> = Pick<RawTaskRunStreamResult, 'response'> & {
stream: AsyncIterableIterator<TaskRunStreamEvent<OS>>;
export type TaskRunStreamResult<O extends TaskOutput> = Pick<RawTaskRunStreamResult, 'response'> & {
stream: AsyncIterableIterator<TaskRunStreamEvent<O>>;
};
export type RunFn<IS extends InputSchema, OS extends OutputSchema, Stream extends true | false = false> = (input: TaskInput<IS>, options?: Partial<RunTaskOptions<Stream>>) => Promise<TaskRunResult<OS>> & {
stream: () => Promise<TaskRunStreamResult<OS>>;
export type RunFn<I extends TaskInput, O extends TaskOutput, Stream extends true | false = false> = (input: I, options?: Partial<RunTaskOptions<Stream>>) => Promise<TaskRunResult<O>> & {
stream: () => Promise<TaskRunStreamResult<O>>;
};
export type UseTaskResult<IS extends InputSchema, OS extends OutputSchema, Stream extends true | false = false> = {
run: RunFn<IS, OS, Stream>;
export type UseTaskResult<I extends TaskInput, O extends TaskOutput, Stream extends true | false = false> = {
run: RunFn<I, O, Stream>;
};
export type TaskInput<T> = T extends InputSchema ? z.input<T> : T extends TaskDefinition<infer IS, infer _OS> ? TaskInput<IS> : T extends UseTaskResult<infer IS, infer _OS> ? TaskInput<IS> : T extends RunFn<infer IS, infer _OS> ? TaskInput<IS> : T extends UseTaskResult<infer IS, infer _OS>['run'] ? TaskInput<IS> : never;
export type TaskOutput<T> = T extends OutputSchema ? z.output<T> : T extends TaskDefinition<infer _IS, infer OS> ? TaskOutput<OS> : T extends UseTaskResult<infer _IS, infer OS> ? TaskOutput<OS> : T extends RunFn<infer _IS, infer OS> ? TaskOutput<OS> : T extends UseTaskResult<infer _IS, infer OS>['run'] ? TaskOutput<OS> : never;
export {};
//# sourceMappingURL=task.d.ts.map
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 = {
api?: WorkflowAIApi | InitWorkflowAIApiConfig;
};
import type { TaskDefinition, TaskInput, TaskOutput, TaskRunResult, TaskRunStreamResult, UseTaskResult } from './task.js';
export type WorkflowAIConfig = InitWorkflowAIApiConfig;
export type RunTaskOptions<Stream extends true | false = false> = {

@@ -17,7 +15,7 @@ version: VersionReference;

protected api: WorkflowAIApi;
constructor(config?: WorkflowAIConfig);
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>>;
useTask<IS extends InputSchema, OS extends OutputSchema>(taskDef: TaskDefinition<IS, OS>, defaultOptions?: Partial<RunTaskOptions>): UseTaskResult<IS, OS>;
constructor(apiConfig?: WorkflowAIConfig);
protected runTask<I extends TaskInput, O extends TaskOutput>(taskDef: TaskDefinition, input: I, options: RunTaskOptions<false>): Promise<TaskRunResult<O>>;
protected runTask<I extends TaskInput, O extends TaskOutput>(taskDef: TaskDefinition, input: I, options: RunTaskOptions<true>): Promise<TaskRunStreamResult<O>>;
useTask<I extends TaskInput, O extends TaskOutput>(taskDef: TaskDefinition & Partial<RunTaskOptions>): UseTaskResult<I, O>;
}
//# sourceMappingURL=WorkflowAI.d.ts.map
{
"name": "@workflowai/workflowai",
"version": "1.5.0",
"version": "1.6.0",
"description": "WorkflowAI TS SDK",

@@ -31,7 +31,6 @@ "author": "WorkflowAI",

"fetch-retry": "^6.0.0",
"openapi-fetch": "^0.9.8",
"zod": "^3.23.8",
"zod-to-json-schema": "^3.23.1"
"openapi-fetch": "^0.9.8"
},
"devDependencies": {
"zod": "^3.23.8",
"@actions/core": "^1.10.1",

@@ -84,2 +83,3 @@ "@jest/globals": "^29.4.3",

"clean": "rm -rf dist/*",
"prebuild": "tsx ./configs/prebuild.ts",
"build:types": "tsc -p ./configs/tsconfig.types.json",

@@ -89,3 +89,3 @@ "build:cjs": "tsc -p ./configs/tsconfig.cjs.json && tsx ./configs/postcjs.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",
"build": "npm run clean && npm run prebuild && npm run build:types && npm run build:cjs && npm run build:esm",
"dry": "npm run build && npm pub --dry-run",

@@ -92,0 +92,0 @@ "prepublishOnly": "npm run build"

@@ -1,12 +0,5 @@

# WorkflowAI TS/JS libraries
# WorkflowAI
This repo hosts the different TS/JS libraries for workflowAI.
## Usage
### Deployment
```sh
# Setting a version
npm run set-version 1.4.0-alpha.0
```
Create a task on workflowai.com then visit the code page to get the code to use in your project.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet