feat: add allowedTools for SDK use and re-organize test setup

This commit is contained in:
mingholy.lmh
2025-11-28 16:47:45 +08:00
parent 56957a687b
commit 249b141f19
15 changed files with 1779 additions and 394 deletions

View File

@@ -296,32 +296,17 @@ export class Query implements AsyncIterable<SDKMessage> {
timeoutPromise,
]);
// Handle boolean return (backward compatibility)
if (typeof result === 'boolean') {
return result
? { behavior: 'allow', updatedInput: toolInput }
: { behavior: 'deny', message: 'Denied' };
}
// Handle PermissionResult format
const permissionResult = result as {
behavior: 'allow' | 'deny';
updatedInput?: Record<string, unknown>;
message?: string;
interrupt?: boolean;
};
if (permissionResult.behavior === 'allow') {
if (result.behavior === 'allow') {
return {
behavior: 'allow',
updatedInput: permissionResult.updatedInput ?? toolInput,
updatedInput: result.updatedInput ?? toolInput,
};
} else {
return {
behavior: 'deny',
message: permissionResult.message ?? 'Denied',
...(permissionResult.interrupt !== undefined
? { interrupt: permissionResult.interrupt }
message: result.message ?? 'Denied',
...(result.interrupt !== undefined
? { interrupt: result.interrupt }
: {}),
};
}

View File

@@ -54,6 +54,7 @@ export function query({
maxSessionTurns: options.maxSessionTurns,
coreTools: options.coreTools,
excludeTools: options.excludeTools,
allowedTools: options.allowedTools,
authType: options.authType,
includePartialMessages: options.includePartialMessages,
});