fix: updatedInput support and clean up types (#6)

This commit is contained in:
Christina Tong
2026-01-28 12:28:48 -08:00
committed by GitHub
parent 18467507e9
commit c4c5106797
3 changed files with 10 additions and 16 deletions

View File

@@ -37,8 +37,10 @@ export type {
SDKResultMessage,
SDKStreamEventMessage,
PermissionMode,
PermissionResult,
CanUseToolCallback,
CanUseToolResponse,
CanUseToolResponseAllow,
CanUseToolResponseDeny,
} from "./types.js";
export { Session } from "./session.js";

View File

@@ -137,16 +137,16 @@ export class Session implements AsyncDisposable {
if (this.options.canUseTool) {
try {
const result = await this.options.canUseTool(req.tool_name, req.input);
if (result.allow) {
if (result.behavior === "allow") {
response = {
behavior: "allow",
updatedInput: null, // TODO: not supported
updatedInput: result.updatedInput ?? null,
updatedPermissions: [], // TODO: not implemented
} satisfies CanUseToolResponseAllow;
} else {
response = {
behavior: "deny",
message: result.reason ?? "Denied by canUseTool callback",
message: result.message ?? "Denied by canUseTool callback",
interrupt: false, // TODO: not wired up yet
} satisfies CanUseToolResponseDeny;
}

View File

@@ -24,8 +24,8 @@ export type {
CreateBlock,
} from "@letta-ai/letta-code/protocol";
// Import types for use in SessionOptions
import type { CreateBlock } from "@letta-ai/letta-code/protocol";
// Import types for use in this file
import type { CreateBlock, CanUseToolResponse } from "@letta-ai/letta-code/protocol";
// ═══════════════════════════════════════════════════════════════
// SYSTEM PROMPT TYPES
@@ -86,20 +86,12 @@ export type MemoryPreset = "persona" | "human" | "project";
// ═══════════════════════════════════════════════════════════════
/**
* Result of a canUseTool callback
*/
export interface PermissionResult {
allow: boolean;
reason?: string;
}
/**
* Callback for custom permission handling
* Callback for custom permission handling.
*/
export type CanUseToolCallback = (
toolName: string,
toolInput: Record<string, unknown>,
) => Promise<PermissionResult> | PermissionResult;
) => Promise<CanUseToolResponse> | CanUseToolResponse;
/**
* Options for creating a session