feat: migrate to Letta TS SDK v1 (alpha) (#11)
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import { parseArgs } from "node:util";
|
||||
import { Letta } from "@letta-ai/letta-client";
|
||||
import type {
|
||||
AgentState,
|
||||
MessageCreate,
|
||||
} from "@letta-ai/letta-client/resources/agents/agents";
|
||||
import type { ApprovalCreate } from "@letta-ai/letta-client/resources/agents/messages";
|
||||
import { getClient } from "./agent/client";
|
||||
import { createAgent } from "./agent/create";
|
||||
import { sendMessageStream } from "./agent/message";
|
||||
@@ -49,7 +53,7 @@ export async function handleHeadlessCommand(argv: string[]) {
|
||||
const client = await getClient();
|
||||
|
||||
// Resolve agent (same logic as interactive mode)
|
||||
let agent: Letta.AgentState | null = null;
|
||||
let agent: AgentState | null = null;
|
||||
const specifiedAgentId = values.agent as string | undefined;
|
||||
const shouldContinue = values.continue as boolean | undefined;
|
||||
const forceNew = values.new as boolean | undefined;
|
||||
@@ -132,9 +136,9 @@ export async function handleHeadlessCommand(argv: string[]) {
|
||||
}
|
||||
|
||||
// Send message and process stream loop
|
||||
let currentInput: Array<Letta.MessageCreate | Letta.ApprovalCreate> = [
|
||||
let currentInput: Array<MessageCreate | ApprovalCreate> = [
|
||||
{
|
||||
role: Letta.MessageCreateRole.User,
|
||||
role: "user",
|
||||
content: [{ type: "text", text: prompt }],
|
||||
},
|
||||
];
|
||||
@@ -218,12 +222,12 @@ export async function handleHeadlessCommand(argv: string[]) {
|
||||
sessionStats.endTurn(apiDurationMs);
|
||||
|
||||
// Case 1: Turn ended normally
|
||||
if (stopReason === Letta.StopReasonType.EndTurn) {
|
||||
if (stopReason === "end_turn") {
|
||||
break;
|
||||
}
|
||||
|
||||
// Case 2: Requires approval
|
||||
if (stopReason === Letta.StopReasonType.RequiresApproval) {
|
||||
if (stopReason === "requires_approval") {
|
||||
if (!approval) {
|
||||
console.error("Unexpected null approval");
|
||||
process.exit(1);
|
||||
@@ -244,7 +248,7 @@ export async function handleHeadlessCommand(argv: string[]) {
|
||||
currentInput = [
|
||||
{
|
||||
type: "approval",
|
||||
approvalRequestId: toolCallId,
|
||||
approval_request_id: toolCallId,
|
||||
approve: false,
|
||||
reason: denyReason,
|
||||
},
|
||||
@@ -257,7 +261,7 @@ export async function handleHeadlessCommand(argv: string[]) {
|
||||
currentInput = [
|
||||
{
|
||||
type: "approval",
|
||||
approvalRequestId: toolCallId,
|
||||
approval_request_id: toolCallId,
|
||||
approve: false,
|
||||
reason: "Tool requires approval (headless mode)",
|
||||
},
|
||||
@@ -274,8 +278,8 @@ export async function handleHeadlessCommand(argv: string[]) {
|
||||
approvals: [
|
||||
{
|
||||
type: "tool",
|
||||
toolCallId,
|
||||
toolReturn: toolResult.toolReturn,
|
||||
tool_call_id: toolCallId,
|
||||
tool_return: toolResult.toolReturn,
|
||||
status: toolResult.status,
|
||||
stdout: toolResult.stdout,
|
||||
stderr: toolResult.stderr,
|
||||
|
||||
Reference in New Issue
Block a user