@sentry/junior 0.147.0 → 0.148.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-HS6VGUPM.js → agent-hooks-VAUYT6PD.js} +10 -10
- package/dist/api/conversations/access.d.ts +2 -1
- package/dist/api/conversations/archive.d.ts +3 -5
- package/dist/api/conversations/create.d.ts +6 -0
- package/dist/api/conversations/detail.d.ts +2 -296
- package/dist/api/conversations/event-list.d.ts +2 -193
- package/dist/api/conversations/list.d.ts +4 -66
- package/dist/api/conversations/routes.d.ts +1 -1
- package/dist/api/conversations/stats.d.ts +0 -54
- package/dist/api/http.d.ts +2 -6
- package/dist/api/locations/detail.d.ts +3 -111
- package/dist/api/locations/list.d.ts +0 -45
- package/dist/api/locations/query.d.ts +2 -1
- package/dist/api/locations/routes.d.ts +1 -1
- package/dist/api/people/list.d.ts +0 -29
- package/dist/api/people/profile.d.ts +2 -106
- package/dist/api/people/profile.query.d.ts +2 -1
- package/dist/api/people/routes.d.ts +1 -1
- package/dist/api/people/shared.d.ts +1 -1
- package/dist/api/people/spend.d.ts +3 -4
- package/dist/api/personal-tokens/routes.d.ts +2 -2
- package/dist/api/route.d.ts +8 -14
- package/dist/api/schema/conversation.d.ts +60 -29
- package/dist/api/schema/location.d.ts +4 -0
- package/dist/api/schema/person.d.ts +7 -3
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +7 -1
- package/dist/api/stats.d.ts +0 -13
- package/dist/api/validation.d.ts +7 -0
- package/dist/api/viewer.d.ts +3 -0
- package/dist/api.d.ts +2 -1
- package/dist/api.js +624 -562
- package/dist/app.js +183 -105
- package/dist/{catalog-runtime-M6ZTPYRV.js → catalog-runtime-WADOZVTB.js} +5 -5
- package/dist/chat/actor.d.ts +4 -1
- package/dist/chat/agent/request.d.ts +2 -0
- package/dist/chat/agent/resume.d.ts +1 -0
- package/dist/chat/agent-dispatch/context.d.ts +2 -2
- package/dist/chat/agent-invocations/types.d.ts +52 -0
- package/dist/chat/api-turns/work.d.ts +103 -0
- package/dist/chat/conversations/history.d.ts +60 -0
- package/dist/chat/conversations/provenance.d.ts +6 -0
- package/dist/chat/conversations/sql/actor-identity.d.ts +19 -0
- package/dist/chat/conversations/store.d.ts +1 -1
- package/dist/chat/resource-events/store.d.ts +1 -1
- package/dist/chat/runtime/reply-executor.d.ts +1 -1
- package/dist/chat/runtime/slack-runtime.d.ts +2 -1
- package/dist/chat/runtime/turn-preparation.d.ts +9 -0
- package/dist/chat/scheduled-tasks/tool-support.d.ts +5 -5
- package/dist/chat/scheduled-tasks/tools/create.d.ts +2 -2
- package/dist/chat/scheduled-tasks/tools/delete.d.ts +2 -2
- package/dist/chat/scheduled-tasks/tools/list.d.ts +2 -2
- package/dist/chat/scheduled-tasks/tools/run-now.d.ts +2 -2
- package/dist/chat/scheduled-tasks/tools/update.d.ts +2 -2
- package/dist/chat/slack/channel.d.ts +26 -0
- package/dist/chat/slack/dispatch-turn.d.ts +1 -0
- package/dist/chat/slack/timestamp-param.d.ts +0 -2
- package/dist/chat/slack/{tools → tool-support}/canvas/api.d.ts +1 -1
- package/dist/chat/slack/{tools → tool-support}/canvas/context.d.ts +3 -0
- package/dist/chat/slack/tool-support/channel-access.d.ts +42 -0
- package/dist/chat/slack/tool-support/channel-target.d.ts +27 -0
- package/dist/chat/slack/tool-support/list/params.d.ts +5 -0
- package/dist/chat/slack/tools/canvas/create.d.ts +1 -1
- package/dist/chat/slack/tools/channel-join.d.ts +28 -0
- package/dist/chat/slack/tools/channel-list-messages.d.ts +3 -2
- package/dist/chat/slack/tools/conversation-message-search.d.ts +2 -8
- package/dist/chat/slack/tools/message-add-reaction.d.ts +1 -1
- package/dist/chat/slack/tools/public-search.d.ts +63 -2
- package/dist/chat/slack/tools/send-files.d.ts +1 -1
- package/dist/chat/slack/tools/thread-read.d.ts +2 -5
- package/dist/chat/source.d.ts +2 -0
- package/dist/chat/task-execution/checkpoint.d.ts +1 -0
- package/dist/chat/task-execution/state.d.ts +9 -4
- package/dist/chat/task-execution/store.d.ts +3 -2
- package/dist/chat/task-execution/turn-cursor.d.ts +2 -0
- package/dist/chat/task-execution/worker.d.ts +2 -0
- package/dist/chat/tasks/read.d.ts +1 -1
- package/dist/chat/tools/search-conversation-events.d.ts +1 -1
- package/dist/chat/tools/types.d.ts +11 -4
- package/dist/chat/tools/watch-resource-events.d.ts +2 -2
- package/dist/{chunk-ORO3PWKQ.js → chunk-2B3PT3V2.js} +1 -1
- package/dist/{chunk-SVHUEHUL.js → chunk-45LOR4PU.js} +21 -4
- package/dist/{chunk-YBVXBNSV.js → chunk-4AQZYNHM.js} +2 -2
- package/dist/{chunk-Z4YU7Z4L.js → chunk-4EA2SFK2.js} +65 -4
- package/dist/{chunk-7NVJVJID.js → chunk-4GXJUYJV.js} +2 -2
- package/dist/{chunk-IIOOO4FQ.js → chunk-55F4QU2V.js} +2 -1
- package/dist/{chunk-745QJ3ZA.js → chunk-7OEIXFC3.js} +2 -2
- package/dist/{chunk-DU74WPIC.js → chunk-D3WPMGEX.js} +1 -1
- package/dist/{chunk-PVNG6UMU.js → chunk-D6YX4NNN.js} +22 -10
- package/dist/chunk-DUY5CDAM.js +36 -0
- package/dist/{chunk-4LJO56OJ.js → chunk-EAI67NTM.js} +1 -1
- package/dist/{chunk-X5UY34KT.js → chunk-EINWQFXI.js} +8 -8
- package/dist/chunk-GDFF3BQG.js +136 -0
- package/dist/{chunk-EFLJ2WJH.js → chunk-GXYDVZKM.js} +5 -5
- package/dist/{chunk-CWP5RHVX.js → chunk-HLPLT3NY.js} +8 -5
- package/dist/{chunk-JUUKWRBE.js → chunk-HWQGBIH7.js} +1 -1
- package/dist/{chunk-AZ7EAOBE.js → chunk-IL4EDBMV.js} +5 -5
- package/dist/{chunk-DLDRQHG5.js → chunk-LAZGHEYU.js} +1 -1
- package/dist/{chunk-RXBVB2JM.js → chunk-LE5H7LMT.js} +1 -1
- package/dist/chunk-LNVEIJ2L.js +48 -0
- package/dist/{chunk-YEO3VX72.js → chunk-OJCP3C3J.js} +8 -6
- package/dist/{chunk-GGB4WL5A.js → chunk-POSZWRGL.js} +1 -1
- package/dist/{chunk-YNTTROJT.js → chunk-QOWHHM3F.js} +1 -1
- package/dist/{chunk-6H5SZR24.js → chunk-RRJV5UR5.js} +302 -59
- package/dist/{chunk-AYU72WO7.js → chunk-ULAU5ZGU.js} +41 -64
- package/dist/{chunk-SGZO7UWH.js → chunk-V2FXMOEA.js} +2 -2
- package/dist/{chunk-AIOK6LAG.js → chunk-VCYSOXON.js} +272 -41
- package/dist/{chunk-7A4M7PCV.js → chunk-VMNRXKAH.js} +1166 -540
- package/dist/{chunk-YSB2N563.js → chunk-VRHTNBA6.js} +121 -87
- package/dist/{chunk-AVZDSUFB.js → chunk-VY6W3T43.js} +4 -4
- package/dist/{chunk-7UQIVT6G.js → chunk-WCN4YSH7.js} +6 -6
- package/dist/{chunk-CSZINQJ2.js → chunk-WOONT5ZP.js} +1 -1
- package/dist/{chunk-Q4R73I43.js → chunk-XJ42NBP5.js} +58 -28
- package/dist/{chunk-YHDERDRO.js → chunk-ZCHIC2GM.js} +91 -75
- package/dist/chunk-ZPL2RR7F.js +798 -0
- package/dist/cli/chat.js +33 -35
- package/dist/cli/check.js +6 -6
- package/dist/cli/plugins.js +13 -13
- package/dist/cli/snapshot-create.js +9 -9
- package/dist/cli/upgrade.js +7 -7
- package/dist/db/schema/agent-invocations.d.ts +20 -0
- package/dist/db/schema/conversation-annotations.d.ts +2 -2
- package/dist/db/schema.d.ts +22 -2
- package/dist/{db-CSEW4RII.js → db-XUKZRFFK.js} +7 -7
- package/dist/instrumentation.js +4 -4
- package/dist/nitro.js +2 -2
- package/dist/{oauth-callback-server-FUEV5HNG.js → oauth-callback-server-LPZMMGFI.js} +25 -26
- package/dist/{runner-U3XHSKSH.js → runner-DGKUTMPX.js} +17 -18
- package/dist/{skills-AKE6W3WI.js → skills-P7YUFSXM.js} +6 -6
- package/dist/spawn-DSK3ZEVD.js +38 -0
- package/dist/{validation-WDTAULUF.js → validation-S7U5M5NR.js} +6 -6
- package/dist/version.js +1 -1
- package/dist/{work-C3HAO2BG.js → work-GAA7TVAD.js} +18 -19
- package/dist/{worker-LNP4YKBM.js → worker-JXPJH3QB.js} +11 -10
- package/package.json +5 -4
- package/dist/api/health.d.ts +0 -7
- package/dist/api/personal-tokens/create.d.ts +0 -11
- package/dist/api/personal-tokens/list.d.ts +0 -12
- package/dist/api/personal-tokens/revoke.d.ts +0 -5
- package/dist/api/plugin-reports.d.ts +0 -63
- package/dist/api/plugins.d.ts +0 -8
- package/dist/api/runtime.d.ts +0 -24
- package/dist/api/skills.d.ts +0 -6
- package/dist/chat/slack/tools/channel-access.d.ts +0 -30
- package/dist/chunk-34GS7B6L.js +0 -115
- package/dist/chunk-AVOCH2Z5.js +0 -285
- package/dist/chunk-HLXXQI5Q.js +0 -238
- package/dist/chunk-K4SZAP3K.js +0 -67
- package/dist/chunk-R776HKPK.js +0 -81
- package/dist/spawn-B6GDTWJ4.js +0 -39
- /package/dist/chat/slack/{tools → tool-support}/canvas/markdown.d.ts +0 -0
- /package/dist/chat/slack/{tools → tool-support}/channel-capabilities.d.ts +0 -0
- /package/dist/chat/slack/{tools → tool-support}/context.d.ts +0 -0
- /package/dist/chat/slack/{tools → tool-support}/list/api.d.ts +0 -0
- /package/dist/chat/slack/{tools → tool-support}/slack-message-url.d.ts +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
appendAndEnqueueInboundMessage
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-HLPLT3NY.js";
|
|
4
4
|
import {
|
|
5
5
|
ConversationTurnLifecycleService,
|
|
6
6
|
getPersistedSandboxState,
|
|
7
7
|
getPersistedThreadState,
|
|
8
8
|
persistThreadStateById
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-IL4EDBMV.js";
|
|
10
10
|
import {
|
|
11
11
|
AgentInvocationBusyError,
|
|
12
12
|
AgentInvocationLimitError,
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
agentBindingSchema,
|
|
16
16
|
agentInvocationSchema,
|
|
17
17
|
createAgentInvocationSchema
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-EINWQFXI.js";
|
|
19
19
|
import {
|
|
20
20
|
TurnInputCommitLostError,
|
|
21
21
|
failTurnRecord,
|
|
@@ -26,16 +26,16 @@ import {
|
|
|
26
26
|
isTurnInputCommitLostError,
|
|
27
27
|
openConversationProjection,
|
|
28
28
|
saveTurnCheckpoint
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-VCYSOXON.js";
|
|
30
30
|
import {
|
|
31
31
|
getConversationEventStore,
|
|
32
32
|
getConversationStore,
|
|
33
33
|
getSqlExecutor
|
|
34
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-VRHTNBA6.js";
|
|
35
35
|
import {
|
|
36
36
|
juniorAgentBindings,
|
|
37
37
|
juniorAgentInvocations
|
|
38
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-D3WPMGEX.js";
|
|
39
39
|
|
|
40
40
|
// src/chat/agent-invocations/work.ts
|
|
41
41
|
import { z } from "zod";
|
|
@@ -308,6 +308,7 @@ function buildAgentInvocationInboundMessage(invocation, nowMs = Date.now()) {
|
|
|
308
308
|
}
|
|
309
309
|
},
|
|
310
310
|
receivedAtMs: nowMs,
|
|
311
|
+
publishExternally: false,
|
|
311
312
|
source: "internal"
|
|
312
313
|
};
|
|
313
314
|
}
|
|
@@ -533,6 +534,7 @@ function createAgentInvocationWorker(options) {
|
|
|
533
534
|
credentialContext: invocation.credentialContext,
|
|
534
535
|
destination: invocation.destination,
|
|
535
536
|
destinationVisibility: invocation.destinationVisibility,
|
|
537
|
+
publishExternally: context.publishExternally,
|
|
536
538
|
source: invocation.source,
|
|
537
539
|
surface: "internal"
|
|
538
540
|
},
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
coerceThreadConversationState,
|
|
3
|
-
getPersistedThreadState
|
|
4
|
-
|
|
5
|
-
} from "./chunk-AZ7EAOBE.js";
|
|
6
|
-
import {
|
|
7
|
-
recordTaskExecution
|
|
8
|
-
} from "./chunk-AVOCH2Z5.js";
|
|
3
|
+
getPersistedThreadState
|
|
4
|
+
} from "./chunk-IL4EDBMV.js";
|
|
9
5
|
import {
|
|
10
6
|
pluginTaskId,
|
|
11
7
|
pluginTaskParamsSchema,
|
|
@@ -14,8 +10,10 @@ import {
|
|
|
14
10
|
import {
|
|
15
11
|
calculateContextCompactionTargetTokens,
|
|
16
12
|
estimateTextTokens,
|
|
13
|
+
fallbackShortTitle,
|
|
14
|
+
generateShortTitle,
|
|
17
15
|
getConversationContextCompactionTriggerTokens
|
|
18
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-4EA2SFK2.js";
|
|
19
17
|
import {
|
|
20
18
|
buildDeterministicTurnId,
|
|
21
19
|
clearPendingAuth,
|
|
@@ -25,18 +23,13 @@ import {
|
|
|
25
23
|
instructionTextForProjection,
|
|
26
24
|
isToolResultError,
|
|
27
25
|
isToolResultMessage,
|
|
28
|
-
markTurnClosed,
|
|
29
26
|
markTurnCompleted,
|
|
30
27
|
normalizeToolNameFromResult,
|
|
31
28
|
stripRuntimeTurnContext
|
|
32
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-VCYSOXON.js";
|
|
33
30
|
import {
|
|
34
31
|
JUNIOR_THREAD_STATE_TTL_MS
|
|
35
32
|
} from "./chunk-3Y47VMHV.js";
|
|
36
|
-
import {
|
|
37
|
-
fallbackShortTitle,
|
|
38
|
-
generateShortTitle
|
|
39
|
-
} from "./chunk-Z4YU7Z4L.js";
|
|
40
33
|
import {
|
|
41
34
|
createPluginConversationEvents,
|
|
42
35
|
createPluginEmbedder,
|
|
@@ -44,15 +37,19 @@ import {
|
|
|
44
37
|
createPluginModel,
|
|
45
38
|
createPluginState,
|
|
46
39
|
getPlugins
|
|
47
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-ZCHIC2GM.js";
|
|
48
41
|
import {
|
|
49
42
|
getConversationStore,
|
|
50
43
|
getDb,
|
|
51
44
|
sameActorIdentity
|
|
52
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-VRHTNBA6.js";
|
|
46
|
+
import {
|
|
47
|
+
juniorConversations,
|
|
48
|
+
juniorTaskExecutions
|
|
49
|
+
} from "./chunk-D3WPMGEX.js";
|
|
53
50
|
import {
|
|
54
51
|
getStateAdapter
|
|
55
|
-
} from "./chunk-
|
|
52
|
+
} from "./chunk-2B3PT3V2.js";
|
|
56
53
|
import {
|
|
57
54
|
ProviderError,
|
|
58
55
|
botConfig,
|
|
@@ -60,7 +57,7 @@ import {
|
|
|
60
57
|
findProviderError,
|
|
61
58
|
getProviderErrorAttributes,
|
|
62
59
|
getProviderErrorUserMessage
|
|
63
|
-
} from "./chunk-
|
|
60
|
+
} from "./chunk-4GXJUYJV.js";
|
|
64
61
|
import {
|
|
65
62
|
credentialSubjectSchema
|
|
66
63
|
} from "./chunk-RUIXF3YQ.js";
|
|
@@ -71,7 +68,7 @@ import {
|
|
|
71
68
|
buildTurnFailureResponse,
|
|
72
69
|
logWarn,
|
|
73
70
|
setSpanAttributes
|
|
74
|
-
} from "./chunk-
|
|
71
|
+
} from "./chunk-EAI67NTM.js";
|
|
75
72
|
|
|
76
73
|
// src/chat/services/conversation-memory.ts
|
|
77
74
|
var CONTEXT_MIN_LIVE_MESSAGES = 12;
|
|
@@ -239,7 +236,7 @@ function pruneCompactions(compactions) {
|
|
|
239
236
|
const merged = compactions.slice(0, overflowCount);
|
|
240
237
|
const mergedSummary = merged.map((entry) => entry.summary).join("\n").slice(0, 3500);
|
|
241
238
|
const coveredMessageCount = merged.reduce(
|
|
242
|
-
(
|
|
239
|
+
(count2, entry) => count2 + entry.coveredMessageCount,
|
|
243
240
|
0
|
|
244
241
|
);
|
|
245
242
|
const compacted = {
|
|
@@ -399,14 +396,11 @@ function buildDeliveredTurnStatePatch(args) {
|
|
|
399
396
|
}
|
|
400
397
|
|
|
401
398
|
// src/chat/plugins/task-runner.ts
|
|
402
|
-
import {
|
|
403
|
-
isPrivateSource,
|
|
404
|
-
pluginRunContextSchema
|
|
405
|
-
} from "@sentry/junior-plugin-api";
|
|
399
|
+
import { pluginRunContextSchema } from "@sentry/junior-plugin-api";
|
|
406
400
|
|
|
407
401
|
// src/chat/services/turn-session-routing.ts
|
|
408
402
|
async function resolveTurnSessionRouting(args) {
|
|
409
|
-
const conversationStore = args.conversationStore ?? (await import("./db-
|
|
403
|
+
const conversationStore = args.conversationStore ?? (await import("./db-XUKZRFFK.js")).getConversationStore();
|
|
410
404
|
const conversation = await conversationStore.get({
|
|
411
405
|
conversationId: args.conversationId
|
|
412
406
|
});
|
|
@@ -431,6 +425,273 @@ import {
|
|
|
431
425
|
sourceSchema
|
|
432
426
|
} from "@sentry/junior-plugin-api";
|
|
433
427
|
import { z } from "zod";
|
|
428
|
+
|
|
429
|
+
// src/chat/tasks/execution-stats.ts
|
|
430
|
+
import {
|
|
431
|
+
and,
|
|
432
|
+
asc,
|
|
433
|
+
count,
|
|
434
|
+
desc,
|
|
435
|
+
eq,
|
|
436
|
+
gte,
|
|
437
|
+
inArray,
|
|
438
|
+
lte,
|
|
439
|
+
max,
|
|
440
|
+
or,
|
|
441
|
+
sql
|
|
442
|
+
} from "drizzle-orm";
|
|
443
|
+
var TASK_EXECUTION_TYPES = ["scheduled", "event"];
|
|
444
|
+
var TASK_EXECUTION_STATUSES = [
|
|
445
|
+
"blocked",
|
|
446
|
+
"completed",
|
|
447
|
+
"failed"
|
|
448
|
+
];
|
|
449
|
+
function utcDate(nowMs) {
|
|
450
|
+
return new Date(nowMs).toISOString().slice(0, 10);
|
|
451
|
+
}
|
|
452
|
+
function emptyDay(date) {
|
|
453
|
+
return { date, event: 0, scheduled: 0 };
|
|
454
|
+
}
|
|
455
|
+
function emptyStatusDay(date) {
|
|
456
|
+
return { blocked: 0, completed: 0, date, failed: 0 };
|
|
457
|
+
}
|
|
458
|
+
async function recordTaskExecution(type, taskId, options) {
|
|
459
|
+
const namespace = options.namespace ?? "junior";
|
|
460
|
+
const nowMs = options.nowMs ?? Date.now();
|
|
461
|
+
const status = options.status ?? "completed";
|
|
462
|
+
try {
|
|
463
|
+
await getDb().insert(juniorTaskExecutions).values({
|
|
464
|
+
...options.conversationId ? { conversationId: options.conversationId } : {},
|
|
465
|
+
executedAtMs: nowMs,
|
|
466
|
+
executionId: options.executionId,
|
|
467
|
+
kind: type,
|
|
468
|
+
namespace,
|
|
469
|
+
status,
|
|
470
|
+
taskId
|
|
471
|
+
}).onConflictDoNothing({
|
|
472
|
+
target: [
|
|
473
|
+
juniorTaskExecutions.kind,
|
|
474
|
+
juniorTaskExecutions.namespace,
|
|
475
|
+
juniorTaskExecutions.executionId
|
|
476
|
+
]
|
|
477
|
+
});
|
|
478
|
+
} catch (error) {
|
|
479
|
+
logWarn("task.execution.stat_failed", {
|
|
480
|
+
error,
|
|
481
|
+
"app.task.execution.id": options.executionId,
|
|
482
|
+
"app.task.execution.namespace": namespace,
|
|
483
|
+
"app.task.execution.status": status,
|
|
484
|
+
"app.task.execution.task_id": taskId,
|
|
485
|
+
"app.task.execution.type": type
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
async function readTaskExecutionSummaries(type, namespace, options = {}) {
|
|
490
|
+
const sevenDaysAgoMs = (options.nowMs ?? Date.now()) - 7 * 24 * 60 * 60 * 1e3;
|
|
491
|
+
const db = getDb();
|
|
492
|
+
const latest = db.selectDistinctOn([juniorTaskExecutions.taskId], {
|
|
493
|
+
conversationId: juniorTaskExecutions.conversationId,
|
|
494
|
+
taskId: juniorTaskExecutions.taskId
|
|
495
|
+
}).from(juniorTaskExecutions).where(
|
|
496
|
+
and(
|
|
497
|
+
eq(juniorTaskExecutions.kind, type),
|
|
498
|
+
eq(juniorTaskExecutions.namespace, namespace)
|
|
499
|
+
)
|
|
500
|
+
).orderBy(
|
|
501
|
+
juniorTaskExecutions.taskId,
|
|
502
|
+
desc(juniorTaskExecutions.executedAtMs),
|
|
503
|
+
desc(juniorTaskExecutions.executionId)
|
|
504
|
+
).as("latest_task_execution");
|
|
505
|
+
const rows = await db.select({
|
|
506
|
+
lastConversationId: latest.conversationId,
|
|
507
|
+
lastExecutedAtMs: max(juniorTaskExecutions.executedAtMs),
|
|
508
|
+
runsLast7Days: sql`count(*) filter (where ${juniorTaskExecutions.executedAtMs} >= ${sevenDaysAgoMs})::int`,
|
|
509
|
+
taskId: juniorTaskExecutions.taskId,
|
|
510
|
+
totalRuns: sql`count(*)::int`
|
|
511
|
+
}).from(juniorTaskExecutions).innerJoin(latest, eq(latest.taskId, juniorTaskExecutions.taskId)).where(
|
|
512
|
+
and(
|
|
513
|
+
eq(juniorTaskExecutions.kind, type),
|
|
514
|
+
eq(juniorTaskExecutions.namespace, namespace)
|
|
515
|
+
)
|
|
516
|
+
).groupBy(juniorTaskExecutions.taskId, latest.conversationId);
|
|
517
|
+
return new Map(
|
|
518
|
+
rows.map((row) => [
|
|
519
|
+
row.taskId,
|
|
520
|
+
{
|
|
521
|
+
...row.lastConversationId ? { lastConversationId: row.lastConversationId } : {},
|
|
522
|
+
...row.lastExecutedAtMs !== null ? { lastExecutedAtMs: row.lastExecutedAtMs } : {},
|
|
523
|
+
runsLast7Days: row.runsLast7Days,
|
|
524
|
+
totalRuns: row.totalRuns
|
|
525
|
+
}
|
|
526
|
+
])
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
async function readTaskExecutionDays(dayCount = 90, options = {}) {
|
|
530
|
+
const nowMs = options.nowMs ?? Date.now();
|
|
531
|
+
const end = utcDate(nowMs);
|
|
532
|
+
const endMs = Date.parse(`${end}T23:59:59.999Z`);
|
|
533
|
+
const startMs = Date.parse(`${end}T00:00:00.000Z`) - (dayCount - 1) * 864e5;
|
|
534
|
+
const executionDate = sql`to_char(to_timestamp(${juniorTaskExecutions.executedAtMs} / 1000.0) at time zone 'UTC', 'YYYY-MM-DD')`;
|
|
535
|
+
const rows = await getDb().select({
|
|
536
|
+
count: count(),
|
|
537
|
+
date: executionDate,
|
|
538
|
+
kind: juniorTaskExecutions.kind
|
|
539
|
+
}).from(juniorTaskExecutions).where(
|
|
540
|
+
and(
|
|
541
|
+
gte(juniorTaskExecutions.executedAtMs, startMs),
|
|
542
|
+
lte(juniorTaskExecutions.executedAtMs, endMs),
|
|
543
|
+
eq(juniorTaskExecutions.status, "completed")
|
|
544
|
+
)
|
|
545
|
+
).groupBy(executionDate, juniorTaskExecutions.kind).orderBy(asc(executionDate), asc(juniorTaskExecutions.kind));
|
|
546
|
+
const byDate = /* @__PURE__ */ new Map();
|
|
547
|
+
for (let offset = 0; offset < dayCount; offset += 1) {
|
|
548
|
+
const date = utcDate(startMs + offset * 864e5);
|
|
549
|
+
byDate.set(date, emptyDay(date));
|
|
550
|
+
}
|
|
551
|
+
for (const row of rows) {
|
|
552
|
+
const day = byDate.get(row.date);
|
|
553
|
+
if (!day) continue;
|
|
554
|
+
if (row.kind === "scheduled") day.scheduled = row.count;
|
|
555
|
+
else if (row.kind === "event") day.event = row.count;
|
|
556
|
+
}
|
|
557
|
+
return [...byDate.values()];
|
|
558
|
+
}
|
|
559
|
+
async function readTaskExecutionByConversationId(args) {
|
|
560
|
+
const namespace = args.namespace ?? "junior";
|
|
561
|
+
const rows = await getDb().select({
|
|
562
|
+
kind: juniorTaskExecutions.kind,
|
|
563
|
+
taskId: juniorTaskExecutions.taskId
|
|
564
|
+
}).from(juniorTaskExecutions).where(
|
|
565
|
+
and(
|
|
566
|
+
eq(juniorTaskExecutions.conversationId, args.conversationId),
|
|
567
|
+
eq(juniorTaskExecutions.namespace, namespace),
|
|
568
|
+
inArray(juniorTaskExecutions.kind, [...TASK_EXECUTION_TYPES])
|
|
569
|
+
)
|
|
570
|
+
).orderBy(
|
|
571
|
+
desc(juniorTaskExecutions.executedAtMs),
|
|
572
|
+
desc(juniorTaskExecutions.executionId)
|
|
573
|
+
).limit(1);
|
|
574
|
+
const row = rows[0];
|
|
575
|
+
if (!row) return void 0;
|
|
576
|
+
if (row.kind !== "scheduled" && row.kind !== "event") return void 0;
|
|
577
|
+
return { kind: row.kind, taskId: row.taskId };
|
|
578
|
+
}
|
|
579
|
+
async function readTaskExecutions(args) {
|
|
580
|
+
const namespace = args.namespace ?? "junior";
|
|
581
|
+
const rows = await getDb().select({
|
|
582
|
+
conversationId: juniorTaskExecutions.conversationId,
|
|
583
|
+
executedAtMs: juniorTaskExecutions.executedAtMs,
|
|
584
|
+
executionId: juniorTaskExecutions.executionId,
|
|
585
|
+
status: juniorTaskExecutions.status,
|
|
586
|
+
title: juniorConversations.title
|
|
587
|
+
}).from(juniorTaskExecutions).leftJoin(
|
|
588
|
+
juniorConversations,
|
|
589
|
+
eq(
|
|
590
|
+
juniorConversations.conversationId,
|
|
591
|
+
juniorTaskExecutions.conversationId
|
|
592
|
+
)
|
|
593
|
+
).where(
|
|
594
|
+
and(
|
|
595
|
+
eq(juniorTaskExecutions.kind, args.kind),
|
|
596
|
+
eq(juniorTaskExecutions.namespace, namespace),
|
|
597
|
+
eq(juniorTaskExecutions.taskId, args.taskId)
|
|
598
|
+
)
|
|
599
|
+
).orderBy(
|
|
600
|
+
desc(juniorTaskExecutions.executedAtMs),
|
|
601
|
+
desc(juniorTaskExecutions.executionId)
|
|
602
|
+
).limit(args.limit);
|
|
603
|
+
return rows.map((row) => {
|
|
604
|
+
const title = row.title?.trim();
|
|
605
|
+
return {
|
|
606
|
+
...row.conversationId ? { conversationId: row.conversationId } : {},
|
|
607
|
+
executedAt: new Date(row.executedAtMs).toISOString(),
|
|
608
|
+
executionId: row.executionId,
|
|
609
|
+
status: row.status,
|
|
610
|
+
...title ? { title } : {}
|
|
611
|
+
};
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
async function readTaskRuns(args) {
|
|
615
|
+
if (args.tasks.length === 0) return [];
|
|
616
|
+
const namespace = args.namespace ?? "junior";
|
|
617
|
+
const selectors = args.tasks.map(
|
|
618
|
+
(task) => and(
|
|
619
|
+
eq(juniorTaskExecutions.kind, task.kind),
|
|
620
|
+
eq(juniorTaskExecutions.taskId, task.taskId)
|
|
621
|
+
)
|
|
622
|
+
);
|
|
623
|
+
const rows = await getDb().select({
|
|
624
|
+
conversationId: juniorTaskExecutions.conversationId,
|
|
625
|
+
executedAtMs: juniorTaskExecutions.executedAtMs,
|
|
626
|
+
executionId: juniorTaskExecutions.executionId,
|
|
627
|
+
kind: juniorTaskExecutions.kind,
|
|
628
|
+
status: juniorTaskExecutions.status,
|
|
629
|
+
taskId: juniorTaskExecutions.taskId,
|
|
630
|
+
title: juniorConversations.title
|
|
631
|
+
}).from(juniorTaskExecutions).leftJoin(
|
|
632
|
+
juniorConversations,
|
|
633
|
+
eq(
|
|
634
|
+
juniorConversations.conversationId,
|
|
635
|
+
juniorTaskExecutions.conversationId
|
|
636
|
+
)
|
|
637
|
+
).where(and(eq(juniorTaskExecutions.namespace, namespace), or(...selectors))).orderBy(
|
|
638
|
+
desc(juniorTaskExecutions.executedAtMs),
|
|
639
|
+
desc(juniorTaskExecutions.executionId)
|
|
640
|
+
).limit(args.limit);
|
|
641
|
+
return rows.flatMap((row) => {
|
|
642
|
+
if (row.kind !== "scheduled" && row.kind !== "event") return [];
|
|
643
|
+
const title = row.title?.trim();
|
|
644
|
+
return [
|
|
645
|
+
{
|
|
646
|
+
...row.conversationId ? { conversationId: row.conversationId } : {},
|
|
647
|
+
executedAt: new Date(row.executedAtMs).toISOString(),
|
|
648
|
+
executionId: row.executionId,
|
|
649
|
+
kind: row.kind,
|
|
650
|
+
status: row.status,
|
|
651
|
+
taskId: row.taskId,
|
|
652
|
+
...title ? { title } : {}
|
|
653
|
+
}
|
|
654
|
+
];
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
async function readTaskExecutionStatusDays(args) {
|
|
658
|
+
const dayCount = args.dayCount ?? 90;
|
|
659
|
+
const namespace = args.namespace ?? "junior";
|
|
660
|
+
const nowMs = args.nowMs ?? Date.now();
|
|
661
|
+
const end = utcDate(nowMs);
|
|
662
|
+
const endMs = Date.parse(`${end}T23:59:59.999Z`);
|
|
663
|
+
const startMs = Date.parse(`${end}T00:00:00.000Z`) - (dayCount - 1) * 864e5;
|
|
664
|
+
const executionDate = sql`to_char(to_timestamp(${juniorTaskExecutions.executedAtMs} / 1000.0) at time zone 'UTC', 'YYYY-MM-DD')`;
|
|
665
|
+
const rows = await getDb().select({
|
|
666
|
+
count: count(),
|
|
667
|
+
date: executionDate,
|
|
668
|
+
status: juniorTaskExecutions.status
|
|
669
|
+
}).from(juniorTaskExecutions).where(
|
|
670
|
+
and(
|
|
671
|
+
eq(juniorTaskExecutions.kind, args.kind),
|
|
672
|
+
eq(juniorTaskExecutions.namespace, namespace),
|
|
673
|
+
eq(juniorTaskExecutions.taskId, args.taskId),
|
|
674
|
+
gte(juniorTaskExecutions.executedAtMs, startMs),
|
|
675
|
+
lte(juniorTaskExecutions.executedAtMs, endMs),
|
|
676
|
+
inArray(juniorTaskExecutions.status, [...TASK_EXECUTION_STATUSES])
|
|
677
|
+
)
|
|
678
|
+
).groupBy(executionDate, juniorTaskExecutions.status).orderBy(asc(executionDate), asc(juniorTaskExecutions.status));
|
|
679
|
+
const byDate = /* @__PURE__ */ new Map();
|
|
680
|
+
for (let offset = 0; offset < dayCount; offset += 1) {
|
|
681
|
+
const date = utcDate(startMs + offset * 864e5);
|
|
682
|
+
byDate.set(date, emptyStatusDay(date));
|
|
683
|
+
}
|
|
684
|
+
for (const row of rows) {
|
|
685
|
+
const day = byDate.get(row.date);
|
|
686
|
+
if (!day) continue;
|
|
687
|
+
if (row.status === "completed") day.completed = row.count;
|
|
688
|
+
else if (row.status === "failed") day.failed = row.count;
|
|
689
|
+
else if (row.status === "blocked") day.blocked = row.count;
|
|
690
|
+
}
|
|
691
|
+
return [...byDate.values()];
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
// src/chat/agent-dispatch/store.ts
|
|
434
695
|
var DISPATCH_PREFIX = "junior:agent_dispatch";
|
|
435
696
|
var DISPATCH_LOCK_TTL_MS = 10 * 60 * 1e3;
|
|
436
697
|
var DISPATCH_MAILBOX_APPEND_INDEX_LOCK_TTL_MS = 1e4;
|
|
@@ -942,8 +1203,15 @@ function messageExistedAtRunCompletion(message, completedAtMs) {
|
|
|
942
1203
|
return messageTimestampMs !== void 0 && messageTimestampMs <= completedAtMs;
|
|
943
1204
|
}
|
|
944
1205
|
async function loadConversationContextTranscriptEntries(record, source, runActor) {
|
|
945
|
-
|
|
946
|
-
|
|
1206
|
+
switch (source.platform) {
|
|
1207
|
+
case "slack":
|
|
1208
|
+
if (source.visibility === "private") {
|
|
1209
|
+
return [];
|
|
1210
|
+
}
|
|
1211
|
+
break;
|
|
1212
|
+
case "web":
|
|
1213
|
+
case "local":
|
|
1214
|
+
return [];
|
|
947
1215
|
}
|
|
948
1216
|
const state = await getPersistedThreadState(record.conversationId);
|
|
949
1217
|
const conversation = coerceThreadConversationState(state);
|
|
@@ -1230,37 +1498,14 @@ function getTurnUserReplyAttachmentContext(message) {
|
|
|
1230
1498
|
};
|
|
1231
1499
|
}
|
|
1232
1500
|
|
|
1233
|
-
// src/chat/runtime/auth-pause-state.ts
|
|
1234
|
-
function completeAuthPauseTurn(args) {
|
|
1235
|
-
markConversationMessage(
|
|
1236
|
-
args.conversation,
|
|
1237
|
-
getTurnUserMessageId(args.conversation, args.sessionId),
|
|
1238
|
-
{
|
|
1239
|
-
replied: true,
|
|
1240
|
-
skippedReason: void 0
|
|
1241
|
-
}
|
|
1242
|
-
);
|
|
1243
|
-
markTurnClosed({
|
|
1244
|
-
conversation: args.conversation,
|
|
1245
|
-
nowMs: Date.now(),
|
|
1246
|
-
sessionId: args.sessionId
|
|
1247
|
-
});
|
|
1248
|
-
}
|
|
1249
|
-
async function persistAuthPauseTurnState(args) {
|
|
1250
|
-
const currentState = await getPersistedThreadState(args.threadStateId);
|
|
1251
|
-
const conversation = coerceThreadConversationState(currentState);
|
|
1252
|
-
await hydrateConversationMessages({
|
|
1253
|
-
conversation,
|
|
1254
|
-
conversationId: args.threadStateId
|
|
1255
|
-
});
|
|
1256
|
-
completeAuthPauseTurn({
|
|
1257
|
-
conversation,
|
|
1258
|
-
sessionId: args.sessionId
|
|
1259
|
-
});
|
|
1260
|
-
await persistThreadStateById(args.threadStateId, { conversation });
|
|
1261
|
-
}
|
|
1262
|
-
|
|
1263
1501
|
export {
|
|
1502
|
+
recordTaskExecution,
|
|
1503
|
+
readTaskExecutionSummaries,
|
|
1504
|
+
readTaskExecutionDays,
|
|
1505
|
+
readTaskExecutionByConversationId,
|
|
1506
|
+
readTaskExecutions,
|
|
1507
|
+
readTaskRuns,
|
|
1508
|
+
readTaskExecutionStatusDays,
|
|
1264
1509
|
getDispatchConversationId,
|
|
1265
1510
|
getDispatchInputMessageId,
|
|
1266
1511
|
getDispatchInputMessageIds,
|
|
@@ -1299,7 +1544,5 @@ export {
|
|
|
1299
1544
|
getInterruptionMarker,
|
|
1300
1545
|
requireTurnFailureEventId,
|
|
1301
1546
|
getAgentTurnDiagnosticsAttributes,
|
|
1302
|
-
finalizeFailedTurnReplyWithEvent
|
|
1303
|
-
completeAuthPauseTurn,
|
|
1304
|
-
persistAuthPauseTurnState
|
|
1547
|
+
finalizeFailedTurnReplyWithEvent
|
|
1305
1548
|
};
|