@@ -5,7 +5,7 @@ import * as Layer from "effect/Layer";
55import * as Option from "effect/Option" ;
66import * as Schema from "effect/Schema" ;
77import * as Struct from "effect/Struct" ;
8- import { ChatAttachment } from "@t3tools/contracts" ;
8+ import { ChatAttachment , TrimmedNonEmptyString } from "@t3tools/contracts" ;
99
1010import { toPersistenceSqlError } from "../Errors.ts" ;
1111import {
@@ -20,6 +20,7 @@ import {
2020const ProjectionThreadMessageDbRowSchema = ProjectionThreadMessage . mapFields (
2121 Struct . assign ( {
2222 isStreaming : Schema . Number ,
23+ actualModel : Schema . NullOr ( TrimmedNonEmptyString ) ,
2324 attachments : Schema . NullOr ( Schema . fromJsonString ( Schema . Array ( ChatAttachment ) ) ) ,
2425 } ) ,
2526) ;
@@ -33,6 +34,7 @@ function toProjectionThreadMessage(
3334 turnId : row . turnId ,
3435 role : row . role ,
3536 text : row . text ,
37+ ...( row . actualModel !== null ? { actualModel : row . actualModel } : { } ) ,
3638 isStreaming : row . isStreaming === 1 ,
3739 createdAt : row . createdAt ,
3840 updatedAt : row . updatedAt ,
@@ -55,6 +57,7 @@ const makeProjectionThreadMessageRepository = Effect.gen(function* () {
5557 turn_id,
5658 role,
5759 text,
60+ actual_model,
5861 attachments_json,
5962 is_streaming,
6063 created_at,
@@ -66,6 +69,14 @@ const makeProjectionThreadMessageRepository = Effect.gen(function* () {
6669 ${ row . turnId } ,
6770 ${ row . role } ,
6871 ${ row . text } ,
72+ COALESCE(
73+ ${ row . actualModel ?? null } ,
74+ (
75+ SELECT actual_model
76+ FROM projection_thread_messages
77+ WHERE message_id = ${ row . messageId }
78+ )
79+ ),
6980 COALESCE(
7081 ${ nextAttachmentsJson } ,
7182 (
@@ -84,6 +95,10 @@ const makeProjectionThreadMessageRepository = Effect.gen(function* () {
8495 turn_id = excluded.turn_id,
8596 role = excluded.role,
8697 text = excluded.text,
98+ actual_model = COALESCE(
99+ excluded.actual_model,
100+ projection_thread_messages.actual_model
101+ ),
87102 attachments_json = COALESCE(
88103 excluded.attachments_json,
89104 projection_thread_messages.attachments_json
@@ -106,6 +121,7 @@ const makeProjectionThreadMessageRepository = Effect.gen(function* () {
106121 turn_id AS "turnId",
107122 role,
108123 text,
124+ actual_model AS "actualModel",
109125 attachments_json AS "attachments",
110126 is_streaming AS "isStreaming",
111127 created_at AS "createdAt",
@@ -127,6 +143,7 @@ const makeProjectionThreadMessageRepository = Effect.gen(function* () {
127143 turn_id AS "turnId",
128144 role,
129145 text,
146+ actual_model AS "actualModel",
130147 attachments_json AS "attachments",
131148 is_streaming AS "isStreaming",
132149 created_at AS "createdAt",
0 commit comments