feat(server): persist node semantic context and retain CAD agent context
Add a semantic_context column to canvas_nodes (schema, sqlc queries, generated models, repository upserts) and thread SemanticContext through the domain node, API type, and mappers so CAD-derived context survives canvas saves. Treat agent text parts with textSource "cad-context" like settings: keep them for planning, memory, and image-generation prompts but exclude them from the persisted user-visible message copy. Add coverage for the CAD context visibility and mapper behavior. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -26,6 +26,20 @@ type AgentMessage struct {
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type AuthDeviceSession struct {
|
||||
ID string `json:"id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
DeviceType string `json:"device_type"`
|
||||
System string `json:"system"`
|
||||
Browser string `json:"browser"`
|
||||
Client string `json:"client"`
|
||||
UserAgent string `json:"user_agent"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
LastSeenAt pgtype.Timestamptz `json:"last_seen_at"`
|
||||
ExpiresAt pgtype.Timestamptz `json:"expires_at"`
|
||||
RevokedAt pgtype.Timestamptz `json:"revoked_at"`
|
||||
}
|
||||
|
||||
type AuthVerificationCode struct {
|
||||
ID string `json:"id"`
|
||||
Region string `json:"region"`
|
||||
@@ -58,38 +72,39 @@ type CanvasConnection struct {
|
||||
}
|
||||
|
||||
type CanvasNode struct {
|
||||
ID string `json:"id"`
|
||||
ProjectID string `json:"project_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
NodeType string `json:"node_type"`
|
||||
Title string `json:"title"`
|
||||
X float64 `json:"x"`
|
||||
Y float64 `json:"y"`
|
||||
Width float64 `json:"width"`
|
||||
Height float64 `json:"height"`
|
||||
Content string `json:"content"`
|
||||
Tone string `json:"tone"`
|
||||
Status string `json:"status"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
ParentID string `json:"parent_id"`
|
||||
LayerRole string `json:"layer_role"`
|
||||
FontSize float64 `json:"font_size"`
|
||||
FontFamily string `json:"font_family"`
|
||||
FontWeight string `json:"font_weight"`
|
||||
Color string `json:"color"`
|
||||
TextAlign string `json:"text_align"`
|
||||
LineHeight float64 `json:"line_height"`
|
||||
LetterSpacing float64 `json:"letter_spacing"`
|
||||
TextDecoration string `json:"text_decoration"`
|
||||
TextTransform string `json:"text_transform"`
|
||||
Opacity float64 `json:"opacity"`
|
||||
FillColor string `json:"fill_color"`
|
||||
StrokeColor string `json:"stroke_color"`
|
||||
StrokeWidth float64 `json:"stroke_width"`
|
||||
StrokeStyle string `json:"stroke_style"`
|
||||
FlipX bool `json:"flip_x"`
|
||||
FlipY bool `json:"flip_y"`
|
||||
Rotation float64 `json:"rotation"`
|
||||
ID string `json:"id"`
|
||||
ProjectID string `json:"project_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
NodeType string `json:"node_type"`
|
||||
Title string `json:"title"`
|
||||
X float64 `json:"x"`
|
||||
Y float64 `json:"y"`
|
||||
Width float64 `json:"width"`
|
||||
Height float64 `json:"height"`
|
||||
Content string `json:"content"`
|
||||
Tone string `json:"tone"`
|
||||
Status string `json:"status"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
ParentID string `json:"parent_id"`
|
||||
LayerRole string `json:"layer_role"`
|
||||
FontSize float64 `json:"font_size"`
|
||||
FontFamily string `json:"font_family"`
|
||||
FontWeight string `json:"font_weight"`
|
||||
Color string `json:"color"`
|
||||
TextAlign string `json:"text_align"`
|
||||
LineHeight float64 `json:"line_height"`
|
||||
LetterSpacing float64 `json:"letter_spacing"`
|
||||
TextDecoration string `json:"text_decoration"`
|
||||
TextTransform string `json:"text_transform"`
|
||||
Opacity float64 `json:"opacity"`
|
||||
FillColor string `json:"fill_color"`
|
||||
StrokeColor string `json:"stroke_color"`
|
||||
StrokeWidth float64 `json:"stroke_width"`
|
||||
StrokeStyle string `json:"stroke_style"`
|
||||
FlipX bool `json:"flip_x"`
|
||||
FlipY bool `json:"flip_y"`
|
||||
Rotation float64 `json:"rotation"`
|
||||
SemanticContext string `json:"semantic_context"`
|
||||
}
|
||||
|
||||
type CanvasSnapshot struct {
|
||||
|
||||
@@ -467,7 +467,7 @@ func (q *Queries) ListMessagesByProject(ctx context.Context, arg ListMessagesByP
|
||||
}
|
||||
|
||||
const listNodesByProject = `-- name: ListNodesByProject :many
|
||||
SELECT id, project_id, user_id, node_type, title, x, y, width, height, content, tone, status, sort_order, parent_id, layer_role, font_size, font_family, font_weight, color, text_align, line_height, letter_spacing, text_decoration, text_transform, opacity, fill_color, stroke_color, stroke_width, stroke_style, flip_x, flip_y, rotation
|
||||
SELECT id, project_id, user_id, node_type, title, x, y, width, height, content, tone, status, sort_order, parent_id, layer_role, font_size, font_family, font_weight, color, text_align, line_height, letter_spacing, text_decoration, text_transform, opacity, fill_color, stroke_color, stroke_width, stroke_style, flip_x, flip_y, rotation, semantic_context
|
||||
FROM canvas_nodes
|
||||
WHERE project_id = $1 AND user_id = $2
|
||||
ORDER BY sort_order ASC, id ASC
|
||||
@@ -520,6 +520,7 @@ func (q *Queries) ListNodesByProject(ctx context.Context, arg ListNodesByProject
|
||||
&i.FlipX,
|
||||
&i.FlipY,
|
||||
&i.Rotation,
|
||||
&i.SemanticContext,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -745,8 +746,8 @@ func (q *Queries) UpsertBrandKit(ctx context.Context, arg UpsertBrandKitParams)
|
||||
}
|
||||
|
||||
const upsertCanvasNode = `-- name: UpsertCanvasNode :exec
|
||||
INSERT INTO canvas_nodes (id, project_id, user_id, node_type, title, x, y, width, height, content, tone, status, sort_order, parent_id, layer_role, font_size, font_family, font_weight, color, text_align, line_height, letter_spacing, text_decoration, text_transform, opacity, fill_color, stroke_color, stroke_width, stroke_style, flip_x, flip_y, rotation)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32)
|
||||
INSERT INTO canvas_nodes (id, project_id, user_id, node_type, title, x, y, width, height, content, tone, status, sort_order, parent_id, layer_role, font_size, font_family, font_weight, color, text_align, line_height, letter_spacing, text_decoration, text_transform, opacity, fill_color, stroke_color, stroke_width, stroke_style, flip_x, flip_y, rotation, semantic_context)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33)
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
project_id = EXCLUDED.project_id,
|
||||
user_id = EXCLUDED.user_id,
|
||||
@@ -778,42 +779,44 @@ ON CONFLICT (id) DO UPDATE SET
|
||||
stroke_style = EXCLUDED.stroke_style,
|
||||
flip_x = EXCLUDED.flip_x,
|
||||
flip_y = EXCLUDED.flip_y,
|
||||
rotation = EXCLUDED.rotation
|
||||
rotation = EXCLUDED.rotation,
|
||||
semantic_context = EXCLUDED.semantic_context
|
||||
`
|
||||
|
||||
type UpsertCanvasNodeParams struct {
|
||||
ID string `json:"id"`
|
||||
ProjectID string `json:"project_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
NodeType string `json:"node_type"`
|
||||
Title string `json:"title"`
|
||||
X float64 `json:"x"`
|
||||
Y float64 `json:"y"`
|
||||
Width float64 `json:"width"`
|
||||
Height float64 `json:"height"`
|
||||
Content string `json:"content"`
|
||||
Tone string `json:"tone"`
|
||||
Status string `json:"status"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
ParentID string `json:"parent_id"`
|
||||
LayerRole string `json:"layer_role"`
|
||||
FontSize float64 `json:"font_size"`
|
||||
FontFamily string `json:"font_family"`
|
||||
FontWeight string `json:"font_weight"`
|
||||
Color string `json:"color"`
|
||||
TextAlign string `json:"text_align"`
|
||||
LineHeight float64 `json:"line_height"`
|
||||
LetterSpacing float64 `json:"letter_spacing"`
|
||||
TextDecoration string `json:"text_decoration"`
|
||||
TextTransform string `json:"text_transform"`
|
||||
Opacity float64 `json:"opacity"`
|
||||
FillColor string `json:"fill_color"`
|
||||
StrokeColor string `json:"stroke_color"`
|
||||
StrokeWidth float64 `json:"stroke_width"`
|
||||
StrokeStyle string `json:"stroke_style"`
|
||||
FlipX bool `json:"flip_x"`
|
||||
FlipY bool `json:"flip_y"`
|
||||
Rotation float64 `json:"rotation"`
|
||||
ID string `json:"id"`
|
||||
ProjectID string `json:"project_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
NodeType string `json:"node_type"`
|
||||
Title string `json:"title"`
|
||||
X float64 `json:"x"`
|
||||
Y float64 `json:"y"`
|
||||
Width float64 `json:"width"`
|
||||
Height float64 `json:"height"`
|
||||
Content string `json:"content"`
|
||||
Tone string `json:"tone"`
|
||||
Status string `json:"status"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
ParentID string `json:"parent_id"`
|
||||
LayerRole string `json:"layer_role"`
|
||||
FontSize float64 `json:"font_size"`
|
||||
FontFamily string `json:"font_family"`
|
||||
FontWeight string `json:"font_weight"`
|
||||
Color string `json:"color"`
|
||||
TextAlign string `json:"text_align"`
|
||||
LineHeight float64 `json:"line_height"`
|
||||
LetterSpacing float64 `json:"letter_spacing"`
|
||||
TextDecoration string `json:"text_decoration"`
|
||||
TextTransform string `json:"text_transform"`
|
||||
Opacity float64 `json:"opacity"`
|
||||
FillColor string `json:"fill_color"`
|
||||
StrokeColor string `json:"stroke_color"`
|
||||
StrokeWidth float64 `json:"stroke_width"`
|
||||
StrokeStyle string `json:"stroke_style"`
|
||||
FlipX bool `json:"flip_x"`
|
||||
FlipY bool `json:"flip_y"`
|
||||
Rotation float64 `json:"rotation"`
|
||||
SemanticContext string `json:"semantic_context"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertCanvasNode(ctx context.Context, arg UpsertCanvasNodeParams) error {
|
||||
@@ -850,6 +853,7 @@ func (q *Queries) UpsertCanvasNode(ctx context.Context, arg UpsertCanvasNodePara
|
||||
arg.FlipX,
|
||||
arg.FlipY,
|
||||
arg.Rotation,
|
||||
arg.SemanticContext,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -189,38 +189,39 @@ func (r *ProjectRepository) Save(ctx context.Context, project design.Project) er
|
||||
|
||||
for index, node := range project.Nodes {
|
||||
if err := q.UpsertCanvasNode(ctx, sqlcdb.UpsertCanvasNodeParams{
|
||||
ID: node.ID,
|
||||
ProjectID: project.ID,
|
||||
UserID: toPGUUID(project.UserID),
|
||||
NodeType: string(node.Type),
|
||||
Title: node.Title,
|
||||
X: node.X,
|
||||
Y: node.Y,
|
||||
Width: node.Width,
|
||||
Height: node.Height,
|
||||
Content: node.Content,
|
||||
Tone: node.Tone,
|
||||
Status: node.Status,
|
||||
SortOrder: int32(index),
|
||||
ParentID: node.ParentID,
|
||||
LayerRole: node.LayerRole,
|
||||
FontSize: node.FontSize,
|
||||
FontFamily: node.FontFamily,
|
||||
FontWeight: node.FontWeight,
|
||||
Color: node.Color,
|
||||
TextAlign: node.TextAlign,
|
||||
LineHeight: node.LineHeight,
|
||||
LetterSpacing: node.LetterSpacing,
|
||||
TextDecoration: node.TextDecoration,
|
||||
TextTransform: node.TextTransform,
|
||||
Opacity: node.Opacity,
|
||||
FillColor: node.FillColor,
|
||||
StrokeColor: node.StrokeColor,
|
||||
StrokeWidth: node.StrokeWidth,
|
||||
StrokeStyle: node.StrokeStyle,
|
||||
FlipX: node.FlipX,
|
||||
FlipY: node.FlipY,
|
||||
Rotation: node.Rotation,
|
||||
ID: node.ID,
|
||||
ProjectID: project.ID,
|
||||
UserID: toPGUUID(project.UserID),
|
||||
NodeType: string(node.Type),
|
||||
Title: node.Title,
|
||||
X: node.X,
|
||||
Y: node.Y,
|
||||
Width: node.Width,
|
||||
Height: node.Height,
|
||||
Content: node.Content,
|
||||
Tone: node.Tone,
|
||||
Status: node.Status,
|
||||
SortOrder: int32(index),
|
||||
ParentID: node.ParentID,
|
||||
LayerRole: node.LayerRole,
|
||||
SemanticContext: node.SemanticContext,
|
||||
FontSize: node.FontSize,
|
||||
FontFamily: node.FontFamily,
|
||||
FontWeight: node.FontWeight,
|
||||
Color: node.Color,
|
||||
TextAlign: node.TextAlign,
|
||||
LineHeight: node.LineHeight,
|
||||
LetterSpacing: node.LetterSpacing,
|
||||
TextDecoration: node.TextDecoration,
|
||||
TextTransform: node.TextTransform,
|
||||
Opacity: node.Opacity,
|
||||
FillColor: node.FillColor,
|
||||
StrokeColor: node.StrokeColor,
|
||||
StrokeWidth: node.StrokeWidth,
|
||||
StrokeStyle: node.StrokeStyle,
|
||||
FlipX: node.FlipX,
|
||||
FlipY: node.FlipY,
|
||||
Rotation: node.Rotation,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -509,35 +510,36 @@ func mapNodes(rows []sqlcdb.CanvasNode) []design.Node {
|
||||
nodes := make([]design.Node, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
nodes = append(nodes, design.Node{
|
||||
ID: row.ID,
|
||||
Type: design.NodeType(row.NodeType),
|
||||
Title: row.Title,
|
||||
X: row.X,
|
||||
Y: row.Y,
|
||||
Width: row.Width,
|
||||
Height: row.Height,
|
||||
Content: row.Content,
|
||||
Tone: row.Tone,
|
||||
Status: row.Status,
|
||||
ParentID: row.ParentID,
|
||||
LayerRole: row.LayerRole,
|
||||
FontSize: row.FontSize,
|
||||
FontFamily: row.FontFamily,
|
||||
FontWeight: row.FontWeight,
|
||||
Color: row.Color,
|
||||
TextAlign: row.TextAlign,
|
||||
LineHeight: row.LineHeight,
|
||||
LetterSpacing: row.LetterSpacing,
|
||||
TextDecoration: row.TextDecoration,
|
||||
TextTransform: row.TextTransform,
|
||||
Opacity: row.Opacity,
|
||||
FillColor: row.FillColor,
|
||||
StrokeColor: row.StrokeColor,
|
||||
StrokeWidth: row.StrokeWidth,
|
||||
StrokeStyle: row.StrokeStyle,
|
||||
FlipX: row.FlipX,
|
||||
FlipY: row.FlipY,
|
||||
Rotation: row.Rotation,
|
||||
ID: row.ID,
|
||||
Type: design.NodeType(row.NodeType),
|
||||
Title: row.Title,
|
||||
X: row.X,
|
||||
Y: row.Y,
|
||||
Width: row.Width,
|
||||
Height: row.Height,
|
||||
Content: row.Content,
|
||||
Tone: row.Tone,
|
||||
Status: row.Status,
|
||||
ParentID: row.ParentID,
|
||||
LayerRole: row.LayerRole,
|
||||
SemanticContext: row.SemanticContext,
|
||||
FontSize: row.FontSize,
|
||||
FontFamily: row.FontFamily,
|
||||
FontWeight: row.FontWeight,
|
||||
Color: row.Color,
|
||||
TextAlign: row.TextAlign,
|
||||
LineHeight: row.LineHeight,
|
||||
LetterSpacing: row.LetterSpacing,
|
||||
TextDecoration: row.TextDecoration,
|
||||
TextTransform: row.TextTransform,
|
||||
Opacity: row.Opacity,
|
||||
FillColor: row.FillColor,
|
||||
StrokeColor: row.StrokeColor,
|
||||
StrokeWidth: row.StrokeWidth,
|
||||
StrokeStyle: row.StrokeStyle,
|
||||
FlipX: row.FlipX,
|
||||
FlipY: row.FlipY,
|
||||
Rotation: row.Rotation,
|
||||
})
|
||||
}
|
||||
return nodes
|
||||
|
||||
@@ -114,7 +114,7 @@ SET thumbnail = $3,
|
||||
WHERE id = $1 AND user_id = $2;
|
||||
|
||||
-- name: ListNodesByProject :many
|
||||
SELECT id, project_id, user_id, node_type, title, x, y, width, height, content, tone, status, sort_order, parent_id, layer_role, font_size, font_family, font_weight, color, text_align, line_height, letter_spacing, text_decoration, text_transform, opacity, fill_color, stroke_color, stroke_width, stroke_style, flip_x, flip_y, rotation
|
||||
SELECT id, project_id, user_id, node_type, title, x, y, width, height, content, tone, status, sort_order, parent_id, layer_role, font_size, font_family, font_weight, color, text_align, line_height, letter_spacing, text_decoration, text_transform, opacity, fill_color, stroke_color, stroke_width, stroke_style, flip_x, flip_y, rotation, semantic_context
|
||||
FROM canvas_nodes
|
||||
WHERE project_id = $1 AND user_id = $2
|
||||
ORDER BY sort_order ASC, id ASC;
|
||||
@@ -124,8 +124,8 @@ DELETE FROM canvas_nodes
|
||||
WHERE project_id = $1 AND user_id = $2;
|
||||
|
||||
-- name: UpsertCanvasNode :exec
|
||||
INSERT INTO canvas_nodes (id, project_id, user_id, node_type, title, x, y, width, height, content, tone, status, sort_order, parent_id, layer_role, font_size, font_family, font_weight, color, text_align, line_height, letter_spacing, text_decoration, text_transform, opacity, fill_color, stroke_color, stroke_width, stroke_style, flip_x, flip_y, rotation)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32)
|
||||
INSERT INTO canvas_nodes (id, project_id, user_id, node_type, title, x, y, width, height, content, tone, status, sort_order, parent_id, layer_role, font_size, font_family, font_weight, color, text_align, line_height, letter_spacing, text_decoration, text_transform, opacity, fill_color, stroke_color, stroke_width, stroke_style, flip_x, flip_y, rotation, semantic_context)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33)
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
project_id = EXCLUDED.project_id,
|
||||
user_id = EXCLUDED.user_id,
|
||||
@@ -157,7 +157,8 @@ ON CONFLICT (id) DO UPDATE SET
|
||||
stroke_style = EXCLUDED.stroke_style,
|
||||
flip_x = EXCLUDED.flip_x,
|
||||
flip_y = EXCLUDED.flip_y,
|
||||
rotation = EXCLUDED.rotation;
|
||||
rotation = EXCLUDED.rotation,
|
||||
semantic_context = EXCLUDED.semantic_context;
|
||||
|
||||
-- name: ListConnectionsByProject :many
|
||||
SELECT id, project_id, user_id, from_node_id, to_node_id
|
||||
|
||||
@@ -194,7 +194,8 @@ CREATE TABLE IF NOT EXISTS canvas_nodes (
|
||||
stroke_style TEXT NOT NULL DEFAULT '',
|
||||
flip_x BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
flip_y BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
rotation DOUBLE PRECISION NOT NULL DEFAULT 0
|
||||
rotation DOUBLE PRECISION NOT NULL DEFAULT 0,
|
||||
semantic_context TEXT NOT NULL DEFAULT ''
|
||||
);
|
||||
|
||||
ALTER TABLE canvas_nodes ADD COLUMN IF NOT EXISTS user_id UUID;
|
||||
@@ -225,6 +226,7 @@ ALTER TABLE canvas_nodes ADD COLUMN IF NOT EXISTS stroke_style TEXT NOT NULL DEF
|
||||
ALTER TABLE canvas_nodes ADD COLUMN IF NOT EXISTS flip_x BOOLEAN NOT NULL DEFAULT FALSE;
|
||||
ALTER TABLE canvas_nodes ADD COLUMN IF NOT EXISTS flip_y BOOLEAN NOT NULL DEFAULT FALSE;
|
||||
ALTER TABLE canvas_nodes ADD COLUMN IF NOT EXISTS rotation DOUBLE PRECISION NOT NULL DEFAULT 0;
|
||||
ALTER TABLE canvas_nodes ADD COLUMN IF NOT EXISTS semantic_context TEXT NOT NULL DEFAULT '';
|
||||
|
||||
CREATE INDEX IF NOT EXISTS canvas_nodes_project_id_idx ON canvas_nodes(project_id);
|
||||
CREATE INDEX IF NOT EXISTS canvas_nodes_user_project_idx ON canvas_nodes(user_id, project_id);
|
||||
|
||||
Reference in New Issue
Block a user