Skip to content

Commit e104bdd

Browse files
authored
Copilot Agents - Production Release (#59)
2 parents 29b7a79 + 3311674 commit e104bdd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1670
-425
lines changed

src/AnalyticsEngine/App.ControlPanel.Engine/Utils/DatabaseUpgrader.cs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static void CheckDbUpgraded(DatabaseUpgradeInfo initInfo, Action<string>
5555
log?.Invoke($"--Running script '{scriptName}'...");
5656
var script = rr.ReadResourceString(scriptName);
5757

58-
var statements = SplitSqlStatements(script);
58+
var statements = StringUtils.SplitSqlStatements(script);
5959
foreach (var statement in statements)
6060
context.Database.ExecuteSqlCommand(statement);
6161
}
@@ -85,24 +85,5 @@ public static void CheckDbUpgraded(DatabaseUpgradeInfo initInfo, Action<string>
8585
log?.Invoke($"[{DateTime.Now}]: Database initialised successfully. Everything worked.");
8686
}
8787

88-
// https://stackoverflow.com/questions/18596876/go-statements-blowing-up-sql-execution-in-net
89-
private static IEnumerable<string> SplitSqlStatements(string sqlScript)
90-
{
91-
// Make line endings standard to match RegexOptions.Multiline
92-
sqlScript = Regex.Replace(sqlScript, @"(\r\n|\n\r|\n|\r)", "\n");
93-
94-
// Split by "GO" statements
95-
var statements = Regex.Split(
96-
sqlScript,
97-
@"^[\t ]*GO[\t ]*\d*[\t ]*(?:--.*)?$",
98-
RegexOptions.Multiline |
99-
RegexOptions.IgnorePatternWhitespace |
100-
RegexOptions.IgnoreCase);
101-
102-
// Remove empties, trim, and return
103-
return statements
104-
.Where(x => !string.IsNullOrWhiteSpace(x))
105-
.Select(x => x.Trim(' ', '\n'));
106-
}
10788
}
10889
}

src/AnalyticsEngine/Common/DataUtils/StringUtils.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Newtonsoft.Json.Linq;
22
using System;
3+
using System.Collections.Generic;
34
using System.IO;
45
using System.Linq;
56
using System.Security.Cryptography;
@@ -410,5 +411,26 @@ public static string EnsureMaxLength(string potentiallyLongString, int maxLength
410411
return potentiallyLongString;
411412
}
412413
}
414+
415+
416+
// https://stackoverflow.com/questions/18596876/go-statements-blowing-up-sql-execution-in-net
417+
public static IEnumerable<string> SplitSqlStatements(string sqlScript)
418+
{
419+
// Make line endings standard to match RegexOptions.Multiline
420+
sqlScript = Regex.Replace(sqlScript, @"(\r\n|\n\r|\n|\r)", "\n");
421+
422+
// Split by "GO" statements
423+
var statements = Regex.Split(
424+
sqlScript,
425+
@"^[\t ]*GO[\t ]*\d*[\t ]*(?:--.*)?$",
426+
RegexOptions.Multiline |
427+
RegexOptions.IgnorePatternWhitespace |
428+
RegexOptions.IgnoreCase);
429+
430+
// Remove empties, trim, and return
431+
return statements
432+
.Where(x => !string.IsNullOrWhiteSpace(x))
433+
.Select(x => x.Trim(' ', '\n'));
434+
}
413435
}
414436
}

