fix: updatedInput support and clean up types (#6)
This commit is contained in:
@@ -37,8 +37,10 @@ export type {
|
||||
SDKResultMessage,
|
||||
SDKStreamEventMessage,
|
||||
PermissionMode,
|
||||
PermissionResult,
|
||||
CanUseToolCallback,
|
||||
CanUseToolResponse,
|
||||
CanUseToolResponseAllow,
|
||||
CanUseToolResponseDeny,
|
||||
} from "./types.js";
|
||||
|
||||
export { Session } from "./session.js";
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
16
src/types.ts
16
src/types.ts
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user