@artinet/sdk
Version:
A TypeScript SDK for building collaborative AI agents.
252 lines (251 loc) • 9.22 kB
TypeScript
/**
* Copyright 2025 The Artinet Project
* SPDX-License-Identifier: Apache-2.0
*/
import { A2A } from "../types/index.js";
import { type MessageParams } from "./message-builder.js";
import { Kindless } from "./base.js";
export type BaseArtifactParams = Partial<Kindless<A2A.Artifact>>;
export type ArtifactParams = BaseArtifactParams | string;
export declare const isArtifactParams: (params: any) => params is ArtifactParams;
export declare class Artifact {
private readonly _artifact;
constructor(artifact_params?: Partial<A2A.Artifact>);
get artifact(): A2A.Artifact;
static create(params?: ArtifactParams): A2A.Artifact;
}
export declare const artifact: typeof Artifact.create;
export type StatusParams = Partial<Kindless<A2A.TaskStatus>> | A2A.TaskState | MessageParams;
export declare const isStatusParams: (params: any) => params is StatusParams;
export declare class TaskStatus {
private readonly _status;
constructor(params?: Partial<A2A.TaskStatus>);
get status(): A2A.TaskStatus;
static create(params?: StatusParams): A2A.TaskStatus;
}
/**
* Convenience factory function for creating a task status with default parameters.
*
* @returns New {@link A2A.TaskStatus} with default parameters
* @defaults {
* state: "working",
* timestamp: getCurrentTimestamp(),
* }
*
* @example
* ```typescript
* const status = status("working");
* ```
*
* @public
* @since 0.6.0
*/
export declare const status: typeof TaskStatus.create;
export type TaskParams = Partial<Kindless<A2A.Task>> | StatusParams;
export declare class Task {
private readonly _task;
constructor(params?: Partial<Kindless<A2A.Task>>);
get task(): A2A.Task;
static create(params?: TaskParams): A2A.Task;
}
/**
* Convenience factory function for creating a task with default parameters.
*
* @returns New {@link A2A.Task} with default parameters
* @defaults:
* - `id`: uuidv4()
* - `contextId`: id
* - `status`: { state: "working" }
* @example
* ```typescript
* const task = task({ status: { state: "working" } });
* ```
*
* @public
* @since 0.6.0
*/
export declare const task: typeof Task.create;
export type StatusUpdateParams = (Partial<Kindless<A2A.TaskStatusUpdateEvent>> & {
status: StatusParams;
}) | StatusParams;
export declare class TaskStatusUpdateEvent {
private readonly _event;
constructor(params: Partial<Kindless<A2A.TaskStatusUpdateEvent>> & Required<Pick<Kindless<A2A.TaskStatusUpdateEvent>, "status">>);
get event(): A2A.TaskStatusUpdateEvent;
static create(params: StatusUpdateParams): A2A.TaskStatusUpdateEvent;
}
export type ArtifactUpdateParams = (Partial<Kindless<A2A.TaskArtifactUpdateEvent>> & {
artifact: ArtifactParams;
}) | ArtifactParams;
export declare class TaskArtifactUpdateEvent {
private readonly _event;
constructor(params: Partial<Kindless<A2A.TaskArtifactUpdateEvent>> & Required<Pick<Kindless<A2A.TaskArtifactUpdateEvent>, "artifact">>);
get event(): A2A.TaskArtifactUpdateEvent;
static create(params: ArtifactUpdateParams): A2A.TaskArtifactUpdateEvent;
}
type StrictUpdateParams = Partial<Kindless<A2A.TaskStatusUpdateEvent>> & Required<Pick<Kindless<A2A.TaskStatusUpdateEvent>, "taskId" | "contextId" | "status">>;
export type BuildStatusParams = Omit<StrictUpdateParams, "status"> & Omit<A2A.TaskStatus, "state">;
declare function _working(params: BuildStatusParams): A2A.TaskStatusUpdateEvent;
declare function _canceled(params: BuildStatusParams): A2A.TaskStatusUpdateEvent;
declare function _submitted(params: BuildStatusParams): A2A.TaskStatusUpdateEvent;
declare function _failed(params: BuildStatusParams): A2A.TaskStatusUpdateEvent;
declare function _completed(params: BuildStatusParams): A2A.TaskStatusUpdateEvent;
declare function _inputRequired(params: BuildStatusParams): A2A.TaskStatusUpdateEvent;
declare function _rejected(params: BuildStatusParams): A2A.TaskStatusUpdateEvent;
declare function _authRequired(params: BuildStatusParams): A2A.TaskStatusUpdateEvent;
declare function _unknown(params: BuildStatusParams): A2A.TaskStatusUpdateEvent;
/**
* Convenience factory function for creating a task status and artifact update events with default parameters.
*
* @returns New {@link A2A.TaskStatusUpdateEvent} and {@link A2A.TaskArtifactUpdateEvent} with default parameters
*
* @example
* ```typescript
* const artifactEvent = update.artifact({
* artifact: "result"
* });
* const statusEvent = update.status({
* status: "working"
* });
* ```
*
* @public
* @since 0.6.0
*/
export declare const update: {
/**
* Convenience factory function for creating a task artifact update event.
* @returns New {@link A2A.TaskArtifactUpdateEvent}
* @example
* ```typescript
* const event = update.artifact({
* artifact: "result"
* });
* ```
*/
artifact: typeof TaskArtifactUpdateEvent.create;
/**
* Convenience factory function for creating a task status update event.
* @returns New {@link A2A.TaskStatusUpdateEvent}
* @example
* ```typescript
* const event = update.status({
* message: "Working on the task"
* });
* ```
*/
status: typeof TaskStatusUpdateEvent.create;
/**
* Convenience factory function for creating a task status update event with the working state.
* @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.working} state
* @example
* ```typescript
* const event = update.working({
* message: "Working on the task"
* });
* ```
*/
working: typeof _working;
/**
* Convenience factory function for creating a task status update event with the canceled state.
* @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.canceled} state
* @example
* ```typescript
* const event = update.canceled({
* message: "Task canceled"
* });
* ```
*/
canceled: typeof _canceled;
/**
* Convenience factory function for creating a task status update event with the submitted state.
* @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.submitted} state
* @example
* ```typescript
* const event = update.submitted({
* message: "Task submitted"
* });
* ```
*/
submitted: typeof _submitted;
/**
* Convenience factory function for creating a task status update event with the failed state.
* @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.failed} state
* @example
* ```typescript
* const event = update.failed({
* message: "Task failed"
* });
* ```
*/
failed: typeof _failed;
/**
* Convenience factory function for creating a task status update event with the completed state.
* @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.completed} state
* @example
* ```typescript
* const event = update.completed({
* message: "Task completed"
* });
* ```
*/
completed: typeof _completed;
/**
* Convenience factory function for creating a task status update event with the input required state.
* @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState["input-required"]} state
* @example
* ```typescript
* const event = update.inputRequired({
* message: "Task input required"
* });
* ```
*/
inputRequired: typeof _inputRequired;
/**
* Convenience factory function for creating a task status update event with the rejected state.
* @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.rejected} state
* @example
* ```typescript
* const event = update.rejected({
* message: "Task rejected"
* });
* ```
*/
rejected: typeof _rejected;
/**
* Convenience factory function for creating a task status update event with the auth required state.
* @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState["auth-required"]} state
* @example
* ```typescript
* const event = update.authRequired({
* message: {
* role: "agent"
* parts: [
* {
* text: "Task auth required"
* }
* ]
* kind: "message"
* });
* ```
*/
authRequired: typeof _authRequired;
/**
* Convenience factory function for creating a task status update event with the unknown state.
* @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.unknown} state
* @example
* ```typescript
* const event = update.unknown({
* message: "Task unknown"
* });
* ```
*/
unknown: typeof _unknown;
};
/**
* @description A temporary compatibility function for updating a task status, purely for migration purposes.
* @deprecated Use {@link update.status} instead
* @since 0.6.0
*/
export declare const update_compat: (taskId: string, contextId: string, state: A2A.TaskState, message?: A2A.Message, timestamp?: string, final?: boolean) => A2A.TaskStatusUpdateEvent;
export {};