Merge branch 'upstream' into concedo_experimental

# Conflicts:
#	.github/workflows/build-apple.yml
#	.github/workflows/build-cpu.yml
#	.github/workflows/build-cuda-ubuntu.yml
#	.github/workflows/build-sycl.yml
#	.github/workflows/build-vulkan.yml
#	.github/workflows/build-wasm.yml
#	.github/workflows/build-webgpu.yml
#	.github/workflows/hip-quality-check.yml
#	.github/workflows/server.yml
#	CMakeLists.txt
#	docs/backend/SYCL.md
#	ggml/CMakeLists.txt
#	ggml/src/CMakeLists.txt
#	ggml/src/ggml-opencl/CMakeLists.txt
#	ggml/src/ggml-opencl/ggml-opencl.cpp
#	ggml/src/ggml-opencl/kernels/concat.cl
#	ggml/src/ggml-opencl/kernels/cpy.cl
#	ggml/src/ggml-sycl/common.cpp
#	ggml/src/ggml-sycl/common.hpp
#	ggml/src/ggml-sycl/fattn-buffers.cpp
#	ggml/src/ggml-sycl/fwht.cpp
#	ggml/src/ggml-sycl/ggml-sycl.cpp
#	scripts/sync-ggml.last
#	tests/test-backend-ops.cpp
#	tests/test-llama-archs.cpp
This commit is contained in:
Concedo
2026-09-05 12:09:30 +08:00
35 changed files with 1665 additions and 50 deletions
+1 -2
View File
@@ -1718,8 +1718,7 @@ struct clip_model_loader {
hparams.patch_size = hparams.patch_size * hparams.n_merge;
hparams.n_merge = 1;
}
// @ngxson : the model performs quite poor with small images, we need to bump minimum image tokens to 40 to avoid that
hparams.set_limit_image_tokens(40, 280);
hparams.set_limit_image_tokens(70, 1120);
hparams.set_warmup_n_tokens(256); // avoid OOM on warmup
} break;
+3 -1
View File
@@ -2173,9 +2173,11 @@ bool mtmd_decode_use_non_causal(const mtmd_context * ctx, const mtmd_input_chunk
proj_type = ctx->proj_type_a();
}
switch (proj_type) {
case PROJECTOR_TYPE_GEMMA3:
case PROJECTOR_TYPE_GEMMA4V:
// E2B (n_embd = 1536) and E4B (n_embd = 2560) always use causal
return ctx->n_embd_text != 1536 && ctx->n_embd_text != 2560;
case PROJECTOR_TYPE_GEMMA4UV:
case PROJECTOR_TYPE_GEMMA3:
case PROJECTOR_TYPE_DEEPSEEK4V:
return true;
default:
+1 -1
View File
@@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"build": "npm run build-pwa-assets && vite build",
"build-pwa-assets": "npx @vite-pwa/assets-generator --root . --config pwa-assets.config.ts && npx @vite-pwa/assets-generator --root . --config pwa-assets-dark.config.ts && node scripts/make-icons-circular.js",
"build-pwa-assets": "pwa-assets-generator --root . --config pwa-assets.config.ts && pwa-assets-generator --root . --config pwa-assets-dark.config.ts && node scripts/make-icons-circular.js",
"dev": "bash scripts/dev.sh",
"preview": "vite preview",
"prepare": "svelte-kit sync || echo ''",
@@ -194,7 +194,7 @@
/>
{:else if section.type === AgenticSectionType.TOOL_CALL || section.type === AgenticSectionType.TOOL_CALL_PENDING || section.type === AgenticSectionType.TOOL_CALL_STREAMING}
<ChatMessageToolCallBlock
attachments={message?.extra}
attachments={section.toolResultExtras}
isExecuting={section.toolCallId !== undefined &&
section.toolCallId === currentlyExecutingToolCallId}
{isStreaming}
@@ -139,12 +139,8 @@
async function handleExportConfirm(selectedConversations: DatabaseConversation[]) {
try {
const allData: ExportedConversation[] = await Promise.all(
selectedConversations.map(async (conv) => {
const messages = await conversationsStore.getConversationMessages(conv.id);
return { conv: $state.snapshot(conv), messages: $state.snapshot(messages) };
})
const allData = await conversationsStore.getConversationsForExport(
selectedConversations.map((conv) => conv.id)
);
if (allData.length === 1) {
@@ -2,8 +2,11 @@ import type { AgenticConfig } from '$lib/types/agentic';
export const ATTACHMENT_SAVED_REGEX = /\[Attachment saved: ([^\]]+)\]/;
// JSON detection: trimmed content opens with an object or array literal.
export const TOOL_RESULT_JSON_OPEN_REGEX = /^[[{]/;
// JSON detection: an attachment placeholder also starts with `[`, but is
// plain text (`[Attachment saved: ...]`), not an array literal. Require the
// first array value (or the closing bracket for an empty array) to look like
// a valid JSON token before attempting JSON.parse.
export const TOOL_RESULT_JSON_OPEN_REGEX = /^(?:\{|\[\s*(?:[[\]"{\-0-9]|true|false|null))/;
// Search-summary wire format used by file-glob and grep tools:
// <matches>
@@ -168,15 +168,7 @@ class ConversationsStore implements ConversationsPreferencesHost {
if (convIds.length === 0) return;
try {
const fetched = await DatabaseService.getConversationsWithMessages(convIds);
const activeId = this.activeConversation?.id;
const overridden = fetched.get(activeId ?? '');
if (overridden && activeId) {
overridden.conv = { ...this.activeConversation! };
}
const exported = [...fetched.values()];
const exported = await this.getConversationsForExport(convIds);
if (exported.length === 0) {
toast.error('No conversations to export');
@@ -365,16 +357,11 @@ class ConversationsStore implements ConversationsPreferencesHost {
* @param convId - The conversation ID to download
*/
async downloadConversation(convId: string): Promise<void> {
const conversation =
this.activeConversation?.id === convId
? this.activeConversation
: await DatabaseService.getConversation(convId);
const [exportedConversation] = await this.getConversationsForExport([convId]);
if (!conversation) return;
if (!exportedConversation) return;
const messages = await DatabaseService.getConversationMessages(convId);
ConversationTransferService.downloadConversationFile({ conv: conversation, messages });
ConversationTransferService.downloadConversationFile(exportedConversation);
}
/**
@@ -453,6 +440,19 @@ class ConversationsStore implements ConversationsPreferencesHost {
return await DatabaseService.getConversationMessages(convId);
}
/**
* Gets conversations and their messages from the database for export.
* @param convIds - Conversation IDs
* @returns List of conversations with messages, ordered by the input IDs
*/
async getConversationsForExport(convIds: string[]): Promise<ExportedConversation[]> {
const fetched = await DatabaseService.getConversationsWithMessages(convIds);
return convIds
.map((id) => fetched.get(id))
.filter((entry): entry is ExportedConversation => entry !== undefined);
}
/**
* Imports conversations from provided data (without file picker)
* @param data - Array of conversation data with messages
@@ -37,6 +37,10 @@ describe('classifyToolResult', () => {
expect(classifyToolResult('["a", "b", "c"]')).toBe('json');
});
it('classifies a nested JSON array', () => {
expect(classifyToolResult('[[1, 2], [3, 4]]')).toBe('json');
});
it('classifies a pretty-printed JSON object', () => {
expect(classifyToolResult('{\n "key": "value"\n}')).toBe('json');
});
@@ -0,0 +1,175 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
vi.mock('$lib/services/database.service', () => ({
DatabaseService: { getConversationsWithMessages: vi.fn() }
}));
import { MessageRole, MessageType } from '$lib/enums';
import { ConversationTransferService } from '$lib/services/conversation-transfer.service';
import { DatabaseService } from '$lib/services/database.service';
import { conversationsStore } from '$lib/stores/conversations/index.svelte';
import type { DatabaseConversation, DatabaseMessage } from '$lib/types/database';
import { filterByLeafNodeId } from '$lib/utils/branching';
/**
* Reproduces the exported-conversation bug:
*
* A conversation created in the current page session keeps `currNode: ''` in the
* sidebar list, because that list is only loaded at init while IndexedDB is stamped
* on every message insert.
*
* Exporting from the cached record resulted in no branch pointer, and importing
* the file showed every branch at once.
*/
const fetchMock = vi.mocked(DatabaseService.getConversationsWithMessages);
beforeEach(() => {
fetchMock.mockReset();
});
const CONV_ID = 'c1';
function message(
id: string,
parent: string | null,
timestamp: number,
role: MessageRole,
type: MessageType = MessageType.TEXT
): DatabaseMessage {
return {
children: [],
content: id,
convId: CONV_ID,
id,
parent,
role,
timestamp,
toolCalls: '',
type
} as DatabaseMessage;
}
/** root -> u1 -> a1 -> { u2a -> a2a (older) | u2b -> a2b (newer) } */
function branchedMessages(): DatabaseMessage[] {
const messages = [
message('root', null, 10, MessageRole.USER, MessageType.ROOT),
message('u1', 'root', 20, MessageRole.USER),
message('a1', 'u1', 30, MessageRole.ASSISTANT),
message('u2a', 'a1', 40, MessageRole.USER),
message('a2a', 'u2a', 50, MessageRole.ASSISTANT),
message('u2b', 'a1', 60, MessageRole.USER),
message('a2b', 'u2b', 70, MessageRole.ASSISTANT)
];
for (const m of messages) {
m.children = messages.filter((c) => c.parent === m.id).map((c) => c.id);
}
return messages;
}
/** A second conversation with a single linear path: root -> u1 -> a1. */
function linearMessages(convId: string): DatabaseMessage[] {
return [
{ ...message('root', null, 10, MessageRole.USER, MessageType.ROOT), children: ['u1'], convId },
{ ...message('u1', 'root', 20, MessageRole.USER), children: ['a1'], convId },
{ ...message('a1', 'u1', 30, MessageRole.ASSISTANT), convId }
];
}
function conversation(currNode: string, id: string = CONV_ID): DatabaseConversation {
return { currNode, id, lastModified: 100, name: `Chat ${id}` };
}
/** Mirrors `conversationsStore.loadConversation` */
function displayedIds(imported: { conv: DatabaseConversation; messages: DatabaseMessage[] }) {
if (imported.conv.currNode) {
return filterByLeafNodeId(imported.messages, imported.conv.currNode, false).map((m) => m.id);
}
return imported.messages.map((m) => m.id);
}
/** Export then re-import */
function roundTrip(conv: DatabaseConversation) {
const jsonl = ConversationTransferService.serializeSessionToJsonl({
conv,
messages: branchedMessages()
});
const [imported] = ConversationTransferService.parseSessionsJsonl(jsonl);
return { imported, sessionLine: JSON.parse(jsonl.split('\n')[0]) };
}
describe('conversation export source', () => {
it('reads the database record rather than the stale sidebar list', async () => {
conversationsStore.conversations = [conversation('')];
fetchMock.mockResolvedValue(
new Map([[CONV_ID, { conv: conversation('a2a'), messages: branchedMessages() }]])
);
const [exported] = await conversationsStore.getConversationsForExport([CONV_ID]);
expect(exported.conv.currNode).toBe('a2a');
expect(conversationsStore.conversations[0].currNode).toBe('');
});
it('reads every selected conversation from the database on bulk export', async () => {
conversationsStore.conversations = [conversation(''), conversation('', 'c2')];
conversationsStore.activeConversation = conversation('');
fetchMock.mockResolvedValue(
new Map([
['c2', { conv: conversation('a1', 'c2'), messages: linearMessages('c2') }],
[CONV_ID, { conv: conversation('a2a'), messages: branchedMessages() }]
])
);
const archive = vi
.spyOn(ConversationTransferService, 'downloadConversationsArchive')
.mockImplementation(() => {});
await conversationsStore.bulkExportConversations([CONV_ID, 'c2']);
expect(fetchMock).toHaveBeenCalledWith([CONV_ID, 'c2']);
expect(archive).toHaveBeenCalledTimes(1);
const payload = archive.mock.calls[0][0];
expect(payload.map((entry) => entry.conv.id)).toEqual([CONV_ID, 'c2']);
// Each entry carries its own database currNode.
expect(payload.map((entry) => entry.conv.currNode)).toEqual(['a2a', 'a1']);
expect(payload[1].messages.map((m: DatabaseMessage) => m.id)).toEqual(['root', 'u1', 'a1']);
archive.mockRestore();
});
});
describe('exported conversation branch pointer', () => {
it('carries the database currNode, so the import restores the current branch', () => {
// The user regenerated to create a2b, then switched back to the a2a branch,
// so the stored leaf is NOT the newest message.
const { imported, sessionLine } = roundTrip(conversation('a2a'));
expect(sessionLine.currNode).toBe('a2a');
expect(displayedIds(imported)).toEqual(['u1', 'a1', 'u2a', 'a2a']);
expect(imported.messages.map((m: DatabaseMessage) => m.id).sort()).toEqual([
'a1',
'a2a',
'a2b',
'root',
'u1',
'u2a',
'u2b'
]);
});
it('shows every branch on import when the cache entry exported an empty currNode', () => {
const { imported, sessionLine } = roundTrip(conversation(''));
expect(sessionLine.currNode).toBe('');
expect(displayedIds(imported)).toEqual(['root', 'u1', 'a1', 'u2a', 'a2a', 'u2b', 'a2b']);
});
});