@@ -2,7 +2,6 @@ import { trace } from '@opentelemetry/api'
22import { db } from '@sim/db'
33import {
44 chat as chatTable ,
5- copilotChats ,
65 customTools as customToolsTable ,
76 document ,
87 folder as folderTable ,
@@ -17,7 +16,7 @@ import {
1716} from '@sim/db/schema'
1817import { createLogger } from '@sim/logger'
1918import { toError } from '@sim/utils/errors'
20- import { and , desc , eq , inArray , isNotNull , isNull , or , sql } from 'drizzle-orm'
19+ import { and , desc , eq , inArray , isNotNull , isNull , or } from 'drizzle-orm'
2120import { listApiKeys } from '@/lib/api-key/service'
2221import {
2322 buildWorkspaceContextMd ,
@@ -79,8 +78,6 @@ import {
7978 serializeRecentExecutions ,
8079 serializeSkill ,
8180 serializeTableMeta ,
82- serializeTaskChat ,
83- serializeTaskSession ,
8481 serializeTriggerOverview ,
8582 serializeTriggerSchema ,
8683 serializeVersions ,
@@ -521,8 +518,6 @@ function getStaticComponentFiles(): Map<string, string> {
521518 * files/{name} (workspace file leaf; dynamic content on read)
522519 * files/{path}/{name}/style (dynamic — style extraction for .docx/.pptx/.pdf)
523520 * files/{path}/{name}/compiled-check (dynamic — compile generated source / validate diagrams, returns {ok,error?})
524- * tasks/{title}/session.md
525- * tasks/{title}/chat.json
526521 * custom-tools/{name}.json
527522 * environment/credentials.json
528523 * environment/api-keys.json
@@ -777,10 +772,6 @@ export class WorkspaceVFS {
777772 timed ( 'workspace_row' , getWorkspaceWithOwner ( workspaceId ) ) ,
778773 timed ( 'members' , getUsersWithPermissions ( workspaceId ) ) ,
779774 permissionConfigPromise ,
780- // Writes tasks/ files only — WORKSPACE.md has no Tasks section
781- // (recent chats reorder every turn and would bust the cached
782- // prompt prefix), so nothing is destructured from this one.
783- timed ( 'tasks' , this . materializeTasks ( workspaceId , userId ) ) ,
784775 ] )
785776
786777 const workspaceMdData = {
@@ -2116,89 +2107,6 @@ export class WorkspaceVFS {
21162107 }
21172108 }
21182109
2119- /**
2120- * Materialize mothership task chats as browsable conversation files under
2121- * `tasks/{title}/`. Nothing is returned: the inventory deliberately has no
2122- * Tasks section, so these files are reached through glob/read only.
2123- */
2124- private async materializeTasks ( workspaceId : string , userId : string ) : Promise < void > {
2125- try {
2126- const taskRows = await db
2127- . select ( {
2128- id : copilotChats . id ,
2129- title : copilotChats . title ,
2130- messageCount : sql < number > `COALESCE((
2131- SELECT COUNT(*) FROM copilot_messages cm
2132- WHERE cm.chat_id = ${ copilotChats . id } AND cm.deleted_at IS NULL
2133- ), 0)` ,
2134- messages : sql < unknown [ ] > `COALESCE((
2135- SELECT jsonb_agg(
2136- jsonb_build_object(
2137- 'role', cm.content->>'role',
2138- 'content', cm.content->'content',
2139- 'contentBlocks', COALESCE((
2140- SELECT jsonb_agg(jsonb_build_object('type', 'text', 'content', b.value->'content') ORDER BY b.ord)
2141- FROM jsonb_array_elements(
2142- CASE WHEN jsonb_typeof(cm.content->'contentBlocks') = 'array'
2143- THEN cm.content->'contentBlocks'
2144- ELSE '[]'::jsonb
2145- END
2146- ) WITH ORDINALITY AS b(value, ord)
2147- WHERE b.value->>'type' = 'text'
2148- ), '[]'::jsonb)
2149- )
2150- ORDER BY cm.seq ASC NULLS LAST, cm.created_at ASC, cm.id ASC
2151- )
2152- FROM copilot_messages cm
2153- WHERE cm.chat_id = ${ copilotChats . id }
2154- AND cm.deleted_at IS NULL
2155- AND cm.content->>'role' IN ('user', 'assistant')
2156- ), '[]'::jsonb)` ,
2157- createdAt : copilotChats . createdAt ,
2158- updatedAt : copilotChats . updatedAt ,
2159- } )
2160- . from ( copilotChats )
2161- . where (
2162- and (
2163- eq ( copilotChats . workspaceId , workspaceId ) ,
2164- eq ( copilotChats . userId , userId ) ,
2165- eq ( copilotChats . type , 'mothership' ) ,
2166- isNull ( copilotChats . deletedAt )
2167- )
2168- )
2169- . orderBy ( desc ( copilotChats . updatedAt ) )
2170- . limit ( 5 )
2171-
2172- for ( const task of taskRows ) {
2173- const title = task . title || 'Untitled task'
2174- const safeName = sanitizeName ( title )
2175- const prefix = `tasks/${ safeName } /`
2176- const messages = Array . isArray ( task . messages ) ? task . messages : [ ]
2177- const messageCount = Number ( task . messageCount ) || 0
2178-
2179- this . files . set (
2180- `${ prefix } session.md` ,
2181- serializeTaskSession ( {
2182- id : task . id ,
2183- title,
2184- messageCount,
2185- createdAt : task . createdAt ,
2186- updatedAt : task . updatedAt ,
2187- } )
2188- )
2189-
2190- if ( messages . length > 0 ) {
2191- this . files . set ( `${ prefix } chat.json` , serializeTaskChat ( messages ) )
2192- }
2193- }
2194- } catch ( err ) {
2195- logger . warn ( 'Failed to materialize tasks' , {
2196- workspaceId,
2197- error : toError ( err ) . message ,
2198- } )
2199- }
2200- }
2201-
22022110 private async materializeRecentlyDeleted ( workspaceId : string , userId : string ) : Promise < void > {
22032111 try {
22042112 const [
0 commit comments