Skip to content

Commit 17c452b

Browse files
authored
Merge pull request #16 from Ignite-Solutions-Group/devbrain-fix-hash-and-casing
fix: persist contentHash on append and normalize response casing
2 parents fc25079 + a83aace commit 17c452b

2 files changed

Lines changed: 44 additions & 39 deletions

File tree

src/DevBrain.Functions/Services/CosmosDocumentStore.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,15 +306,18 @@ public async Task<BrainDocument> AppendAsync(
306306

307307
var (existing, etag) = read.Value;
308308

309+
var mergedContent = existing.Content + separator + content;
309310
var merged = new BrainDocument
310311
{
311312
Id = existing.Id,
312313
Key = existing.Key,
313314
Project = existing.Project,
314-
Content = existing.Content + separator + content,
315+
Content = mergedContent,
315316
Tags = UnionTags(existing.Tags, tags),
316317
UpdatedAt = DateTimeOffset.UtcNow,
317-
UpdatedBy = updatedBy
318+
UpdatedBy = updatedBy,
319+
ContentHash = ComputeSha256(mergedContent),
320+
ContentLength = mergedContent.Length
318321
};
319322

320323
try

src/DevBrain.Functions/Tools/DocumentTools.cs

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ public async Task<string> GetDocumentMetadata(
9797

9898
return JsonSerializer.Serialize(new
9999
{
100-
document.Key,
101-
document.Project,
102-
document.Tags,
103-
document.UpdatedAt,
104-
document.UpdatedBy,
105-
document.ContentHash,
106-
document.ContentLength
100+
key = document.Key,
101+
project = document.Project,
102+
tags = document.Tags,
103+
updatedAt = document.UpdatedAt,
104+
updatedBy = document.UpdatedBy,
105+
contentHash = document.ContentHash,
106+
contentLength = document.ContentLength
107107
});
108108
}
109109

@@ -154,8 +154,8 @@ public async Task<string> CompareDocument(
154154
storedContentHash = document.ContentHash,
155155
storedContentLength = document.ContentLength,
156156
candidateHash,
157-
document.UpdatedAt,
158-
document.UpdatedBy
157+
updatedAt = document.UpdatedAt,
158+
updatedBy = document.UpdatedBy
159159
});
160160
}
161161

@@ -174,17 +174,17 @@ public async Task<string> ListDocuments(
174174
{
175175
return JsonSerializer.Serialize(new[]
176176
{
177-
new { documents[0].Key, documents[0].Content }
177+
new { key = documents[0].Key, content = documents[0].Content }
178178
});
179179
}
180180

181181
var projection = documents.Select(d => new
182182
{
183-
d.Key,
184-
d.Tags,
185-
d.UpdatedAt,
186-
d.UpdatedBy,
187-
d.Project
183+
key = d.Key,
184+
tags = d.Tags,
185+
updatedAt = d.UpdatedAt,
186+
updatedBy = d.UpdatedBy,
187+
project = d.Project
188188
});
189189

190190
return JsonSerializer.Serialize(projection);
@@ -258,12 +258,13 @@ public async Task<string> AppendDocument(
258258

259259
return JsonSerializer.Serialize(new
260260
{
261-
saved.Key,
262-
saved.Project,
263-
saved.Tags,
264-
saved.UpdatedAt,
265-
saved.UpdatedBy,
266-
ContentLength = saved.Content.Length
261+
key = saved.Key,
262+
project = saved.Project,
263+
tags = saved.Tags,
264+
updatedAt = saved.UpdatedAt,
265+
updatedBy = saved.UpdatedBy,
266+
contentHash = saved.ContentHash,
267+
contentLength = saved.Content.Length
267268
});
268269
}
269270
catch (Exception ex)
@@ -329,17 +330,18 @@ public async Task<string> UpsertDocumentChunked(
329330
{
330331
key,
331332
project = resolvedProject,
332-
result.Status,
333-
result.ChunksReceived,
334-
result.TotalChunks,
335-
Document = result.Document is null ? null : new
333+
status = result.Status,
334+
chunksReceived = result.ChunksReceived,
335+
totalChunks = result.TotalChunks,
336+
document = result.Document is null ? null : new
336337
{
337-
result.Document.Key,
338-
result.Document.Project,
339-
result.Document.Tags,
340-
result.Document.UpdatedAt,
341-
result.Document.UpdatedBy,
342-
ContentLength = result.Document.Content.Length
338+
key = result.Document.Key,
339+
project = result.Document.Project,
340+
tags = result.Document.Tags,
341+
updatedAt = result.Document.UpdatedAt,
342+
updatedBy = result.Document.UpdatedBy,
343+
contentHash = result.Document.ContentHash,
344+
contentLength = result.Document.Content.Length
343345
}
344346
});
345347
}
@@ -366,17 +368,17 @@ public async Task<string> SearchDocuments(
366368
{
367369
return JsonSerializer.Serialize(new[]
368370
{
369-
new { documents[0].Key, documents[0].Content }
371+
new { key = documents[0].Key, content = documents[0].Content }
370372
});
371373
}
372374

373375
var projection = documents.Select(d => new
374376
{
375-
d.Key,
376-
d.Tags,
377-
d.UpdatedAt,
378-
d.Project,
379-
ContentExcerpt = d.Content.Length > 300 ? d.Content[..300] + "..." : d.Content
377+
key = d.Key,
378+
tags = d.Tags,
379+
updatedAt = d.UpdatedAt,
380+
project = d.Project,
381+
contentExcerpt = d.Content.Length > 300 ? d.Content[..300] + "..." : d.Content
380382
});
381383

382384
return JsonSerializer.Serialize(projection);

0 commit comments

Comments
 (0)