Skip to content

Commit

Permalink
fix: Replace user attention level with timeline activity retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
nadeesha committed Dec 7, 2024
1 parent d385127 commit f385af6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
51 changes: 43 additions & 8 deletions control-plane/src/modules/observability/events.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ulid } from "ulid";
import { db, events as eventsTable } from "../data";
import { logger } from "./logger";
import { eq, and, gte, SQL, desc, or, sql } from "drizzle-orm";
import { eq, and, gte, SQL, desc, or, sql, inArray } from "drizzle-orm";
import { NotFoundError } from "../../utilities/errors";

export type EventTypes =
Expand All @@ -18,13 +18,6 @@ export type EventTypes =
| "machineStalled"
| "machineResourceProbe"
| "modelInvocation"
| "functionInvocation"
| "encryptedAgentMessage"
| "workflowScheduleCreated"
| "workflowScheduleRemoved"
| "listenerAttached"
| "listenerDetached"
| "listenerNotificationReceived"
| "humanMessage"
| "systemMessage"
| "agentMessage"
Expand Down Expand Up @@ -251,6 +244,48 @@ export const getActivityByWorkflowIdForUserAttentionLevel = async (params: {
return results;
};

export const getActivityForTimeline = async (params: {
clusterId: string;
runId: string;
after?: string;
}) => {
const results = await db
.select({
id: eventsTable.id,
clusterId: eventsTable.cluster_id,
type: eventsTable.type,
jobId: eventsTable.job_id,
machineId: eventsTable.machine_id,
service: eventsTable.service,
createdAt: eventsTable.created_at,
targetFn: eventsTable.target_fn,
resultType: eventsTable.result_type,
status: eventsTable.status,
workflowId: eventsTable.run_id,
})
.from(eventsTable)
.where(
and(
eq(eventsTable.cluster_id, params.clusterId),
eq(eventsTable.run_id, params.runId),
inArray(eventsTable.type, [
"jobCreated",
"jobAcknowledged",
"jobResulted",
"jobStalled",
"jobStalledTooManyTimes",
"jobRecovered",
"resultSummarized",
"knowledgeArtifactsAccessed",
]),
),
)
.limit(100)
.orderBy(desc(eventsTable.created_at));

return results;
};

export const getMetaForActivity = async (params: {
clusterId: string;
eventId: string;
Expand Down
3 changes: 1 addition & 2 deletions control-plane/src/modules/workflows/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,9 @@ export const runsRouter = initServer().router(
runId,
after: messagesAfter,
}),
events.getActivityByWorkflowIdForUserAttentionLevel({
events.getActivityForTimeline({
clusterId,
runId,
userAttentionLevel: "info",
after: activityAfter,
}),
getJobsForWorkflow({
Expand Down

0 comments on commit f385af6

Please sign in to comment.