chore: test deploy snapshot
This commit is contained in:
@@ -20,11 +20,22 @@ export type ChatShareTokenRoomMapItem = {
|
||||
contextLabel: string | null;
|
||||
contextDescription: string | null;
|
||||
notifyOffline: boolean;
|
||||
linkContext: ChatShareRoomLinkContext | null;
|
||||
createdAt: string | null;
|
||||
updatedAt: string | null;
|
||||
conversationUpdatedAt: string | null;
|
||||
};
|
||||
|
||||
export type ChatShareRoomLinkContext = {
|
||||
kind: 'linked-session';
|
||||
sourceSessionId: string;
|
||||
sourceRequestId: string;
|
||||
sourceTitle: string | null;
|
||||
sourceRequestPreview: string | null;
|
||||
sourceChatTypeLabel: string | null;
|
||||
linkedAt: string | null;
|
||||
};
|
||||
|
||||
function normalizeOptionalText(value: unknown) {
|
||||
if (typeof value !== 'string') {
|
||||
return null;
|
||||
@@ -72,6 +83,72 @@ function normalizeDateTime(value: unknown) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function parseChatShareRoomLinkContext(value: unknown) {
|
||||
if (typeof value !== 'string') {
|
||||
return null;
|
||||
}
|
||||
|
||||
const normalized = value.trim();
|
||||
|
||||
if (!normalized) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(normalized) as Record<string, unknown>;
|
||||
|
||||
if (parsed.kind !== 'linked-session') {
|
||||
return null;
|
||||
}
|
||||
|
||||
const sourceSessionId = normalizeRequiredText(parsed.sourceSessionId);
|
||||
const sourceRequestId = normalizeRequiredText(parsed.sourceRequestId);
|
||||
|
||||
if (!sourceSessionId || !sourceRequestId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
kind: 'linked-session',
|
||||
sourceSessionId,
|
||||
sourceRequestId,
|
||||
sourceTitle: normalizeOptionalText(parsed.sourceTitle),
|
||||
sourceRequestPreview: normalizeOptionalText(parsed.sourceRequestPreview),
|
||||
sourceChatTypeLabel: normalizeOptionalText(parsed.sourceChatTypeLabel),
|
||||
linkedAt: normalizeDateTime(parsed.linkedAt),
|
||||
} satisfies ChatShareRoomLinkContext;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function stringifyChatShareRoomLinkContext(value: ChatShareRoomLinkContext | null | undefined) {
|
||||
if (!value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (value.kind !== 'linked-session') {
|
||||
return null;
|
||||
}
|
||||
|
||||
const sourceSessionId = normalizeRequiredText(value.sourceSessionId);
|
||||
const sourceRequestId = normalizeRequiredText(value.sourceRequestId);
|
||||
|
||||
if (!sourceSessionId || !sourceRequestId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return JSON.stringify({
|
||||
kind: 'linked-session',
|
||||
sourceSessionId,
|
||||
sourceRequestId,
|
||||
sourceTitle: normalizeOptionalText(value.sourceTitle),
|
||||
sourceRequestPreview: normalizeOptionalText(value.sourceRequestPreview),
|
||||
sourceChatTypeLabel: normalizeOptionalText(value.sourceChatTypeLabel),
|
||||
linkedAt: normalizeDateTime(value.linkedAt),
|
||||
});
|
||||
}
|
||||
|
||||
function mapChatShareTokenRoomRow(row: Record<string, unknown>): ChatShareTokenRoomMapItem {
|
||||
return {
|
||||
tokenId: normalizeRequiredText(row.shared_resource_token_id),
|
||||
@@ -87,6 +164,7 @@ function mapChatShareTokenRoomRow(row: Record<string, unknown>): ChatShareTokenR
|
||||
contextLabel: normalizeOptionalText(row.context_label),
|
||||
contextDescription: normalizeOptionalText(row.context_description),
|
||||
notifyOffline: normalizeBoolean(row.notify_offline),
|
||||
linkContext: parseChatShareRoomLinkContext(row.link_context_json),
|
||||
createdAt: normalizeDateTime(row.created_at),
|
||||
updatedAt: normalizeDateTime(row.updated_at),
|
||||
conversationUpdatedAt: normalizeDateTime(row.conversation_updated_at),
|
||||
@@ -121,6 +199,7 @@ export async function ensureChatShareTokenRoomMapTable() {
|
||||
['is_default', (table) => table.boolean('is_default').notNullable().defaultTo(false)],
|
||||
['sort_order', (table) => table.integer('sort_order').notNullable().defaultTo(0)],
|
||||
['created_by_client_id', (table) => table.string('created_by_client_id', 120).nullable()],
|
||||
['link_context_json', (table) => table.text('link_context_json').nullable()],
|
||||
['archived_at', (table) => table.timestamp('archived_at', { useTz: true }).nullable().index()],
|
||||
['created_at', (table) => table.timestamp('created_at', { useTz: true }).notNullable().defaultTo(db.fn.now())],
|
||||
['updated_at', (table) => table.timestamp('updated_at', { useTz: true }).notNullable().defaultTo(db.fn.now())],
|
||||
@@ -164,6 +243,7 @@ export async function listChatShareTokenRoomMaps(tokenId: string) {
|
||||
'conversation.context_label',
|
||||
'conversation.context_description',
|
||||
'conversation.notify_offline',
|
||||
'room_map.link_context_json',
|
||||
'conversation.updated_at as conversation_updated_at',
|
||||
)
|
||||
.where({ 'room_map.shared_resource_token_id': normalizedTokenId })
|
||||
@@ -194,6 +274,7 @@ export async function upsertChatShareTokenRoomMap(args: {
|
||||
isDefault?: boolean;
|
||||
sortOrder?: number | null;
|
||||
createdByClientId?: string | null;
|
||||
linkContext?: ChatShareRoomLinkContext | null;
|
||||
}) {
|
||||
const normalizedTokenId = args.tokenId.trim();
|
||||
const normalizedSessionId = args.sessionId.trim();
|
||||
@@ -240,6 +321,10 @@ export async function upsertChatShareTokenRoomMap(args: {
|
||||
is_default: args.isDefault === true,
|
||||
sort_order: nextSortOrder,
|
||||
created_by_client_id: normalizeOptionalText(args.createdByClientId),
|
||||
link_context_json:
|
||||
args.linkContext === undefined
|
||||
? (current?.link_context_json ?? null)
|
||||
: stringifyChatShareRoomLinkContext(args.linkContext),
|
||||
archived_at: null,
|
||||
updated_at: db.fn.now(),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user