@humanlayer/sdk
Version:
typescript client for humanlayer.dev
250 lines (244 loc) • 8.07 kB
text/typescript
type FunctionCallStatus = {
requested_at: Date;
responded_at?: Date;
approved?: boolean;
comment?: string;
reject_option_name?: string;
slack_message_ts?: string;
};
type SlackContactChannel = {
channel_or_user_id: string;
context_about_channel_or_user?: string;
bot_token?: string;
experimental_slack_blocks?: boolean;
thread_ts?: string;
};
type SMSContactChannel = {
phone_number: string;
context_about_user?: string;
};
type WhatsAppContactChannel = {
phone_number: string;
context_about_user?: string;
};
type EmailContactChannel = {
address: string;
context_about_user?: string;
additional_recipients?: EmailRecipient[];
experimental_subject_line?: string;
experimental_in_reply_to_message_id?: string;
experimental_references_message_id?: string;
template?: string;
};
type EmailRecipient = {
address: string;
context_about_user?: string;
field: 'to' | 'cc' | 'bcc';
};
type ContactChannel = {
slack?: SlackContactChannel;
sms?: SMSContactChannel;
whatsapp?: WhatsAppContactChannel;
email?: EmailContactChannel;
};
type ResponseOption = {
name: string;
title?: string;
description?: string;
prompt_fill?: string;
interactive?: boolean;
};
type FunctionCallSpec = {
fn: string;
kwargs: Record<string, any>;
channel?: ContactChannel;
reject_options?: ResponseOption[];
state?: Record<string, any>;
};
type FunctionCall = {
run_id: string;
call_id: string;
spec: FunctionCallSpec;
status?: FunctionCallStatus;
};
type Escalation = {
escalation_msg: string;
additional_recipients?: EmailRecipient[];
channel?: ContactChannel;
};
type HumanContactSpec = {
msg: string;
channel?: ContactChannel;
response_options?: ResponseOption[];
state?: Record<string, any>;
};
type HumanContactStatus = {
requested_at?: Date;
responded_at?: Date;
response?: string;
response_option_name?: string;
};
type HumanContact = {
run_id: string;
call_id: string;
spec: HumanContactSpec;
status?: HumanContactStatus;
};
type AgentStore<T_Call, T_Status> = {
add: (item: T_Call) => Promise<T_Call>;
get: (call_id: string) => Promise<T_Call>;
respond: (call_id: string, status: T_Status) => Promise<T_Call>;
escalateEmail: (call_id: string, escalation: Escalation) => Promise<T_Call>;
};
type AgentBackend = {
functions(): AgentStore<FunctionCall, FunctionCallStatus>;
contacts(): AgentStore<HumanContact, HumanContactStatus>;
};
declare class HumanLayerCloudConnection {
apiKey?: string;
apiBaseURL?: string;
constructor(api_key?: string, api_base_url?: string);
request({ method, path, body, }: {
method: string;
path: string;
body?: any;
}): Promise<Response>;
}
declare class CloudFunctionCallStore implements AgentStore<FunctionCall, FunctionCallStatus> {
private connection;
constructor(connection: HumanLayerCloudConnection);
add(item: FunctionCall): Promise<FunctionCall>;
get(call_id: string): Promise<FunctionCall>;
respond(call_id: string, status: FunctionCallStatus): Promise<FunctionCall>;
escalateEmail(call_id: string, escalation: Escalation): Promise<FunctionCall>;
}
declare class CloudHumanContactStore implements AgentStore<HumanContact, HumanContactStatus> {
private connection;
constructor(connection: HumanLayerCloudConnection);
add(item: HumanContact): Promise<HumanContact>;
get(call_id: string): Promise<HumanContact>;
respond(call_id: string, status: HumanContactStatus): Promise<HumanContact>;
escalateEmail(call_id: string, escalation: Escalation): Promise<HumanContact>;
}
declare class CloudHumanLayerBackend implements AgentBackend {
connection: HumanLayerCloudConnection;
private _function_calls;
private _human_contacts;
constructor(connection: HumanLayerCloudConnection);
functions(): CloudFunctionCallStore;
contacts(): CloudHumanContactStore;
}
declare enum ApprovalMethod {
cli = "cli",
backend = "backend"
}
declare const humanlayer: (params?: HumanLayerParams) => HumanLayer;
interface HumanLayerParams {
runId?: string;
approvalMethod?: ApprovalMethod;
backend?: AgentBackend;
agentName?: string;
genid?: (prefix: string) => string;
sleep?: (ms: number) => Promise<void>;
contactChannel?: ContactChannel;
apiKey?: string;
apiBaseUrl?: string;
verbose?: boolean;
httpTimeoutSeconds?: number;
}
declare class HumanLayer {
approvalMethod: ApprovalMethod;
backend?: AgentBackend;
runId: string;
agentName: string;
genid: (prefix: string) => string;
sleep: (ms: number) => Promise<void>;
contactChannel?: ContactChannel;
verbose?: boolean;
constructor(params?: HumanLayerParams);
static cloud(params?: {
connection?: HumanLayerCloudConnection;
apiKey?: string;
apiBaseUrl?: string;
}): HumanLayer;
static cli(): HumanLayer;
requireApproval<TFn extends Function>(contactChannel?: ContactChannel): (fn: TFn) => TFn;
approveCli<TFn extends Function>(fn: TFn): TFn;
approveWithBackend<TFn extends Function>(fn: TFn, contactChannel?: ContactChannel): TFn;
humanAsTool(contactChannel?: ContactChannel): ({ message }: {
message: string;
}) => Promise<string>;
humanAsToolCli(): ({ message }: {
message: string;
}) => Promise<string>;
humanAsToolBackend(contactChannel?: ContactChannel): ({ message }: {
message: string;
}) => Promise<string>;
fetchHumanResponse({ spec }: {
spec: HumanContactSpec;
}): Promise<string>;
createHumanContact({ spec }: {
spec: HumanContactSpec;
}): Promise<HumanContact>;
escalateEmailHumanContact(call_id: string, escalation: Escalation): Promise<HumanContact>;
getHumanContact(call_id: string): Promise<HumanContact>;
fetchHumanApproval({ spec }: {
spec: FunctionCallSpec;
}): Promise<FunctionCallStatus>;
createFunctionCall({ spec }: {
spec: FunctionCallSpec;
}): Promise<FunctionCall>;
escalateEmailFunctionCall(call_id: string, escalation: Escalation): Promise<FunctionCall>;
getFunctionCall(call_id: string): Promise<FunctionCall>;
}
type EmailMessage = {
from_address: string;
to_address: string[];
cc_address: string[];
bcc_address: string[];
subject: string;
content: string;
datetime: string;
};
type EmailPayload = {
from_address: string;
to_address: string;
subject: string;
body: string;
message_id: string;
previous_thread?: EmailMessage[];
raw_email: string;
is_test?: boolean;
};
type SlackMessage = {
from_user_id: string;
channel_id: string;
content: string;
message_id: string;
};
type SlackThread = {
thread_ts: string;
channel_id: string;
events: SlackMessage[];
};
type V1Beta2EmailEventReceived = {
is_test?: boolean;
type: 'agent_email.received';
event: EmailPayload;
};
type V1Beta2SlackEventReceived = {
is_test?: boolean;
type: 'agent_slack.received';
event: SlackThread;
};
type V1Beta2FunctionCallCompleted = {
is_test?: boolean;
type: 'function_call.completed';
event: FunctionCall;
};
type V1Beta2HumanContactCompleted = {
is_test?: boolean;
type: 'human_contact.completed';
event: HumanContact;
};
export { ApprovalMethod, CloudFunctionCallStore, CloudHumanContactStore, CloudHumanLayerBackend, type ContactChannel, type EmailContactChannel, type EmailRecipient, type Escalation, type FunctionCall, type FunctionCallSpec, type FunctionCallStatus, type HumanContact, type HumanContactSpec, type HumanContactStatus, HumanLayer, HumanLayerCloudConnection, type HumanLayerParams, type ResponseOption, type SMSContactChannel, type SlackContactChannel, type V1Beta2EmailEventReceived, type V1Beta2FunctionCallCompleted, type V1Beta2HumanContactCompleted, type V1Beta2SlackEventReceived, type WhatsAppContactChannel, humanlayer };