Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/DevBrain.Functions/Services/CosmosDocumentStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,18 @@ public async Task<BrainDocument> AppendAsync(

var (existing, etag) = read.Value;

var mergedContent = existing.Content + separator + content;
var merged = new BrainDocument
{
Id = existing.Id,
Key = existing.Key,
Project = existing.Project,
Content = existing.Content + separator + content,
Content = mergedContent,
Tags = UnionTags(existing.Tags, tags),
UpdatedAt = DateTimeOffset.UtcNow,
UpdatedBy = updatedBy
UpdatedBy = updatedBy,
ContentHash = ComputeSha256(mergedContent),
ContentLength = mergedContent.Length
};

try
Expand Down
76 changes: 39 additions & 37 deletions src/DevBrain.Functions/Tools/DocumentTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ public async Task<string> GetDocumentMetadata(

return JsonSerializer.Serialize(new
{
document.Key,
document.Project,
document.Tags,
document.UpdatedAt,
document.UpdatedBy,
document.ContentHash,
document.ContentLength
key = document.Key,
project = document.Project,
tags = document.Tags,
updatedAt = document.UpdatedAt,
updatedBy = document.UpdatedBy,
contentHash = document.ContentHash,
contentLength = document.ContentLength
});
}

Expand Down Expand Up @@ -154,8 +154,8 @@ public async Task<string> CompareDocument(
storedContentHash = document.ContentHash,
storedContentLength = document.ContentLength,
candidateHash,
document.UpdatedAt,
document.UpdatedBy
updatedAt = document.UpdatedAt,
updatedBy = document.UpdatedBy
});
}

Expand All @@ -174,17 +174,17 @@ public async Task<string> ListDocuments(
{
return JsonSerializer.Serialize(new[]
{
new { documents[0].Key, documents[0].Content }
new { key = documents[0].Key, content = documents[0].Content }
});
}

var projection = documents.Select(d => new
{
d.Key,
d.Tags,
d.UpdatedAt,
d.UpdatedBy,
d.Project
key = d.Key,
tags = d.Tags,
updatedAt = d.UpdatedAt,
updatedBy = d.UpdatedBy,
project = d.Project
});

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

return JsonSerializer.Serialize(new
{
saved.Key,
saved.Project,
saved.Tags,
saved.UpdatedAt,
saved.UpdatedBy,
ContentLength = saved.Content.Length
key = saved.Key,
project = saved.Project,
tags = saved.Tags,
updatedAt = saved.UpdatedAt,
updatedBy = saved.UpdatedBy,
contentHash = saved.ContentHash,
contentLength = saved.Content.Length
});
}
catch (Exception ex)
Expand Down Expand Up @@ -329,17 +330,18 @@ public async Task<string> UpsertDocumentChunked(
{
key,
project = resolvedProject,
result.Status,
result.ChunksReceived,
result.TotalChunks,
Document = result.Document is null ? null : new
status = result.Status,
chunksReceived = result.ChunksReceived,
totalChunks = result.TotalChunks,
document = result.Document is null ? null : new
{
result.Document.Key,
result.Document.Project,
result.Document.Tags,
result.Document.UpdatedAt,
result.Document.UpdatedBy,
ContentLength = result.Document.Content.Length
key = result.Document.Key,
project = result.Document.Project,
tags = result.Document.Tags,
updatedAt = result.Document.UpdatedAt,
updatedBy = result.Document.UpdatedBy,
contentHash = result.Document.ContentHash,
contentLength = result.Document.Content.Length
}
});
}
Expand All @@ -366,17 +368,17 @@ public async Task<string> SearchDocuments(
{
return JsonSerializer.Serialize(new[]
{
new { documents[0].Key, documents[0].Content }
new { key = documents[0].Key, content = documents[0].Content }
});
}

var projection = documents.Select(d => new
{
d.Key,
d.Tags,
d.UpdatedAt,
d.Project,
ContentExcerpt = d.Content.Length > 300 ? d.Content[..300] + "..." : d.Content
key = d.Key,
tags = d.Tags,
updatedAt = d.UpdatedAt,
project = d.Project,
contentExcerpt = d.Content.Length > 300 ? d.Content[..300] + "..." : d.Content
});

return JsonSerializer.Serialize(projection);
Expand Down
Loading