Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 032cac3

Browse files
committed
refactor: make project memories generic by dropping the type enum
Memories keep a name, one-line description, and body. The guidance still tells the agent what kinds of facts are worth saving, without asking it to categorize them.
1 parent d07af59 commit 032cac3

30 files changed

Lines changed: 126 additions & 425 deletions

coderd/apidoc/docs.go

Lines changed: 1 addition & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 1 addition & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/chat_project_memories.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (api *API) postChatProjectMemory(rw http.ResponseWriter, r *http.Request) {
6666
if !httpapi.Read(ctx, rw, r, &req) {
6767
return
6868
}
69-
normalized, resp := validateChatProjectMemory(req.Type, req.Name, req.Description, req.Body)
69+
normalized, resp := validateChatProjectMemory(req.Name, req.Description, req.Body)
7070
if resp != nil {
7171
httpapi.Write(ctx, rw, http.StatusBadRequest, *resp)
7272
return
@@ -82,7 +82,7 @@ func (api *API) postChatProjectMemory(rw http.ResponseWriter, r *http.Request) {
8282
}
8383
aReq, commit := audit.InitRequest[database.ChatProjectMemory](rw, &audit.RequestParams{Audit: *api.Auditor.Load(), Log: api.Logger, Request: r, Action: database.AuditActionCreate, OrganizationID: project.OrganizationID})
8484
defer commit()
85-
memory, err := api.Database.InsertChatProjectMemory(ctx, database.InsertChatProjectMemoryParams{ID: uuid.NullUUID{}, ProjectID: project.ID, OrganizationID: project.OrganizationID, Type: database.ChatProjectMemoryType(normalized.Type), Name: normalized.Name, Description: normalized.Description, Body: normalized.Body, SourceChatID: uuid.NullUUID{}, CreatedBy: apiKey.UserID})
85+
memory, err := api.Database.InsertChatProjectMemory(ctx, database.InsertChatProjectMemoryParams{ID: uuid.NullUUID{}, ProjectID: project.ID, OrganizationID: project.OrganizationID, Name: normalized.Name, Description: normalized.Description, Body: normalized.Body, SourceChatID: uuid.NullUUID{}, CreatedBy: apiKey.UserID})
8686
if database.IsUniqueViolation(err) {
8787
httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{Message: "A chat project memory with this name already exists."})
8888
return
@@ -148,10 +148,6 @@ func (api *API) patchChatProjectMemory(rw http.ResponseWriter, r *http.Request)
148148
if !httpapi.Read(ctx, rw, r, &req) {
149149
return
150150
}
151-
memoryType := codersdk.ChatProjectMemoryType(memory.Type)
152-
if req.Type != nil {
153-
memoryType = *req.Type
154-
}
155151
name := memory.Name
156152
if req.Name != nil {
157153
name = *req.Name
@@ -164,15 +160,15 @@ func (api *API) patchChatProjectMemory(rw http.ResponseWriter, r *http.Request)
164160
if req.Body != nil {
165161
body = *req.Body
166162
}
167-
normalized, resp := validateChatProjectMemory(memoryType, name, description, body)
163+
normalized, resp := validateChatProjectMemory(name, description, body)
168164
if resp != nil {
169165
httpapi.Write(ctx, rw, http.StatusBadRequest, *resp)
170166
return
171167
}
172168
aReq, commit := audit.InitRequest[database.ChatProjectMemory](rw, &audit.RequestParams{Audit: *api.Auditor.Load(), Log: api.Logger, Request: r, Action: database.AuditActionWrite, OrganizationID: project.OrganizationID})
173169
defer commit()
174170
aReq.Old = memory
175-
updated, err := api.Database.UpdateChatProjectMemoryByID(ctx, database.UpdateChatProjectMemoryByIDParams{ID: memory.ID, Type: database.ChatProjectMemoryType(normalized.Type), Name: normalized.Name, Description: normalized.Description, Body: normalized.Body})
171+
updated, err := api.Database.UpdateChatProjectMemoryByID(ctx, database.UpdateChatProjectMemoryByIDParams{ID: memory.ID, Name: normalized.Name, Description: normalized.Description, Body: normalized.Body})
176172
if database.IsUniqueViolation(err) {
177173
httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{Message: "A chat project memory with this name already exists."})
178174
return
@@ -222,28 +218,24 @@ func (api *API) deleteChatProjectMemory(rw http.ResponseWriter, r *http.Request)
222218

223219
type normalizedChatProjectMemory struct {
224220
Name string
225-
Type codersdk.ChatProjectMemoryType
226221
Description string
227222
Body string
228223
}
229224

230-
func validateChatProjectMemory(memoryType codersdk.ChatProjectMemoryType, name, description, body string) (normalizedChatProjectMemory, *codersdk.Response) {
225+
func validateChatProjectMemory(name, description, body string) (normalizedChatProjectMemory, *codersdk.Response) {
231226
name = strings.ToLower(strings.TrimSpace(name))
232227
description = chattool.NormalizeProjectMemoryText(description)
233228
body = chattool.NormalizeProjectMemoryText(body)
234229
if err := chattool.ValidateProjectMemoryName(name); err != nil {
235230
return normalizedChatProjectMemory{}, &codersdk.Response{Message: err.Error()}
236231
}
237-
if !database.ChatProjectMemoryType(memoryType).Valid() {
238-
return normalizedChatProjectMemory{}, &codersdk.Response{Message: "Invalid chat project memory type."}
239-
}
240232
if description == "" || utf8.RuneCountInString(description) > chattool.MaxProjectMemoryDescriptionChars {
241233
return normalizedChatProjectMemory{}, &codersdk.Response{Message: "description must be at most 150 characters."}
242234
}
243235
if body == "" || len(body) > chattool.MaxProjectMemoryBodyBytes {
244236
return normalizedChatProjectMemory{}, &codersdk.Response{Message: "body must be at most 8192 bytes."}
245237
}
246-
return normalizedChatProjectMemory{Name: name, Type: memoryType, Description: description, Body: body}, nil
238+
return normalizedChatProjectMemory{Name: name, Description: description, Body: body}, nil
247239
}
248240

249241
func rbacMemoryObject(organizationID uuid.UUID) database.ChatProjectMemory {

coderd/chat_project_memories_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ func TestChatProjectMemoriesCRUD(t *testing.T) {
2222
project := createChatProject(t, client, firstUser.OrganizationID, "Memory Project")
2323

2424
created, err := client.CreateChatProjectMemory(ctx, project.ID, codersdk.CreateChatProjectMemoryRequest{
25-
Type: codersdk.ChatProjectMemoryTypeProject,
2625
Name: "release-process",
2726
Description: "Release process notes",
2827
Body: "Use the release checklist before tagging.",
@@ -48,7 +47,6 @@ func TestChatProjectMemoriesCRUD(t *testing.T) {
4847
require.Equal(t, updatedDescription, updated.Description)
4948

5049
_, err = client.CreateChatProjectMemory(ctx, project.ID, codersdk.CreateChatProjectMemoryRequest{
51-
Type: codersdk.ChatProjectMemoryTypeProject,
5250
Name: "release-process",
5351
Description: "Duplicate",
5452
Body: "Duplicate body.",
@@ -84,14 +82,12 @@ func TestChatProjectMemoryCap(t *testing.T) {
8482
OrganizationID: firstUser.OrganizationID,
8583
CreatedBy: firstUser.UserID,
8684
Name: "memory-" + uuid.NewString() + string(rune('a'+i%26)),
87-
Type: database.ChatProjectMemoryTypeProject,
8885
Description: "Seeded memory",
8986
Body: "Seeded durable memory.",
9087
})
9188
}
9289

9390
_, err := client.CreateChatProjectMemory(ctx, project.ID, codersdk.CreateChatProjectMemoryRequest{
94-
Type: codersdk.ChatProjectMemoryTypeProject,
9591
Name: "one-too-many",
9692
Description: "Too many memories",
9793
Body: "This should be rejected.",

coderd/database/db2sdk/db2sdk.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1856,7 +1856,6 @@ func convertChatProjectMemory(memory database.ChatProjectMemory, createdByUserna
18561856
ID: memory.ID,
18571857
ProjectID: memory.ProjectID,
18581858
OrganizationID: memory.OrganizationID,
1859-
Type: codersdk.ChatProjectMemoryType(memory.Type),
18601859
Name: memory.Name,
18611860
Description: memory.Description,
18621861
Body: memory.Body,

coderd/database/dbgen/dbgen.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ func ChatProjectMemory(t testing.TB, db database.Store, seed database.ChatProjec
103103
ID: uuid.NullUUID{UUID: seed.ID, Valid: seed.ID != uuid.Nil},
104104
ProjectID: takeFirst(seed.ProjectID, uuid.New()),
105105
OrganizationID: takeFirst(seed.OrganizationID, uuid.New()),
106-
Type: takeFirst(seed.Type, database.ChatProjectMemoryTypeProject),
107106
Name: takeFirst(seed.Name, testutil.GetRandomName(t)),
108107
Description: seed.Description,
109108
Body: seed.Body,

coderd/database/dump.sql

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/migrations/000595_chat_project_memories.down.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ DROP TABLE chat_project_memory_cursors;
33
DROP INDEX idx_chat_project_memories_project_updated_at;
44
DROP INDEX idx_chat_project_memories_project_lower_name;
55
DROP TABLE chat_project_memories;
6-
DROP TYPE chat_project_memory_type;

coderd/database/migrations/000595_chat_project_memories.up.sql

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ ALTER TYPE api_key_scope ADD VALUE IF NOT EXISTS 'chat_project_memory:read';
66
ALTER TYPE api_key_scope ADD VALUE IF NOT EXISTS 'chat_project_memory:update';
77
ALTER TYPE api_key_scope ADD VALUE IF NOT EXISTS 'chat_project_memory:delete';
88

9-
CREATE TYPE chat_project_memory_type AS ENUM ('user', 'feedback', 'project', 'reference');
10-
119
CREATE TABLE chat_project_memories (
1210
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
1311
project_id uuid NOT NULL REFERENCES chat_projects(id) ON DELETE CASCADE,
1412
organization_id uuid NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
15-
type chat_project_memory_type NOT NULL,
1613
name text NOT NULL,
1714
description text NOT NULL,
1815
body text NOT NULL,

coderd/database/migrations/testdata/fixtures/000595_chat_project_memories.up.sql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ INSERT INTO chat_project_memories (
22
id,
33
project_id,
44
organization_id,
5-
type,
65
name,
76
description,
87
body,
@@ -12,7 +11,6 @@ VALUES (
1211
'59500000-0000-4000-8000-000000000001',
1312
'59400000-0000-4000-8000-000000000001',
1413
'bb640d07-ca8a-4869-b6bc-ae61ebb2fda1',
15-
'project',
1614
'fixture-memory',
1715
'Fixture project memory.',
1816
'This memory exists for migration fixtures.',

0 commit comments

Comments
 (0)