@sentry/junior-scheduler 0.74.1 → 0.76.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/db/schema.d.ts +223 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +624 -455
- package/dist/plugin.d.ts +2 -2
- package/dist/schedule-tools.d.ts +10 -9
- package/dist/store.d.ts +21 -3
- package/dist/types.d.ts +2 -5
- package/migrations/0001_scheduler.sql +35 -0
- package/package.json +6 -2
- package/src/db/schema.ts +53 -0
- package/src/index.ts +6 -2
- package/src/plugin.ts +89 -30
- package/src/schedule-tools.ts +68 -36
- package/src/store.ts +842 -47
- package/src/types.ts +2 -5
- package/dist/prompt.d.ts +0 -7
- package/src/prompt.ts +0 -90
package/src/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
2
|
+
PluginCredentialSubject,
|
|
3
3
|
SlackDestination,
|
|
4
4
|
} from "@sentry/junior-plugin-api";
|
|
5
5
|
|
|
@@ -71,7 +71,7 @@ export interface ScheduledTask {
|
|
|
71
71
|
createdAtMs: number;
|
|
72
72
|
createdBy: ScheduledTaskPrincipal;
|
|
73
73
|
conversationAccess?: ScheduledTaskConversationAccess;
|
|
74
|
-
credentialSubject?:
|
|
74
|
+
credentialSubject?: PluginCredentialSubject;
|
|
75
75
|
destination: SlackDestination;
|
|
76
76
|
executionActor?: ScheduledTaskExecutionActor;
|
|
77
77
|
lastRunAtMs?: number;
|
|
@@ -83,7 +83,6 @@ export interface ScheduledTask {
|
|
|
83
83
|
statusReason?: string;
|
|
84
84
|
task: ScheduledTaskSpec;
|
|
85
85
|
updatedAtMs: number;
|
|
86
|
-
version: number;
|
|
87
86
|
}
|
|
88
87
|
|
|
89
88
|
export interface ScheduledRun {
|
|
@@ -93,11 +92,9 @@ export interface ScheduledRun {
|
|
|
93
92
|
completedAtMs?: number;
|
|
94
93
|
dispatchId?: string;
|
|
95
94
|
errorMessage?: string;
|
|
96
|
-
idempotencyKey: string;
|
|
97
95
|
resultMessageTs?: string;
|
|
98
96
|
scheduledForMs: number;
|
|
99
97
|
startedAtMs?: number;
|
|
100
98
|
status: ScheduledRunStatus;
|
|
101
99
|
taskId: string;
|
|
102
|
-
taskVersion: number;
|
|
103
100
|
}
|
package/dist/prompt.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type ScheduledRun, type ScheduledTask } from "./types";
|
|
2
|
-
/** Build the marker-delimited user prompt for one scheduled task execution. */
|
|
3
|
-
export declare function buildScheduledTaskRunPrompt(args: {
|
|
4
|
-
nowMs: number;
|
|
5
|
-
run: ScheduledRun;
|
|
6
|
-
task: ScheduledTask;
|
|
7
|
-
}): string;
|
package/src/prompt.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SCHEDULED_TASK_SYSTEM_ACTOR,
|
|
3
|
-
type ScheduledRun,
|
|
4
|
-
type ScheduledTask,
|
|
5
|
-
} from "./types";
|
|
6
|
-
import { sanitizeScheduledTaskPrincipal } from "./identity";
|
|
7
|
-
|
|
8
|
-
function escapeXml(value: string): string {
|
|
9
|
-
return value
|
|
10
|
-
.replaceAll("&", "&")
|
|
11
|
-
.replaceAll("<", "<")
|
|
12
|
-
.replaceAll(">", ">")
|
|
13
|
-
.replaceAll('"', """)
|
|
14
|
-
.replaceAll("'", "'");
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const EXECUTION_RULES = [
|
|
18
|
-
"- Execute as the scheduled-task system actor; creator metadata is audit context, not an active user identity.",
|
|
19
|
-
"- Complete the task without asking follow-up questions unless access, approval, or required input is missing.",
|
|
20
|
-
"- Use the available tools and skills that are relevant to the task contract.",
|
|
21
|
-
"- Do not create, edit, or discuss scheduling during this run; the stored schedule already fired.",
|
|
22
|
-
"- For reminder tasks, deliver the reminder message now instead of explaining how reminders or delayed posts work.",
|
|
23
|
-
"- If blocked, report the specific missing provider, permission, configuration, or input.",
|
|
24
|
-
"- Keep the final result shaped for the configured destination audience.",
|
|
25
|
-
];
|
|
26
|
-
|
|
27
|
-
function renderOptionalLine(name: string, value: string | undefined): string[] {
|
|
28
|
-
return value?.trim() ? [`- ${name}: ${escapeXml(value.trim())}`] : [];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** Build the marker-delimited user prompt for one scheduled task execution. */
|
|
32
|
-
export function buildScheduledTaskRunPrompt(args: {
|
|
33
|
-
nowMs: number;
|
|
34
|
-
run: ScheduledRun;
|
|
35
|
-
task: ScheduledTask;
|
|
36
|
-
}): string {
|
|
37
|
-
const { run, task } = args;
|
|
38
|
-
const destination = task.destination;
|
|
39
|
-
const creator = sanitizeScheduledTaskPrincipal(task.createdBy);
|
|
40
|
-
const executionActor = task.executionActor ?? SCHEDULED_TASK_SYSTEM_ACTOR;
|
|
41
|
-
if (!task.task.text?.trim()) {
|
|
42
|
-
throw new Error("Scheduled task text is required");
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return [
|
|
46
|
-
"<scheduled-task-run>",
|
|
47
|
-
"This is an autonomous scheduled run. Treat the stored task contract as the user request for this turn.",
|
|
48
|
-
"",
|
|
49
|
-
"<scheduled-task>",
|
|
50
|
-
`- id: ${escapeXml(task.id)}`,
|
|
51
|
-
"<task-text>",
|
|
52
|
-
escapeXml(task.task.text),
|
|
53
|
-
"</task-text>",
|
|
54
|
-
"</scheduled-task>",
|
|
55
|
-
"",
|
|
56
|
-
"<run-context>",
|
|
57
|
-
`- run_id: ${escapeXml(run.id)}`,
|
|
58
|
-
`- task_version: ${run.taskVersion}`,
|
|
59
|
-
`- scheduled_for: ${new Date(run.scheduledForMs).toISOString()}`,
|
|
60
|
-
`- running_at: ${new Date(args.nowMs).toISOString()}`,
|
|
61
|
-
`- schedule: ${escapeXml(task.schedule.description)}`,
|
|
62
|
-
`- timezone: ${escapeXml(task.schedule.timezone)}`,
|
|
63
|
-
`- schedule_kind: ${task.schedule.kind}`,
|
|
64
|
-
`- execution_actor_type: ${executionActor.type}`,
|
|
65
|
-
`- execution_actor_id: ${escapeXml(executionActor.id)}`,
|
|
66
|
-
...(task.schedule.recurrence
|
|
67
|
-
? [
|
|
68
|
-
`- recurrence_frequency: ${task.schedule.recurrence.frequency}`,
|
|
69
|
-
`- recurrence_interval: ${task.schedule.recurrence.interval}`,
|
|
70
|
-
`- recurrence_start_date: ${escapeXml(task.schedule.recurrence.startDate)}`,
|
|
71
|
-
]
|
|
72
|
-
: []),
|
|
73
|
-
`- creator_slack_user_id: ${escapeXml(creator.slackUserId)}`,
|
|
74
|
-
...renderOptionalLine("creator_user_name", creator.userName),
|
|
75
|
-
...renderOptionalLine("creator_full_name", creator.fullName),
|
|
76
|
-
`- destination_platform: ${destination.platform}`,
|
|
77
|
-
`- destination_team_id: ${escapeXml(destination.teamId)}`,
|
|
78
|
-
`- destination_channel_id: ${escapeXml(destination.channelId)}`,
|
|
79
|
-
"</run-context>",
|
|
80
|
-
"",
|
|
81
|
-
"<execution-rules>",
|
|
82
|
-
...EXECUTION_RULES,
|
|
83
|
-
"</execution-rules>",
|
|
84
|
-
"",
|
|
85
|
-
'<current-instruction priority="highest">',
|
|
86
|
-
"Execute the scheduled task now and provide the final result for the configured destination.",
|
|
87
|
-
"</current-instruction>",
|
|
88
|
-
"</scheduled-task-run>",
|
|
89
|
-
].join("\n");
|
|
90
|
-
}
|