|
| 1 | +import type { Schema as AISchema } from "ai"; |
| 2 | +import { z } from "zod"; |
1 | 3 | import { SerializableJson } from "../../schemas/json.js";
|
| 4 | +import { TriggerApiRequestOptions } from "../apiClient/index.js"; |
2 | 5 | import { RunTags } from "../schemas/api.js";
|
3 |
| -import { QueueOptions } from "../schemas/schemas.js"; |
4 |
| -import { IdempotencyKey } from "./idempotencyKeys.js"; |
5 | 6 | import {
|
6 | 7 | MachineCpu,
|
7 | 8 | MachineMemory,
|
8 | 9 | RetryOptions,
|
9 | 10 | TaskMetadata,
|
10 | 11 | TaskRunContext,
|
11 | 12 | } from "../schemas/index.js";
|
| 13 | +import { QueueOptions } from "../schemas/schemas.js"; |
| 14 | +import { IdempotencyKey } from "./idempotencyKeys.js"; |
| 15 | +import { AnySchemaParseFn, inferSchemaIn, inferSchemaOut, Schema } from "./schemas.js"; |
12 | 16 | import { Prettify } from "./utils.js";
|
13 |
| -import { AnySchemaParseFn, inferSchemaOut, Schema } from "./schemas.js"; |
14 |
| -import { TriggerApiRequestOptions } from "../apiClient/index.js"; |
| 17 | +import { inferToolParameters, ToolTaskParameters } from "./tools.js"; |
15 | 18 |
|
16 | 19 | type RequireOne<T, K extends keyof T> = {
|
17 | 20 | [X in Exclude<keyof T, K>]?: T[X];
|
@@ -150,6 +153,8 @@ type CommonTaskOptions<
|
150 | 153 | /** An id for your task. This must be unique inside your project and not change between versions. */
|
151 | 154 | id: TIdentifier;
|
152 | 155 |
|
| 156 | + description?: string; |
| 157 | + |
153 | 158 | /** The retry settings when an uncaught error is thrown.
|
154 | 159 | *
|
155 | 160 | * If omitted it will use the values in your `trigger.config.ts` file.
|
@@ -337,6 +342,15 @@ export type TaskWithSchemaOptions<
|
337 | 342 | schema?: TSchema;
|
338 | 343 | };
|
339 | 344 |
|
| 345 | +export type TaskWithToolOptions< |
| 346 | + TIdentifier extends string, |
| 347 | + TParameters extends ToolTaskParameters, |
| 348 | + TOutput = unknown, |
| 349 | + TInitOutput extends InitOutput = any, |
| 350 | +> = CommonTaskOptions<TIdentifier, inferToolParameters<TParameters>, TOutput, TInitOutput> & { |
| 351 | + parameters: TParameters; |
| 352 | +}; |
| 353 | + |
340 | 354 | declare const __output: unique symbol;
|
341 | 355 | declare const __payload: unique symbol;
|
342 | 356 | type BrandRun<P, O> = { [__output]: O; [__payload]: P };
|
@@ -413,6 +427,9 @@ export interface Task<TIdentifier extends string, TInput = void, TOutput = any>
|
413 | 427 | * The id of the task.
|
414 | 428 | */
|
415 | 429 | id: TIdentifier;
|
| 430 | + |
| 431 | + description?: string; |
| 432 | + |
416 | 433 | /**
|
417 | 434 | * Trigger a task with the given payload, and continue without waiting for the result. If you want to wait for the result, use `triggerAndWait`. Returns the id of the triggered task run.
|
418 | 435 | * @param payload
|
@@ -479,6 +496,26 @@ export interface Task<TIdentifier extends string, TInput = void, TOutput = any>
|
479 | 496 | batchTriggerAndWait: (items: Array<BatchItem<TInput>>) => Promise<BatchResult<TOutput>>;
|
480 | 497 | }
|
481 | 498 |
|
| 499 | +export interface TaskWithSchema< |
| 500 | + TIdentifier extends string, |
| 501 | + TSchema extends TaskSchema | undefined = undefined, |
| 502 | + TOutput = any, |
| 503 | +> extends Task<TIdentifier, inferSchemaIn<TSchema>, TOutput> { |
| 504 | + schema?: TSchema; |
| 505 | +} |
| 506 | + |
| 507 | +export interface ToolTask< |
| 508 | + TIdentifier extends string, |
| 509 | + TParameters extends ToolTaskParameters, |
| 510 | + TOutput = any, |
| 511 | +> extends Task<TIdentifier, inferToolParameters<TParameters>, TOutput> { |
| 512 | + tool: { |
| 513 | + parameters: TParameters; |
| 514 | + description?: string; |
| 515 | + execute: (args: inferToolParameters<TParameters>) => Promise<TOutput>; |
| 516 | + }; |
| 517 | +} |
| 518 | + |
482 | 519 | export type AnyTask = Task<string, any, any>;
|
483 | 520 |
|
484 | 521 | export type TaskPayload<TTask extends AnyTask> = TTask extends Task<string, infer TInput, any>
|
|
0 commit comments