@xynehq/jaf
Version:
Juspay Agent Framework - A purely functional agent framework with immutable state and composable tools
69 lines • 2.56 kB
JavaScript
import { safeConsole } from '../utils/logger.js';
export async function approve(state, interruption, additionalContext, config) {
if (interruption.type === 'tool_approval') {
const approvalValue = {
status: 'approved',
approved: true,
additionalContext: { ...(additionalContext || {}), status: 'approved' },
};
// Store in approval storage if available
if (config?.approvalStorage) {
const result = await config.approvalStorage.storeApproval(state.runId, interruption.toolCall.id, approvalValue);
if (!result.success) {
safeConsole.warn('Failed to store approval:', result.error);
// Continue with in-memory fallback
}
}
// Update in-memory state
const newApprovals = new Map(state.approvals ?? []);
newApprovals.set(interruption.toolCall.id, approvalValue);
return {
...state,
approvals: newApprovals,
};
}
return state;
}
export async function reject(state, interruption, additionalContext, config) {
if (interruption.type === 'tool_approval') {
const approvalValue = {
status: 'rejected',
approved: false,
additionalContext: { ...(additionalContext || {}), status: 'rejected' },
};
// Store in approval storage if available
if (config?.approvalStorage) {
const result = await config.approvalStorage.storeApproval(state.runId, interruption.toolCall.id, approvalValue);
if (!result.success) {
safeConsole.warn('Failed to store approval:', result.error);
// Continue with in-memory fallback
}
}
// Update in-memory state
const newApprovals = new Map(state.approvals ?? []);
newApprovals.set(interruption.toolCall.id, approvalValue);
return {
...state,
approvals: newApprovals,
};
}
return state;
}
// Helper function to load approvals from storage into state
export async function loadApprovalsIntoState(state, config) {
if (!config?.approvalStorage) {
return state;
}
const result = await config.approvalStorage.getRunApprovals(state.runId);
if (result.success) {
return {
...state,
approvals: result.data,
};
}
else {
safeConsole.warn('Failed to load approvals:', result.error);
return state;
}
}
//# sourceMappingURL=state.js.map