2023-05-26 19:06:39 +00:00
|
|
|
import { ZodRawShape, ZodTypeAny, z } from 'zod'
|
|
|
|
|
|
|
|
import * as types from './types'
|
|
|
|
|
2023-05-27 00:36:52 +00:00
|
|
|
/**
|
|
|
|
* A `Task` is a typed, async function call that may be non-deterministic.
|
|
|
|
*
|
|
|
|
* Examples of tasks include:
|
|
|
|
* - LLM calls with structured input and output
|
|
|
|
* - API calls
|
2023-06-01 06:03:27 +00:00
|
|
|
* - Native function calls
|
2023-05-27 00:36:52 +00:00
|
|
|
* - Invoking sub-agents
|
|
|
|
*/
|
2023-05-26 19:06:39 +00:00
|
|
|
export abstract class BaseTaskCallBuilder<
|
|
|
|
TInput extends ZodRawShape | ZodTypeAny = ZodTypeAny,
|
|
|
|
TOutput extends ZodRawShape | ZodTypeAny = z.ZodTypeAny
|
|
|
|
> {
|
2023-06-01 01:53:09 +00:00
|
|
|
protected _timeoutMs: number | undefined
|
|
|
|
protected _retryConfig: types.RetryConfig | undefined
|
|
|
|
|
2023-06-01 06:03:27 +00:00
|
|
|
constructor(options: types.BaseTaskOptions = {}) {
|
2023-05-26 19:16:13 +00:00
|
|
|
this._timeoutMs = options.timeoutMs
|
|
|
|
this._retryConfig = options.retryConfig
|
2023-05-26 19:06:39 +00:00
|
|
|
}
|
|
|
|
|
2023-06-01 01:53:09 +00:00
|
|
|
public abstract get inputSchema(): TInput
|
2023-05-26 19:06:39 +00:00
|
|
|
|
2023-06-01 01:53:09 +00:00
|
|
|
public abstract get outputSchema(): TOutput
|
2023-05-26 19:06:39 +00:00
|
|
|
|
2023-06-01 01:53:09 +00:00
|
|
|
public retryConfig(retryConfig: types.RetryConfig) {
|
2023-05-26 19:16:13 +00:00
|
|
|
this._retryConfig = retryConfig
|
2023-05-26 19:06:39 +00:00
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
2023-06-01 01:53:09 +00:00
|
|
|
public abstract call(
|
2023-05-26 19:06:39 +00:00
|
|
|
input?: types.ParsedData<TInput>
|
|
|
|
): Promise<types.ParsedData<TOutput>>
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
// abstract stream({
|
|
|
|
// input: TInput,
|
|
|
|
// onProgress: types.ProgressFunction
|
|
|
|
// }): Promise<TOutput>
|
|
|
|
}
|