Repository: danielmiessler/fabric
File: web/src/lib/services/ChatService.ts (TypeScript)

Code before:
		systemPromptText?: string,
	): ChatPrompt {
		const config = get(modelConfig);
		const language = get(languageStore);

		const languageInstruction =
			language !== "en"
				? `You MUST respond in ${language} language. All output must be in ${language}. `
				: // ? `You MUST respond in ${language} language. ALL output, including section headers, titles, and formatting, MUST be translated into ${language}.  It is CRITICAL that you translate ALL headers, such as SUMMARY, IDEAS, QUOTES, TAKEAWAYS, MAIN POINTS, etc., into ${language}. Maintain markdown formatting in the response. Do not output any English headers.`
					"";

		const finalSystemPrompt =
			languageInstruction + (systemPromptText ?? get(systemPrompt));

		const finalUserInput =
			language !== "en"
				? `${userInput}\n\nIMPORTANT: Respond in ${language} language only.`
				: userInput;

		return {
			userInput: finalUserInput,
			systemPrompt: finalSystemPrompt,
			model: config.model,
			patternName: get(selectedPatternName),
			strategyName: get(selectedStrategy), // Add selected strategy to prompt
			sessionName: get(currentSession) || undefined, // Session name for multi-turn conversations
			variables: get(patternVariables), // Add pattern variables
		};
	}

	public async createChatRequest(
		userInput: string,
		systemPromptText?: string,
		isPattern: boolean = false,
	): Promise<ChatRequest> {
		const prompt = this.createChatPrompt(userInput, systemPromptText);
		const config = get(chatConfig);
		const language = get(languageStore);

		return {
			prompts: [prompt],
			messages: [],
			language: language, // Add language at the top level for backend compatibility
			...config,
		};
	}

	public async streamPattern(
		userInput: string,
		systemPromptText?: string,
	): Promise<ReadableStream<StreamResponse>> {

Review comment (suggestion):
You can replace this with this line instead:

```javascript
sessionName: get(currentSession) ?? undefined,
```

Code after:
		systemPromptText?: string,
	): ChatPrompt {
		const config = get(modelConfig);
		const language = get(languageStore);

		const languageInstruction =
			language !== "en"
				? `You MUST respond in ${language} language. All output must be in ${language}. `
				: // ? `You MUST respond in ${language} language. ALL output, including section headers, titles, and formatting, MUST be translated into ${language}.  It is CRITICAL that you translate ALL headers, such as SUMMARY, IDEAS, QUOTES, TAKEAWAYS, MAIN POINTS, etc., into ${language}. Maintain markdown formatting in the response. Do not output any English headers.`
					"";

		const finalSystemPrompt =
			languageInstruction + (systemPromptText ?? get(systemPrompt));

		const finalUserInput =
			language !== "en"
				? `${userInput}\n\nIMPORTANT: Respond in ${language} language only.`
				: userInput;

		return {
			userInput: finalUserInput,
			systemPrompt: finalSystemPrompt,
			model: config.model,
			patternName: get(selectedPatternName),
			strategyName: get(selectedStrategy), // Add selected strategy to prompt
			sessionName: get(currentSession) ?? undefined, // Session name for multi-turn conversations
			variables: get(patternVariables), // Add pattern variables
		};
	}

	public async createChatRequest(
		userInput: string,
		systemPromptText?: string,
		isPattern: boolean = false,
	): Promise<ChatRequest> {
		const prompt = this.createChatPrompt(userInput, systemPromptText);
		const config = get(chatConfig);
		const language = get(languageStore);

		return {
			prompts: [prompt],
			messages: [],
			language: language, // Add language at the top level for backend compatibility
			...config,
		};
	}

	public async streamPattern(
		userInput: string,
		systemPromptText?: string,
	): Promise<ReadableStream<StreamResponse>> {