src/AnalyticsEngine/Common/Entities/AnalyticsEntitiesContext.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ namespace Common.Entities
1616
/// The database model
1717
/// </summary>
1818
/// <remarks>
19-
/// Add-Migration -Name "ExtendedUsageReports" -ProjectName "Common.Entities" -StartUpProjectName "WebJob.Office365ActivityImporter"
20-
/// Update-Database -TargetMigration "PageCommentsAndLikes" -ProjectName "Common.Entities" -StartUpProjectName "WebJob.Office365ActivityImporter"
19+
/// Add-Migration -Name "ExtendedUsageReports" -ProjectName "Entities" -StartUpProjectName "WebJob.Office365ActivityImporter"
20+
/// Update-Database -TargetMigration "PageCommentsAndLikes" -ProjectName "Entities" -StartUpProjectName "WebJob.Office365ActivityImporter"
2121
/// </remarks>
2222
public class AnalyticsEntitiesContext : DbContext
2323
{
@@ -192,7 +192,7 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
192192

193193
public virtual DbSet<Site> sites { get; set; }
194194
public virtual DbSet<Web> webs { get; set; }
195-
public virtual DbSet<Office365Event> AuditEventsCommon { get; set; }
195+
public virtual DbSet<CommonAuditEvent> AuditEventsCommon { get; set; }
196196
public virtual DbSet<Browser> browsers { get; set; }
197197
public virtual DbSet<City> cities { get; set; }
198198
public virtual DbSet<Country> countries { get; set; }
@@ -299,6 +299,7 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
299299
public DbSet<CopilotChat> CopilotChats { get; set; }
300300
public DbSet<CopilotEventMetadataFile> CopilotEventMetadataFiles { get; set; }
301301
public DbSet<CopilotEventMetadataMeeting> CopilotEventMetadataMeetings { get; set; }
302+
public DbSet<CopilotAgent> CopilotAgents { get; set; }
302303

303304

304305
#endregion

src/AnalyticsEngine/Common/Entities/Config/AppConnectionStrings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ public AppConnectionStrings()
8181

8282
public string DatabaseConnectionString { get; set; } = null;
8383

84+
// Compat with Copilot Feedback Bot
85+
public string SQL => DatabaseConnectionString;
86+
8487
public string RedisConnectionString { get; set; } = null;
8588

8689
public string ServiceBusConnectionString { get; set; } = null;

src/AnalyticsEngine/Common/Entities/Entities.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@
7373
<Reference Include="System.Xml" />
7474
<Reference Include="System.Xml.Linq" />
7575
</ItemGroup>
76+
<ItemGroup>
77+
<EmbeddedResource Include="..\..\..\Clean Old Data Data.sql" />
78+
</ItemGroup>
7679
<ItemGroup>
7780
<Compile Include="BaseEntity.cs" />
7881
<Compile Include="Config\AppConfig.cs" />
@@ -252,6 +255,10 @@
252255
<Compile Include="Migrations\202404101126333_CopilotEvents.Designer.cs">
253256
<DependentUpon>202404101126333_CopilotEvents.cs</DependentUpon>
254257
</Compile>
258+
<Compile Include="Migrations\202510231511508_CopilotAgents.cs" />
259+
<Compile Include="Migrations\202510231511508_CopilotAgents.Designer.cs">
260+
<DependentUpon>202510231511508_CopilotAgents.cs</DependentUpon>
261+
</Compile>
255262
<Compile Include="Migrations\v1-0-5.cs" />
256263
<Compile Include="Migrations\v1-0-5.Designer.cs">
257264
<DependentUpon>v1-0-5.cs</DependentUpon>
@@ -291,6 +298,7 @@
291298
<Compile Include="AnalyticsEntitiesContext.cs" />
292299
<Compile Include="Entities\Url.cs" />
293300
<Compile Include="Entities\User.cs" />
301+
<Compile Include="ResourceProxy.cs" />
294302
</ItemGroup>
295303
<ItemGroup>
296304
<BootstrapperPackage Include=".NETFramework,Version=v4.5.2">
@@ -362,6 +370,9 @@
362370
<EmbeddedResource Include="Migrations\202404101126333_CopilotEvents.resx">
363371
<DependentUpon>202404101126333_CopilotEvents.cs</DependentUpon>
364372
</EmbeddedResource>
373+
<EmbeddedResource Include="Migrations\202510231511508_CopilotAgents.resx">
374+
<DependentUpon>202510231511508_CopilotAgents.cs</DependentUpon>
375+
</EmbeddedResource>
365376
<EmbeddedResource Include="Migrations\v1-0-5.resx">
366377
<DependentUpon>v1-0-5.cs</DependentUpon>
367378
</EmbeddedResource>
@@ -379,6 +390,7 @@
379390
</EmbeddedResource>
380391
<EmbeddedResource Include="Properties\Resources.resx">
381392
<Generator>ResXFileCodeGenerator</Generator>
393+
<SubType>Designer</SubType>
382394
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
383395
</EmbeddedResource>
384396
</ItemGroup>

src/AnalyticsEngine/Common/Entities/Entities/AuditLog/BaseClasses.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ public abstract class BaseOfficeEvent
1111
/// Foriegn key for "Event" only
1212
/// </summary>
1313
[Key]
14-
[ForeignKey("Event")]
14+
[ForeignKey(nameof(AuditEvent))]
1515
[Column("event_id")]
1616
public Guid EventID { get; set; }
1717

1818

19-
public Office365Event Event { get; set; }
19+
public CommonAuditEvent AuditEvent { get; set; }
2020

2121
}
2222

src/AnalyticsEngine/Common/Entities/Entities/AuditLog/CopilotEvents.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ public class CopilotChat : BaseOfficeEvent
1414
{
1515
[Column("app_host")]
1616
public string AppHost { get; set; } = null;
17+
18+
19+
[ForeignKey(nameof(Agent))]
20+
[Column("agent_id")]
21+
public int? AgentId { get; set; }
22+
public CopilotAgent Agent { get; set; } = null;
1723
}
1824

1925
/// <summary>
@@ -77,4 +83,12 @@ public override string GetEventDescription()
7783
}
7884
}
7985

86+
[Table("copilot_agents")]
87+
public class CopilotAgent : AbstractEFEntityWithName
88+
{
89+
[Column("agent_id")]
90+
public string AgentID { get; set; } = null;
91+
}
92+
8093
}
94+

src/AnalyticsEngine/Common/Entities/Entities/AuditLog/Office365Event.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Common.Entities
77
/// The common event entity for any workload. Workload specific events link back to this.
88
/// </summary>
99
[Table("audit_events")]
10-
public class Office365Event
10+
public class CommonAuditEvent
1111
{
1212
[Column("id")]
1313
public System.Guid Id { get; set; }

src/AnalyticsEngine/Common/Entities/Migrations/202510231511508_CopilotAgents.Designer.cs

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace Common.Entities.Migrations
2+
{
3+
using System;
4+
using System.Data.Entity.Migrations;
5+
6+
public partial class CopilotAgents : DbMigration
7+
{
8+
public override void Up()
9+
{
10+
CreateTable(
11+
"dbo.copilot_agents",
12+
c => new
13+
{
14+
id = c.Int(nullable: false, identity: true),
15+
agent_id = c.String(),
16+
name = c.String(maxLength: 100),
17+
})
18+
.PrimaryKey(t => t.id);
19+
20+
AddColumn("dbo.event_copilot_chats", "agent_id", c => c.Int());
21+
CreateIndex("dbo.event_copilot_chats", "agent_id");
22+
AddForeignKey("dbo.event_copilot_chats", "agent_id", "dbo.copilot_agents", "id");
23+
}
24+
25+
public override void Down()
26+
{
27+
DropForeignKey("dbo.event_copilot_chats", "agent_id", "dbo.copilot_agents");
28+
DropIndex("dbo.event_copilot_chats", new[] { "agent_id" });
29+
DropColumn("dbo.event_copilot_chats", "agent_id");
30+
DropTable("dbo.copilot_agents");
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)