@sentry/junior 0.137.0 → 0.139.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{agent-hooks-MZOKEP3J.js → agent-hooks-MJXMD7JP.js} +11 -9
- package/dist/api/schema/task.d.ts +100 -1
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +9 -1
- package/dist/api.js +202 -55
- package/dist/app.d.ts +7 -0
- package/dist/app.js +601 -1356
- package/dist/{catalog-runtime-MD66YLFV.js → catalog-runtime-GCCFYPIK.js} +6 -6
- package/dist/chat/agent/request.d.ts +44 -4
- package/dist/chat/agent-dispatch/heartbeat.d.ts +5 -0
- package/dist/chat/agent-dispatch/types.d.ts +1 -1
- package/dist/chat/agent-invocations/errors.d.ts +8 -0
- package/dist/chat/agent-invocations/spawn.d.ts +12 -0
- package/dist/chat/agent-invocations/store.d.ts +44 -0
- package/dist/chat/agent-invocations/types.d.ts +449 -0
- package/dist/chat/agent-invocations/work.d.ts +31 -0
- package/dist/chat/config.d.ts +1 -0
- package/dist/chat/conversations/sql/store.d.ts +8 -0
- package/dist/chat/conversations/store.d.ts +7 -0
- package/dist/chat/credentials/context.d.ts +14 -0
- package/dist/chat/experimental.d.ts +16 -0
- package/dist/chat/resource-events/actor.d.ts +23 -0
- package/dist/chat/runtime/agent-runner.d.ts +2 -1
- package/dist/chat/services/auth-pause.d.ts +0 -1
- package/dist/chat/services/mcp-auth-orchestration.d.ts +3 -2
- package/dist/chat/services/plugin-auth-orchestration.d.ts +3 -2
- package/dist/chat/state/turn-session.d.ts +1 -5
- package/dist/chat/task-execution/state.d.ts +23 -11
- package/dist/chat/task-execution/store.d.ts +20 -11
- package/dist/chat/task-execution/worker.d.ts +2 -2
- package/dist/chat/tasks/execution-stats.d.ts +34 -3
- package/dist/chat/tasks/read.d.ts +3 -1
- package/dist/chat/tools/runtime/spawn-agent.d.ts +31 -0
- package/dist/chat/tools/types.d.ts +2 -0
- package/dist/{chunk-T6Z5S6PQ.js → chunk-2ECYPYKP.js} +1 -1
- package/dist/chunk-3T2JAGRH.js +115 -0
- package/dist/chunk-3Y47VMHV.js +6 -0
- package/dist/chunk-4V4QIYJH.js +41 -0
- package/dist/{chunk-SYCX4DOK.js → chunk-5GSZWRE2.js} +434 -65
- package/dist/chunk-5IDFPCON.js +46 -0
- package/dist/{chunk-36EG34YI.js → chunk-6OHTDR4F.js} +1 -1
- package/dist/chunk-6SU2DT27.js +441 -0
- package/dist/{chunk-UG6ZYPBI.js → chunk-75I3UBIL.js} +73 -60
- package/dist/chunk-AEQISMMU.js +711 -0
- package/dist/{chunk-5PNJMOY5.js → chunk-C2N6MNO4.js} +9 -2
- package/dist/{chunk-BZAMASJP.js → chunk-CXH25EL4.js} +2 -2
- package/dist/{chunk-K2NCQJKH.js → chunk-DW4PMHNW.js} +3 -3
- package/dist/chunk-EM225ITJ.js +56 -0
- package/dist/{chunk-UOXATPSI.js → chunk-G52UXKGO.js} +7 -5
- package/dist/chunk-GI52BW74.js +207 -0
- package/dist/{chunk-3Q342EJJ.js → chunk-GWQSZT4C.js} +2 -2
- package/dist/{chunk-EPBBYMNE.js → chunk-HUO3UTAQ.js} +1 -1
- package/dist/{chunk-WPPXIAFB.js → chunk-IIESAYDL.js} +17 -434
- package/dist/chunk-IUFM5JWV.js +24 -0
- package/dist/{chunk-UZQ4VY3M.js → chunk-J3S57AXY.js} +1 -1
- package/dist/{chunk-DQXAAVTR.js → chunk-J6EJQCHY.js} +46 -1471
- package/dist/{chunk-6ZK6FZIV.js → chunk-KCBZSJRU.js} +6 -27
- package/dist/chunk-MQ5RYATN.js +1523 -0
- package/dist/{chunk-5G34IEK2.js → chunk-MXTVUV3I.js} +2 -56
- package/dist/{chunk-YRPC6MJY.js → chunk-MXVD2BDS.js} +1 -1
- package/dist/{chunk-POBSY47Q.js → chunk-PJW6U46K.js} +337 -306
- package/dist/chunk-Q6QZTTLS.js +55 -0
- package/dist/{chunk-ZFS67WIR.js → chunk-QTBKPZDA.js} +57 -6
- package/dist/chunk-R776HKPK.js +81 -0
- package/dist/{chunk-77VDLF3Z.js → chunk-RUIXF3YQ.js} +10 -0
- package/dist/chunk-U27DSXKB.js +714 -0
- package/dist/{chunk-XZ7NPXAB.js → chunk-U7CMWQ7Z.js} +1 -1
- package/dist/{chunk-RB4NJKEX.js → chunk-UDBUS533.js} +125 -51
- package/dist/chunk-WQRX57EA.js +668 -0
- package/dist/chunk-WZH4JV7R.js +320 -0
- package/dist/{chunk-HCIVH3JS.js → chunk-YCTDA7BD.js} +28 -0
- package/dist/{chunk-YNFERGKP.js → chunk-YGZ2OLXL.js} +1 -1
- package/dist/{chunk-EWDSB24B.js → chunk-ZQCGQMF2.js} +16 -776
- package/dist/{chunk-KJ4HGRHN.js → chunk-ZYQSPQYR.js} +515 -601
- package/dist/cli/chat.js +68 -29
- package/dist/cli/check.js +7 -7
- package/dist/cli/plugins.js +15 -13
- package/dist/cli/snapshot-create.js +11 -10
- package/dist/cli/upgrade.js +8 -8
- package/dist/conversation-work-KATFHLG3.js +56 -0
- package/dist/db/schema/agent-invocations.d.ts +544 -0
- package/dist/db/schema/task-executions.d.ts +23 -2
- package/dist/db/schema.d.ts +563 -2
- package/dist/{db-66E7VDNC.js → db-UXPPGHDF.js} +7 -7
- package/dist/experimental-HH6OM6UH.js +13 -0
- package/dist/instrumentation.js +4 -4
- package/dist/nitro.js +4 -3
- package/dist/{oauth-callback-server-7QPD4Q7P.js → oauth-callback-server-4ZYMD5UA.js} +28 -19
- package/dist/{runner-L2BKJKOD.js → runner-MZSEONRZ.js} +32 -18
- package/dist/{sandbox-egress-signals-A5HWIQH4.js → sandbox-egress-signals-EKPAVWQL.js} +2 -2
- package/dist/{skills-HOQ2NSPW.js → skills-IMVPXSQ7.js} +7 -7
- package/dist/spawn-S5LSVOCE.js +38 -0
- package/dist/{validation-ENHI7S2C.js → validation-ZKCY2BVR.js} +7 -7
- package/dist/version.js +1 -1
- package/dist/work-GG3XDYRX.js +46 -0
- package/dist/worker-23AUELCJ.js +24 -0
- package/migrations/0021_first_warhawk.sql +35 -0
- package/migrations/0022_task_execution_status.sql +3 -0
- package/migrations/meta/0021_snapshot.json +2176 -0
- package/migrations/meta/0022_snapshot.json +2186 -0
- package/migrations/meta/_journal.json +15 -1
- package/package.json +4 -4
- package/dist/chunk-6QW2RRQT.js +0 -233
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
JUNIOR_VERSION
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-U7CMWQ7Z.js";
|
|
4
4
|
|
|
5
5
|
// src/deployment.ts
|
|
6
6
|
var JUNIOR_HEARTBEAT_ROUTE = "/api/internal/heartbeat";
|
|
@@ -15,7 +15,14 @@ function toOptionalTrimmed(value) {
|
|
|
15
15
|
return trimmed ? trimmed : void 0;
|
|
16
16
|
}
|
|
17
17
|
function getDeploymentServiceVersion() {
|
|
18
|
-
|
|
18
|
+
const configuredRelease = toOptionalTrimmed(process.env.SENTRY_RELEASE);
|
|
19
|
+
if (configuredRelease) {
|
|
20
|
+
return configuredRelease;
|
|
21
|
+
}
|
|
22
|
+
const deploymentRevision = toOptionalTrimmed(
|
|
23
|
+
process.env.VERCEL_GIT_COMMIT_SHA
|
|
24
|
+
);
|
|
25
|
+
return deploymentRevision ? `${JUNIOR_VERSION}+${deploymentRevision}` : void 0;
|
|
19
26
|
}
|
|
20
27
|
function getDeploymentTelemetryAttributes() {
|
|
21
28
|
const attributes = {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
credentialUserSubjectId
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-RUIXF3YQ.js";
|
|
4
4
|
import {
|
|
5
5
|
logInfo,
|
|
6
6
|
logWarn,
|
|
7
7
|
setSpanAttributes
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-2ECYPYKP.js";
|
|
9
9
|
import {
|
|
10
10
|
discoverInstalledPluginPackageContent,
|
|
11
11
|
normalizePluginPackageNames
|
|
@@ -4,16 +4,16 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
canRouteResourceEvents,
|
|
6
6
|
getPlugins
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-IIESAYDL.js";
|
|
8
8
|
import {
|
|
9
9
|
getDb
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-QTBKPZDA.js";
|
|
11
11
|
import {
|
|
12
12
|
juniorEventTasks,
|
|
13
13
|
juniorSchedulerRuns,
|
|
14
14
|
juniorSchedulerTasks,
|
|
15
15
|
juniorStats
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-UDBUS533.js";
|
|
17
17
|
import {
|
|
18
18
|
juniorDestinations
|
|
19
19
|
} from "./chunk-VFUK3X5B.js";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/chat/sandbox/paths.ts
|
|
2
|
+
function normalizeWorkspaceRoot(input) {
|
|
3
|
+
const candidate = (input ?? "").trim();
|
|
4
|
+
if (!candidate) {
|
|
5
|
+
return "/vercel/sandbox";
|
|
6
|
+
}
|
|
7
|
+
const normalized = candidate.replace(/\/+$/, "");
|
|
8
|
+
return normalized.startsWith("/") ? normalized : `/${normalized}`;
|
|
9
|
+
}
|
|
10
|
+
var SANDBOX_WORKSPACE_ROOT = normalizeWorkspaceRoot(
|
|
11
|
+
process.env.VERCEL_SANDBOX_WORKSPACE_DIR
|
|
12
|
+
);
|
|
13
|
+
var SANDBOX_SKILLS_ROOT = `${SANDBOX_WORKSPACE_ROOT}/skills`;
|
|
14
|
+
var SANDBOX_DATA_ROOT = `${SANDBOX_WORKSPACE_ROOT}/data`;
|
|
15
|
+
function sandboxSkillDir(skillName) {
|
|
16
|
+
return `${SANDBOX_SKILLS_ROOT}/${skillName}`;
|
|
17
|
+
}
|
|
18
|
+
function sandboxSkillFile(skillName) {
|
|
19
|
+
return `${sandboxSkillDir(skillName)}/SKILL.md`;
|
|
20
|
+
}
|
|
21
|
+
function sandboxSkillPathResolution(skillName) {
|
|
22
|
+
const skillDir = sandboxSkillDir(skillName);
|
|
23
|
+
return `Resolve relative paths in this skill against ${skillDir}. For bash commands from this skill, cd to ${skillDir} first or use absolute paths.`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/chat/sleep.ts
|
|
27
|
+
function sleep(ms, signal) {
|
|
28
|
+
if (!signal) {
|
|
29
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
30
|
+
}
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
if (signal.aborted) {
|
|
33
|
+
reject(signal.reason);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const timeoutId = setTimeout(() => {
|
|
37
|
+
signal.removeEventListener("abort", onAbort);
|
|
38
|
+
resolve();
|
|
39
|
+
}, ms);
|
|
40
|
+
const onAbort = () => {
|
|
41
|
+
clearTimeout(timeoutId);
|
|
42
|
+
reject(signal.reason);
|
|
43
|
+
};
|
|
44
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
SANDBOX_WORKSPACE_ROOT,
|
|
50
|
+
SANDBOX_SKILLS_ROOT,
|
|
51
|
+
SANDBOX_DATA_ROOT,
|
|
52
|
+
sandboxSkillDir,
|
|
53
|
+
sandboxSkillFile,
|
|
54
|
+
sandboxSkillPathResolution,
|
|
55
|
+
sleep
|
|
56
|
+
};
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SANDBOX_WORKSPACE_ROOT,
|
|
3
|
-
getStateAdapter,
|
|
4
3
|
sleep
|
|
5
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-EM225ITJ.js";
|
|
5
|
+
import {
|
|
6
|
+
getStateAdapter
|
|
7
|
+
} from "./chunk-MXTVUV3I.js";
|
|
6
8
|
import {
|
|
7
9
|
toOptionalTrimmed
|
|
8
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-75I3UBIL.js";
|
|
9
11
|
import {
|
|
10
12
|
pluginCatalogRuntime
|
|
11
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-6OHTDR4F.js";
|
|
12
14
|
import {
|
|
13
15
|
setSpanAttributes,
|
|
14
16
|
setSpanStatus,
|
|
15
17
|
withSpan
|
|
16
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-2ECYPYKP.js";
|
|
17
19
|
|
|
18
20
|
// src/chat/sandbox/resources.ts
|
|
19
21
|
var configuredResources;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getDb
|
|
3
|
+
} from "./chunk-QTBKPZDA.js";
|
|
4
|
+
import {
|
|
5
|
+
juniorConversations,
|
|
6
|
+
juniorTaskExecutions
|
|
7
|
+
} from "./chunk-UDBUS533.js";
|
|
8
|
+
import {
|
|
9
|
+
logWarn
|
|
10
|
+
} from "./chunk-2ECYPYKP.js";
|
|
11
|
+
|
|
12
|
+
// src/chat/tasks/execution-stats.ts
|
|
13
|
+
import { and, asc, count, desc, eq, gte, inArray, lte, max, sql } from "drizzle-orm";
|
|
14
|
+
var TASK_EXECUTION_STATUSES = [
|
|
15
|
+
"blocked",
|
|
16
|
+
"completed",
|
|
17
|
+
"failed"
|
|
18
|
+
];
|
|
19
|
+
function utcDate(nowMs) {
|
|
20
|
+
return new Date(nowMs).toISOString().slice(0, 10);
|
|
21
|
+
}
|
|
22
|
+
function emptyDay(date) {
|
|
23
|
+
return { date, event: 0, scheduled: 0 };
|
|
24
|
+
}
|
|
25
|
+
function emptyStatusDay(date) {
|
|
26
|
+
return { blocked: 0, completed: 0, date, failed: 0 };
|
|
27
|
+
}
|
|
28
|
+
async function recordTaskExecution(type, taskId, options) {
|
|
29
|
+
const namespace = options.namespace ?? "junior";
|
|
30
|
+
const nowMs = options.nowMs ?? Date.now();
|
|
31
|
+
const status = options.status ?? "completed";
|
|
32
|
+
try {
|
|
33
|
+
await getDb().insert(juniorTaskExecutions).values({
|
|
34
|
+
...options.conversationId ? { conversationId: options.conversationId } : {},
|
|
35
|
+
executedAtMs: nowMs,
|
|
36
|
+
executionId: options.executionId,
|
|
37
|
+
kind: type,
|
|
38
|
+
namespace,
|
|
39
|
+
status,
|
|
40
|
+
taskId
|
|
41
|
+
}).onConflictDoNothing({
|
|
42
|
+
target: [
|
|
43
|
+
juniorTaskExecutions.kind,
|
|
44
|
+
juniorTaskExecutions.namespace,
|
|
45
|
+
juniorTaskExecutions.executionId
|
|
46
|
+
]
|
|
47
|
+
});
|
|
48
|
+
} catch (error) {
|
|
49
|
+
logWarn("task.execution.stat_failed", {
|
|
50
|
+
error,
|
|
51
|
+
"app.task.execution.id": options.executionId,
|
|
52
|
+
"app.task.execution.namespace": namespace,
|
|
53
|
+
"app.task.execution.status": status,
|
|
54
|
+
"app.task.execution.task_id": taskId,
|
|
55
|
+
"app.task.execution.type": type
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function readTaskExecutionSummaries(type, namespace, options = {}) {
|
|
60
|
+
const sevenDaysAgoMs = (options.nowMs ?? Date.now()) - 7 * 24 * 60 * 60 * 1e3;
|
|
61
|
+
const db = getDb();
|
|
62
|
+
const latest = db.selectDistinctOn([juniorTaskExecutions.taskId], {
|
|
63
|
+
conversationId: juniorTaskExecutions.conversationId,
|
|
64
|
+
taskId: juniorTaskExecutions.taskId
|
|
65
|
+
}).from(juniorTaskExecutions).where(
|
|
66
|
+
and(
|
|
67
|
+
eq(juniorTaskExecutions.kind, type),
|
|
68
|
+
eq(juniorTaskExecutions.namespace, namespace)
|
|
69
|
+
)
|
|
70
|
+
).orderBy(
|
|
71
|
+
juniorTaskExecutions.taskId,
|
|
72
|
+
desc(juniorTaskExecutions.executedAtMs),
|
|
73
|
+
desc(juniorTaskExecutions.executionId)
|
|
74
|
+
).as("latest_task_execution");
|
|
75
|
+
const rows = await db.select({
|
|
76
|
+
lastConversationId: latest.conversationId,
|
|
77
|
+
lastExecutedAtMs: max(juniorTaskExecutions.executedAtMs),
|
|
78
|
+
runsLast7Days: sql`count(*) filter (where ${juniorTaskExecutions.executedAtMs} >= ${sevenDaysAgoMs})::int`,
|
|
79
|
+
taskId: juniorTaskExecutions.taskId,
|
|
80
|
+
totalRuns: sql`count(*)::int`
|
|
81
|
+
}).from(juniorTaskExecutions).innerJoin(latest, eq(latest.taskId, juniorTaskExecutions.taskId)).where(
|
|
82
|
+
and(
|
|
83
|
+
eq(juniorTaskExecutions.kind, type),
|
|
84
|
+
eq(juniorTaskExecutions.namespace, namespace)
|
|
85
|
+
)
|
|
86
|
+
).groupBy(juniorTaskExecutions.taskId, latest.conversationId);
|
|
87
|
+
return new Map(
|
|
88
|
+
rows.map((row) => [
|
|
89
|
+
row.taskId,
|
|
90
|
+
{
|
|
91
|
+
...row.lastConversationId ? { lastConversationId: row.lastConversationId } : {},
|
|
92
|
+
...row.lastExecutedAtMs !== null ? { lastExecutedAtMs: row.lastExecutedAtMs } : {},
|
|
93
|
+
runsLast7Days: row.runsLast7Days,
|
|
94
|
+
totalRuns: row.totalRuns
|
|
95
|
+
}
|
|
96
|
+
])
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
async function readTaskExecutionDays(dayCount = 90, options = {}) {
|
|
100
|
+
const nowMs = options.nowMs ?? Date.now();
|
|
101
|
+
const end = utcDate(nowMs);
|
|
102
|
+
const endMs = Date.parse(`${end}T23:59:59.999Z`);
|
|
103
|
+
const startMs = Date.parse(`${end}T00:00:00.000Z`) - (dayCount - 1) * 864e5;
|
|
104
|
+
const executionDate = sql`to_char(to_timestamp(${juniorTaskExecutions.executedAtMs} / 1000.0) at time zone 'UTC', 'YYYY-MM-DD')`;
|
|
105
|
+
const rows = await getDb().select({
|
|
106
|
+
count: count(),
|
|
107
|
+
date: executionDate,
|
|
108
|
+
kind: juniorTaskExecutions.kind
|
|
109
|
+
}).from(juniorTaskExecutions).where(
|
|
110
|
+
and(
|
|
111
|
+
gte(juniorTaskExecutions.executedAtMs, startMs),
|
|
112
|
+
lte(juniorTaskExecutions.executedAtMs, endMs),
|
|
113
|
+
eq(juniorTaskExecutions.status, "completed")
|
|
114
|
+
)
|
|
115
|
+
).groupBy(executionDate, juniorTaskExecutions.kind).orderBy(asc(executionDate), asc(juniorTaskExecutions.kind));
|
|
116
|
+
const byDate = /* @__PURE__ */ new Map();
|
|
117
|
+
for (let offset = 0; offset < dayCount; offset += 1) {
|
|
118
|
+
const date = utcDate(startMs + offset * 864e5);
|
|
119
|
+
byDate.set(date, emptyDay(date));
|
|
120
|
+
}
|
|
121
|
+
for (const row of rows) {
|
|
122
|
+
const day = byDate.get(row.date);
|
|
123
|
+
if (!day) continue;
|
|
124
|
+
if (row.kind === "scheduled") day.scheduled = row.count;
|
|
125
|
+
else if (row.kind === "event") day.event = row.count;
|
|
126
|
+
}
|
|
127
|
+
return [...byDate.values()];
|
|
128
|
+
}
|
|
129
|
+
async function readTaskExecutions(args) {
|
|
130
|
+
const namespace = args.namespace ?? "junior";
|
|
131
|
+
const rows = await getDb().select({
|
|
132
|
+
conversationId: juniorTaskExecutions.conversationId,
|
|
133
|
+
executedAtMs: juniorTaskExecutions.executedAtMs,
|
|
134
|
+
executionId: juniorTaskExecutions.executionId,
|
|
135
|
+
status: juniorTaskExecutions.status,
|
|
136
|
+
title: juniorConversations.title
|
|
137
|
+
}).from(juniorTaskExecutions).leftJoin(
|
|
138
|
+
juniorConversations,
|
|
139
|
+
eq(
|
|
140
|
+
juniorConversations.conversationId,
|
|
141
|
+
juniorTaskExecutions.conversationId
|
|
142
|
+
)
|
|
143
|
+
).where(
|
|
144
|
+
and(
|
|
145
|
+
eq(juniorTaskExecutions.kind, args.kind),
|
|
146
|
+
eq(juniorTaskExecutions.namespace, namespace),
|
|
147
|
+
eq(juniorTaskExecutions.taskId, args.taskId)
|
|
148
|
+
)
|
|
149
|
+
).orderBy(
|
|
150
|
+
desc(juniorTaskExecutions.executedAtMs),
|
|
151
|
+
desc(juniorTaskExecutions.executionId)
|
|
152
|
+
).limit(args.limit);
|
|
153
|
+
return rows.map((row) => {
|
|
154
|
+
const title = row.title?.trim();
|
|
155
|
+
return {
|
|
156
|
+
...row.conversationId ? { conversationId: row.conversationId } : {},
|
|
157
|
+
executedAt: new Date(row.executedAtMs).toISOString(),
|
|
158
|
+
executionId: row.executionId,
|
|
159
|
+
status: row.status,
|
|
160
|
+
...title ? { title } : {}
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
async function readTaskExecutionStatusDays(args) {
|
|
165
|
+
const dayCount = args.dayCount ?? 90;
|
|
166
|
+
const namespace = args.namespace ?? "junior";
|
|
167
|
+
const nowMs = args.nowMs ?? Date.now();
|
|
168
|
+
const end = utcDate(nowMs);
|
|
169
|
+
const endMs = Date.parse(`${end}T23:59:59.999Z`);
|
|
170
|
+
const startMs = Date.parse(`${end}T00:00:00.000Z`) - (dayCount - 1) * 864e5;
|
|
171
|
+
const executionDate = sql`to_char(to_timestamp(${juniorTaskExecutions.executedAtMs} / 1000.0) at time zone 'UTC', 'YYYY-MM-DD')`;
|
|
172
|
+
const rows = await getDb().select({
|
|
173
|
+
count: count(),
|
|
174
|
+
date: executionDate,
|
|
175
|
+
status: juniorTaskExecutions.status
|
|
176
|
+
}).from(juniorTaskExecutions).where(
|
|
177
|
+
and(
|
|
178
|
+
eq(juniorTaskExecutions.kind, args.kind),
|
|
179
|
+
eq(juniorTaskExecutions.namespace, namespace),
|
|
180
|
+
eq(juniorTaskExecutions.taskId, args.taskId),
|
|
181
|
+
gte(juniorTaskExecutions.executedAtMs, startMs),
|
|
182
|
+
lte(juniorTaskExecutions.executedAtMs, endMs),
|
|
183
|
+
inArray(juniorTaskExecutions.status, [...TASK_EXECUTION_STATUSES])
|
|
184
|
+
)
|
|
185
|
+
).groupBy(executionDate, juniorTaskExecutions.status).orderBy(asc(executionDate), asc(juniorTaskExecutions.status));
|
|
186
|
+
const byDate = /* @__PURE__ */ new Map();
|
|
187
|
+
for (let offset = 0; offset < dayCount; offset += 1) {
|
|
188
|
+
const date = utcDate(startMs + offset * 864e5);
|
|
189
|
+
byDate.set(date, emptyStatusDay(date));
|
|
190
|
+
}
|
|
191
|
+
for (const row of rows) {
|
|
192
|
+
const day = byDate.get(row.date);
|
|
193
|
+
if (!day) continue;
|
|
194
|
+
if (row.status === "completed") day.completed = row.count;
|
|
195
|
+
else if (row.status === "failed") day.failed = row.count;
|
|
196
|
+
else if (row.status === "blocked") day.blocked = row.count;
|
|
197
|
+
}
|
|
198
|
+
return [...byDate.values()];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export {
|
|
202
|
+
recordTaskExecution,
|
|
203
|
+
readTaskExecutionSummaries,
|
|
204
|
+
readTaskExecutionDays,
|
|
205
|
+
readTaskExecutions,
|
|
206
|
+
readTaskExecutionStatusDays
|
|
207
|
+
};
|