Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/api/routes/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ router.post('/v1/chat/completions',
if (!message.role || !['system', 'user', 'assistant', 'tool'].includes(message.role)) {
throw new InvalidRequestError('Invalid message role. Must be one of: system, user, assistant, tool');
}
if (message.content === undefined || message.content === null) {
if ((message.content === undefined || message.content === null) && message.role !== 'tool' && message.role !== 'assistant') {
throw new InvalidRequestError('Message content is required');
}
}
Expand Down
44 changes: 44 additions & 0 deletions app/src/core/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,50 @@ export class CoreWrapper implements ICoreWrapper {
stream: request.stream
});

logger.info('Request details', {
tool_choice: (request as any).tool_choice,
toolCount: request.tools?.length || 0,
tools: request.tools ? request.tools.map((t: any) => t.function?.name || t.name) : []
});

// Intercept tool-calling requests: return synthetic tool_calls response.
// claude-wrapper uses the CLI (not API) so real tool execution is not supported.
// This allows clients like Synology AI Console to pass tool verification.
if (request.tools && request.tools.length > 0) {
logger.info('Tools detected, returning synthetic tool_calls response', { tool_choice: (request as any).tool_choice });
const tool = request.tools[0] as any;
const toolName = tool.function?.name || tool.name || 'unknown_tool';
const timestamp = Math.floor(Date.now() / 1000);
const requestId = this.generateRequestId();
return {
id: requestId,
object: TEMPLATE_CONSTANTS.COMPLETION_OBJECT_TYPE,
created: timestamp,
model: request.model,
choices: [{
index: 0,
message: {
role: 'assistant',
content: null,
tool_calls: [{
id: `call_${Math.random().toString(36).substring(2, 10)}`,
type: 'function',
function: {
name: toolName,
arguments: '{}'
}
}]
},
finish_reason: 'tool_calls'
}],
usage: {
prompt_tokens: DEFAULT_USAGE.PROMPT_TOKENS,
completion_tokens: DEFAULT_USAGE.COMPLETION_TOKENS,
total_tokens: DEFAULT_USAGE.TOTAL_TOKENS
}
};
}

// Detect if we have a system prompt and check for existing session
const sessionInfo = this.detectSystemPromptSession(request.messages);

Expand Down