@sentry/junior 0.73.0 → 0.74.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/api-reference.d.ts +1 -1
- package/dist/app.js +258 -62
- package/dist/chat/app/production.d.ts +3 -0
- package/dist/chat/config.d.ts +3 -0
- package/dist/chat/conversations/configured.d.ts +5 -0
- package/dist/chat/conversations/sql/migrations.d.ts +11 -0
- package/dist/chat/conversations/sql/schema/conversations.d.ts +435 -0
- package/dist/chat/conversations/sql/schema/destinations.d.ts +200 -0
- package/dist/chat/conversations/sql/schema/identities.d.ts +214 -0
- package/dist/chat/conversations/sql/schema/migrations.d.ts +58 -0
- package/dist/chat/conversations/sql/schema/timestamps.d.ts +1 -0
- package/dist/chat/conversations/sql/schema.d.ts +910 -0
- package/dist/chat/conversations/sql/store.d.ts +52 -0
- package/dist/chat/conversations/state.d.ts +4 -0
- package/dist/chat/conversations/store.d.ts +57 -0
- package/dist/chat/ingress/slack-webhook.d.ts +2 -0
- package/dist/chat/plugins/agent-hooks.d.ts +2 -2
- package/dist/chat/respond.d.ts +1 -1
- package/dist/chat/services/mcp-auth-orchestration.d.ts +6 -5
- package/dist/chat/services/pending-auth.d.ts +2 -0
- package/dist/chat/services/plugin-auth-orchestration.d.ts +7 -6
- package/dist/chat/sql/db.d.ts +20 -0
- package/dist/chat/sql/neon.d.ts +9 -0
- package/dist/chat/sql/schema.d.ts +906 -0
- package/dist/chat/state/turn-session.d.ts +3 -0
- package/dist/chat/task-execution/slack-work.d.ts +2 -0
- package/dist/chat/task-execution/state.d.ts +209 -0
- package/dist/chat/task-execution/store.d.ts +30 -114
- package/dist/chat/task-execution/vercel-callback.d.ts +2 -0
- package/dist/chat/task-execution/worker.d.ts +2 -0
- package/dist/{chunk-ZDA2HYX5.js → chunk-2LUZA3LY.js} +3 -3
- package/dist/{chunk-RY6AL5C7.js → chunk-6UP2Z2RZ.js} +2 -2
- package/dist/{chunk-DIMX5F3T.js → chunk-F6HWCPOC.js} +1 -1
- package/dist/{chunk-WS2EG3GW.js → chunk-GM7HTXYC.js} +6 -0
- package/dist/{chunk-UZVHXZ7V.js → chunk-HYHKTFG2.js} +59 -15
- package/dist/chunk-JL2SLRAT.js +1970 -0
- package/dist/{chunk-OQSYYOLM.js → chunk-SQGMG7OD.js} +128 -114
- package/dist/{chunk-QUXPUKBH.js → chunk-Y7X25LFY.js} +1 -1
- package/dist/{chunk-UOTZ3EEQ.js → chunk-YOHFWWBV.js} +1 -1
- package/dist/{chunk-V4VYUY4A.js → chunk-YRDS7VKO.js} +1 -1
- package/dist/cli/chat.js +2 -2
- package/dist/cli/init.js +1 -1
- package/dist/cli/snapshot-warmup.js +3 -3
- package/dist/cli/upgrade.js +77 -7
- package/dist/instrumentation.js +0 -1
- package/dist/nitro.js +3 -3
- package/dist/reporting/conversations.d.ts +13 -3
- package/dist/reporting.d.ts +9 -2
- package/dist/reporting.js +101 -37
- package/dist/{runner-LMAM4OGD.js → runner-27NP2TEO.js} +7 -7
- package/dist/vercel.d.ts +6 -1
- package/dist/vercel.js +1 -1
- package/package.json +9 -4
- package/dist/chunk-AL5T52ZD.js +0 -1119
|
@@ -2,6 +2,7 @@ import type { Destination } from "@sentry/junior-plugin-api";
|
|
|
2
2
|
import type { PiMessage } from "@/chat/pi/messages";
|
|
3
3
|
import { type StoredSlackRequester } from "@/chat/requester";
|
|
4
4
|
import type { AgentTurnUsage } from "@/chat/usage";
|
|
5
|
+
import type { ConversationStore } from "@/chat/conversations/store";
|
|
5
6
|
export type AgentTurnSessionStatus = "running" | "awaiting_resume" | "completed" | "failed" | "abandoned";
|
|
6
7
|
export type AgentTurnSurface = "slack" | "api" | "scheduler" | "internal";
|
|
7
8
|
export type AgentTurnResumeReason = "timeout" | "auth" | "yield";
|
|
@@ -40,6 +41,7 @@ export declare function upsertAgentTurnSessionRecord(args: {
|
|
|
40
41
|
destination?: Destination;
|
|
41
42
|
lastProgressAtMs?: number;
|
|
42
43
|
loadedSkillNames?: string[];
|
|
44
|
+
conversationStore?: ConversationStore;
|
|
43
45
|
sessionId: string;
|
|
44
46
|
sliceId: number;
|
|
45
47
|
state: AgentTurnSessionStatus;
|
|
@@ -62,6 +64,7 @@ export declare function recordAgentTurnSessionSummary(args: {
|
|
|
62
64
|
destination?: Destination;
|
|
63
65
|
lastProgressAtMs?: number;
|
|
64
66
|
loadedSkillNames?: string[];
|
|
67
|
+
conversationStore?: ConversationStore;
|
|
65
68
|
requester?: StoredSlackRequester;
|
|
66
69
|
resumeReason?: AgentTurnResumeReason;
|
|
67
70
|
sessionId: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { SlackAdapter } from "@chat-adapter/slack";
|
|
2
2
|
import { Message, ThreadImpl, type SerializedMessage, type SerializedThread, type StateAdapter } from "chat";
|
|
3
3
|
import type { SlackTurnRuntime } from "@/chat/runtime/slack-runtime";
|
|
4
|
+
import type { ConversationStore } from "@/chat/conversations/store";
|
|
4
5
|
import type { InboundMessage } from "@/chat/task-execution/store";
|
|
5
6
|
import type { ConversationWorkerContext, ConversationWorkerResult } from "@/chat/task-execution/worker";
|
|
6
7
|
import { type SlackInstallationContext } from "@/chat/slack/adapter-context";
|
|
@@ -18,6 +19,7 @@ export interface CreateSlackConversationWorkerOptions {
|
|
|
18
19
|
getSlackAdapter: () => SlackAdapter;
|
|
19
20
|
lookupSlackUser?: (teamId: string, userId: string) => Promise<SlackRequesterProfile | null | undefined>;
|
|
20
21
|
resumeAwaitingContinuation: (conversationId: string) => Promise<boolean>;
|
|
22
|
+
conversationStore?: ConversationStore;
|
|
21
23
|
runtime: Pick<SlackTurnRuntime<unknown>, "handleNewMention" | "handleSubscribedMessage">;
|
|
22
24
|
state?: StateAdapter;
|
|
23
25
|
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import type { StateAdapter } from "chat";
|
|
2
|
+
import type { Destination } from "@sentry/junior-plugin-api";
|
|
3
|
+
import { type StoredSlackRequester } from "@/chat/requester";
|
|
4
|
+
export declare const CONVERSATION_BY_ACTIVITY_INDEX_KEY = "junior:conversation:by-activity";
|
|
5
|
+
export declare const CONVERSATION_ACTIVE_INDEX_KEY = "junior:conversation:active";
|
|
6
|
+
export declare const CONVERSATION_WORK_LEASE_TTL_MS = 90000;
|
|
7
|
+
export declare const CONVERSATION_WORK_CHECK_IN_INTERVAL_MS = 15000;
|
|
8
|
+
export declare const CONVERSATION_WORK_STALE_ENQUEUE_MS = 60000;
|
|
9
|
+
export type Source = "api" | "internal" | "local" | "plugin" | "scheduler" | "slack";
|
|
10
|
+
export type ExecutionStatus = "awaiting_resume" | "idle" | "pending" | "running";
|
|
11
|
+
export interface AgentInput {
|
|
12
|
+
attachments?: unknown[];
|
|
13
|
+
authorId?: string;
|
|
14
|
+
metadata?: Record<string, unknown>;
|
|
15
|
+
text: string;
|
|
16
|
+
}
|
|
17
|
+
export interface InboundMessage {
|
|
18
|
+
conversationId: string;
|
|
19
|
+
createdAtMs: number;
|
|
20
|
+
destination: Destination;
|
|
21
|
+
inboundMessageId: string;
|
|
22
|
+
injectedAtMs?: number;
|
|
23
|
+
input: AgentInput;
|
|
24
|
+
receivedAtMs: number;
|
|
25
|
+
source: Source;
|
|
26
|
+
}
|
|
27
|
+
export interface Lease {
|
|
28
|
+
acquiredAtMs: number;
|
|
29
|
+
expiresAtMs: number;
|
|
30
|
+
lastCheckInAtMs: number;
|
|
31
|
+
token: string;
|
|
32
|
+
}
|
|
33
|
+
export interface ConversationExecution {
|
|
34
|
+
inboundMessageIds: string[];
|
|
35
|
+
lastCheckpointAtMs?: number;
|
|
36
|
+
lastEnqueuedAtMs?: number;
|
|
37
|
+
lease?: Lease;
|
|
38
|
+
pendingCount: number;
|
|
39
|
+
pendingMessages: InboundMessage[];
|
|
40
|
+
runId?: string;
|
|
41
|
+
status: ExecutionStatus;
|
|
42
|
+
updatedAtMs?: number;
|
|
43
|
+
}
|
|
44
|
+
export interface Conversation {
|
|
45
|
+
channelName?: string;
|
|
46
|
+
conversationId: string;
|
|
47
|
+
createdAtMs: number;
|
|
48
|
+
destination?: Destination;
|
|
49
|
+
execution: ConversationExecution;
|
|
50
|
+
lastActivityAtMs: number;
|
|
51
|
+
requester?: StoredSlackRequester;
|
|
52
|
+
schemaVersion: 1;
|
|
53
|
+
source?: Source;
|
|
54
|
+
title?: string;
|
|
55
|
+
updatedAtMs: number;
|
|
56
|
+
}
|
|
57
|
+
export interface ConversationWorkLease {
|
|
58
|
+
acquiredAtMs: number;
|
|
59
|
+
lastCheckInAtMs: number;
|
|
60
|
+
leaseExpiresAtMs: number;
|
|
61
|
+
leaseToken: string;
|
|
62
|
+
}
|
|
63
|
+
export interface ConversationWorkState extends Conversation {
|
|
64
|
+
lastEnqueuedAtMs?: number;
|
|
65
|
+
lease?: ConversationWorkLease;
|
|
66
|
+
messages: InboundMessage[];
|
|
67
|
+
needsRun: boolean;
|
|
68
|
+
}
|
|
69
|
+
export interface StartConversationWorkAcquired {
|
|
70
|
+
leaseExpiresAtMs: number;
|
|
71
|
+
leaseToken: string;
|
|
72
|
+
status: "acquired";
|
|
73
|
+
}
|
|
74
|
+
export interface StartConversationWorkActive {
|
|
75
|
+
leaseExpiresAtMs: number;
|
|
76
|
+
status: "active";
|
|
77
|
+
}
|
|
78
|
+
export interface StartConversationWorkNoWork {
|
|
79
|
+
status: "no_work";
|
|
80
|
+
}
|
|
81
|
+
export type StartConversationWorkResult = StartConversationWorkAcquired | StartConversationWorkActive | StartConversationWorkNoWork;
|
|
82
|
+
export interface AppendInboundMessageResult {
|
|
83
|
+
status: "appended" | "duplicate";
|
|
84
|
+
}
|
|
85
|
+
export interface AppendAndEnqueueInboundMessageResult extends AppendInboundMessageResult {
|
|
86
|
+
queueMessageId?: string;
|
|
87
|
+
}
|
|
88
|
+
export interface RequestConversationWorkResult {
|
|
89
|
+
status: "created" | "updated";
|
|
90
|
+
}
|
|
91
|
+
/** Return a persisted conversation record, if one exists. */
|
|
92
|
+
export declare function getConversation(args: {
|
|
93
|
+
conversationId: string;
|
|
94
|
+
state?: StateAdapter;
|
|
95
|
+
}): Promise<Conversation | undefined>;
|
|
96
|
+
/** Return a persisted conversation work record, if one exists. */
|
|
97
|
+
export declare function getConversationWorkState(args: {
|
|
98
|
+
conversationId: string;
|
|
99
|
+
state?: StateAdapter;
|
|
100
|
+
}): Promise<ConversationWorkState | undefined>;
|
|
101
|
+
/** Count mailbox messages that have not yet reached the session log. */
|
|
102
|
+
export declare function countPendingConversationMessages(conversation: Conversation): number;
|
|
103
|
+
/** Return whether a conversation has pending or resumable execution work. */
|
|
104
|
+
export declare function hasRunnableConversationWork(conversation: Conversation): boolean;
|
|
105
|
+
/** Persist one inbound message idempotently in its conversation mailbox. */
|
|
106
|
+
export declare function appendInboundMessage(args: {
|
|
107
|
+
message: InboundMessage;
|
|
108
|
+
nowMs?: number;
|
|
109
|
+
state?: StateAdapter;
|
|
110
|
+
}): Promise<AppendInboundMessageResult>;
|
|
111
|
+
/** Mark a conversation runnable when there is no new mailbox message. */
|
|
112
|
+
export declare function requestConversationWork(args: {
|
|
113
|
+
conversationId: string;
|
|
114
|
+
destination: Destination;
|
|
115
|
+
nowMs?: number;
|
|
116
|
+
state?: StateAdapter;
|
|
117
|
+
}): Promise<RequestConversationWorkResult>;
|
|
118
|
+
/** Record visible conversation activity without making the conversation runnable. */
|
|
119
|
+
export declare function recordConversationActivity(args: {
|
|
120
|
+
activityAtMs?: number;
|
|
121
|
+
channelName?: string;
|
|
122
|
+
conversationId: string;
|
|
123
|
+
destination?: Destination;
|
|
124
|
+
nowMs?: number;
|
|
125
|
+
requester?: StoredSlackRequester;
|
|
126
|
+
source?: Source;
|
|
127
|
+
state?: StateAdapter;
|
|
128
|
+
title?: string;
|
|
129
|
+
}): Promise<void>;
|
|
130
|
+
/** Record that a wake-up nudge was accepted for the conversation. */
|
|
131
|
+
export declare function markConversationWorkEnqueued(args: {
|
|
132
|
+
conversationId: string;
|
|
133
|
+
nowMs?: number;
|
|
134
|
+
state?: StateAdapter;
|
|
135
|
+
}): Promise<void>;
|
|
136
|
+
/** Try to acquire the durable execution lease for one conversation. */
|
|
137
|
+
export declare function startConversationWork(args: {
|
|
138
|
+
conversationId: string;
|
|
139
|
+
nowMs?: number;
|
|
140
|
+
state?: StateAdapter;
|
|
141
|
+
}): Promise<StartConversationWorkResult>;
|
|
142
|
+
/** Extend the durable execution lease when the worker checks in. */
|
|
143
|
+
export declare function checkInConversationWork(args: {
|
|
144
|
+
conversationId: string;
|
|
145
|
+
leaseToken: string;
|
|
146
|
+
nowMs?: number;
|
|
147
|
+
state?: StateAdapter;
|
|
148
|
+
}): Promise<boolean>;
|
|
149
|
+
/** Drain pending mailbox entries after the caller has durably injected them. */
|
|
150
|
+
export declare function drainConversationMailbox(args: {
|
|
151
|
+
conversationId: string;
|
|
152
|
+
inject: (messages: InboundMessage[]) => Promise<void>;
|
|
153
|
+
leaseToken: string;
|
|
154
|
+
nowMs?: number;
|
|
155
|
+
state?: StateAdapter;
|
|
156
|
+
}): Promise<InboundMessage[]>;
|
|
157
|
+
/** Mark selected leased mailbox entries after their session-log injection succeeds. */
|
|
158
|
+
export declare function markConversationMessagesInjected(args: {
|
|
159
|
+
conversationId: string;
|
|
160
|
+
inboundMessageIds: string[];
|
|
161
|
+
leaseToken: string;
|
|
162
|
+
nowMs?: number;
|
|
163
|
+
state?: StateAdapter;
|
|
164
|
+
}): Promise<boolean>;
|
|
165
|
+
/** Mark the leased conversation as needing another queue-delivered slice. */
|
|
166
|
+
export declare function requestConversationContinuation(args: {
|
|
167
|
+
conversationId: string;
|
|
168
|
+
destination: Destination;
|
|
169
|
+
leaseToken: string;
|
|
170
|
+
nowMs?: number;
|
|
171
|
+
state?: StateAdapter;
|
|
172
|
+
}): Promise<boolean>;
|
|
173
|
+
/** Release the durable execution lease without changing completion state. */
|
|
174
|
+
export declare function releaseConversationWork(args: {
|
|
175
|
+
conversationId: string;
|
|
176
|
+
leaseToken: string;
|
|
177
|
+
nowMs?: number;
|
|
178
|
+
state?: StateAdapter;
|
|
179
|
+
}): Promise<boolean>;
|
|
180
|
+
/** Finish a leased conversation and report whether runnable work remains. */
|
|
181
|
+
export declare function completeConversationWork(args: {
|
|
182
|
+
conversationId: string;
|
|
183
|
+
leaseToken: string;
|
|
184
|
+
nowMs?: number;
|
|
185
|
+
state?: StateAdapter;
|
|
186
|
+
}): Promise<"completed" | "lost_lease" | "pending">;
|
|
187
|
+
/** Clear an expired durable lease so a later worker can resume safely. */
|
|
188
|
+
export declare function clearExpiredConversationLease(args: {
|
|
189
|
+
conversationId: string;
|
|
190
|
+
nowMs?: number;
|
|
191
|
+
state?: StateAdapter;
|
|
192
|
+
}): Promise<boolean>;
|
|
193
|
+
/** Remove one conversation from the active index after it is missing or idle. */
|
|
194
|
+
export declare function removeActiveConversation(args: {
|
|
195
|
+
conversationId: string;
|
|
196
|
+
state?: StateAdapter;
|
|
197
|
+
}): Promise<void>;
|
|
198
|
+
/** List active conversation ids by oldest execution update first. */
|
|
199
|
+
export declare function listActiveConversationIds(args?: {
|
|
200
|
+
limit?: number;
|
|
201
|
+
staleBeforeMs?: number;
|
|
202
|
+
state?: StateAdapter;
|
|
203
|
+
}): Promise<string[]>;
|
|
204
|
+
/** List retained conversations by newest visible activity first. */
|
|
205
|
+
export declare function listConversationsByActivity(args?: {
|
|
206
|
+
limit?: number;
|
|
207
|
+
offset?: number;
|
|
208
|
+
state?: StateAdapter;
|
|
209
|
+
}): Promise<Conversation[]>;
|
|
@@ -1,104 +1,19 @@
|
|
|
1
1
|
import type { StateAdapter } from "chat";
|
|
2
|
-
import type {
|
|
3
|
-
import { type StoredSlackRequester } from "@/chat/requester";
|
|
2
|
+
import type { ConversationStore } from "@/chat/conversations/store";
|
|
4
3
|
import type { ConversationWorkQueue } from "./queue";
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
export declare const CONVERSATION_WORK_CHECK_IN_INTERVAL_MS = 15000;
|
|
9
|
-
export declare const CONVERSATION_WORK_STALE_ENQUEUE_MS = 60000;
|
|
10
|
-
export type Source = "api" | "internal" | "local" | "plugin" | "scheduler" | "slack";
|
|
11
|
-
export type ExecutionStatus = "awaiting_resume" | "idle" | "pending" | "running";
|
|
12
|
-
export interface AgentInput {
|
|
13
|
-
attachments?: unknown[];
|
|
14
|
-
authorId?: string;
|
|
15
|
-
metadata?: Record<string, unknown>;
|
|
16
|
-
text: string;
|
|
17
|
-
}
|
|
18
|
-
export interface InboundMessage {
|
|
19
|
-
conversationId: string;
|
|
20
|
-
createdAtMs: number;
|
|
21
|
-
destination: Destination;
|
|
22
|
-
inboundMessageId: string;
|
|
23
|
-
injectedAtMs?: number;
|
|
24
|
-
input: AgentInput;
|
|
25
|
-
receivedAtMs: number;
|
|
26
|
-
source: Source;
|
|
27
|
-
}
|
|
28
|
-
export interface Lease {
|
|
29
|
-
acquiredAtMs: number;
|
|
30
|
-
expiresAtMs: number;
|
|
31
|
-
lastCheckInAtMs: number;
|
|
32
|
-
token: string;
|
|
33
|
-
}
|
|
34
|
-
export interface ConversationExecution {
|
|
35
|
-
inboundMessageIds: string[];
|
|
36
|
-
lastCheckpointAtMs?: number;
|
|
37
|
-
lastEnqueuedAtMs?: number;
|
|
38
|
-
lease?: Lease;
|
|
39
|
-
pendingCount: number;
|
|
40
|
-
pendingMessages: InboundMessage[];
|
|
41
|
-
runId?: string;
|
|
42
|
-
status: ExecutionStatus;
|
|
43
|
-
updatedAtMs?: number;
|
|
44
|
-
}
|
|
45
|
-
export interface Conversation {
|
|
46
|
-
channelName?: string;
|
|
47
|
-
conversationId: string;
|
|
48
|
-
createdAtMs: number;
|
|
49
|
-
destination?: Destination;
|
|
50
|
-
execution: ConversationExecution;
|
|
51
|
-
lastActivityAtMs: number;
|
|
52
|
-
requester?: StoredSlackRequester;
|
|
53
|
-
schemaVersion: 1;
|
|
54
|
-
source?: Source;
|
|
55
|
-
title?: string;
|
|
56
|
-
updatedAtMs: number;
|
|
57
|
-
}
|
|
58
|
-
export interface ConversationWorkLease {
|
|
59
|
-
acquiredAtMs: number;
|
|
60
|
-
lastCheckInAtMs: number;
|
|
61
|
-
leaseExpiresAtMs: number;
|
|
62
|
-
leaseToken: string;
|
|
63
|
-
}
|
|
64
|
-
export interface ConversationWorkState extends Conversation {
|
|
65
|
-
lastEnqueuedAtMs?: number;
|
|
66
|
-
lease?: ConversationWorkLease;
|
|
67
|
-
messages: InboundMessage[];
|
|
68
|
-
needsRun: boolean;
|
|
69
|
-
}
|
|
70
|
-
export interface StartConversationWorkAcquired {
|
|
71
|
-
leaseExpiresAtMs: number;
|
|
72
|
-
leaseToken: string;
|
|
73
|
-
status: "acquired";
|
|
74
|
-
}
|
|
75
|
-
export interface StartConversationWorkActive {
|
|
76
|
-
leaseExpiresAtMs: number;
|
|
77
|
-
status: "active";
|
|
78
|
-
}
|
|
79
|
-
export interface StartConversationWorkNoWork {
|
|
80
|
-
status: "no_work";
|
|
81
|
-
}
|
|
82
|
-
export type StartConversationWorkResult = StartConversationWorkAcquired | StartConversationWorkActive | StartConversationWorkNoWork;
|
|
83
|
-
export interface AppendInboundMessageResult {
|
|
84
|
-
status: "appended" | "duplicate";
|
|
85
|
-
}
|
|
86
|
-
export interface AppendAndEnqueueInboundMessageResult extends AppendInboundMessageResult {
|
|
87
|
-
queueMessageId?: string;
|
|
88
|
-
}
|
|
89
|
-
export interface RequestConversationWorkResult {
|
|
90
|
-
status: "created" | "updated";
|
|
91
|
-
}
|
|
4
|
+
import * as workState from "./state";
|
|
5
|
+
export { CONVERSATION_ACTIVE_INDEX_KEY, CONVERSATION_BY_ACTIVITY_INDEX_KEY, CONVERSATION_WORK_CHECK_IN_INTERVAL_MS, CONVERSATION_WORK_LEASE_TTL_MS, CONVERSATION_WORK_STALE_ENQUEUE_MS, type AgentInput, type AppendAndEnqueueInboundMessageResult, type AppendInboundMessageResult, type Conversation, type ConversationExecution, type ConversationWorkLease, type ConversationWorkState, type ExecutionStatus, type InboundMessage, type Lease, type RequestConversationWorkResult, type Source, type StartConversationWorkAcquired, type StartConversationWorkActive, type StartConversationWorkNoWork, type StartConversationWorkResult, } from "@/chat/task-execution/state";
|
|
6
|
+
import type { AppendAndEnqueueInboundMessageResult, Conversation, InboundMessage } from "@/chat/task-execution/state";
|
|
92
7
|
/** Return a persisted conversation record, if one exists. */
|
|
93
8
|
export declare function getConversation(args: {
|
|
94
9
|
conversationId: string;
|
|
95
10
|
state?: StateAdapter;
|
|
96
|
-
}): Promise<Conversation | undefined>;
|
|
97
|
-
/** Return a persisted conversation record, if one exists. */
|
|
11
|
+
}): Promise<workState.Conversation | undefined>;
|
|
12
|
+
/** Return a persisted conversation work record, if one exists. */
|
|
98
13
|
export declare function getConversationWorkState(args: {
|
|
99
14
|
conversationId: string;
|
|
100
15
|
state?: StateAdapter;
|
|
101
|
-
}): Promise<ConversationWorkState | undefined>;
|
|
16
|
+
}): Promise<workState.ConversationWorkState | undefined>;
|
|
102
17
|
/** Count mailbox messages that have not yet reached the session log. */
|
|
103
18
|
export declare function countPendingConversationMessages(conversation: Conversation): number;
|
|
104
19
|
/** Return whether a conversation has pending or resumable execution work. */
|
|
@@ -106,12 +21,14 @@ export declare function hasRunnableConversationWork(conversation: Conversation):
|
|
|
106
21
|
/** Persist one inbound message idempotently in its conversation mailbox. */
|
|
107
22
|
export declare function appendInboundMessage(args: {
|
|
108
23
|
message: InboundMessage;
|
|
24
|
+
conversationStore?: ConversationStore;
|
|
109
25
|
nowMs?: number;
|
|
110
26
|
state?: StateAdapter;
|
|
111
|
-
}): Promise<AppendInboundMessageResult>;
|
|
27
|
+
}): Promise<workState.AppendInboundMessageResult>;
|
|
112
28
|
/** Persist inbound work and send the queue nudge that wakes a worker. */
|
|
113
29
|
export declare function appendAndEnqueueInboundMessage(args: {
|
|
114
30
|
message: InboundMessage;
|
|
31
|
+
conversationStore?: ConversationStore;
|
|
115
32
|
nowMs?: number;
|
|
116
33
|
queue: ConversationWorkQueue;
|
|
117
34
|
state?: StateAdapter;
|
|
@@ -119,62 +36,58 @@ export declare function appendAndEnqueueInboundMessage(args: {
|
|
|
119
36
|
/** Mark a conversation runnable when there is no new mailbox message. */
|
|
120
37
|
export declare function requestConversationWork(args: {
|
|
121
38
|
conversationId: string;
|
|
122
|
-
destination:
|
|
39
|
+
destination: InboundMessage["destination"];
|
|
40
|
+
conversationStore?: ConversationStore;
|
|
123
41
|
nowMs?: number;
|
|
124
42
|
state?: StateAdapter;
|
|
125
|
-
}): Promise<RequestConversationWorkResult>;
|
|
43
|
+
}): Promise<workState.RequestConversationWorkResult>;
|
|
126
44
|
/** Record visible conversation activity without making the conversation runnable. */
|
|
127
|
-
export declare function recordConversationActivity(args: {
|
|
128
|
-
|
|
129
|
-
channelName?: string;
|
|
130
|
-
conversationId: string;
|
|
131
|
-
destination?: Destination;
|
|
132
|
-
nowMs?: number;
|
|
133
|
-
requester?: StoredSlackRequester;
|
|
134
|
-
source?: Source;
|
|
45
|
+
export declare function recordConversationActivity(args: Parameters<ConversationStore["recordActivity"]>[0] & {
|
|
46
|
+
conversationStore?: ConversationStore;
|
|
135
47
|
state?: StateAdapter;
|
|
136
|
-
title?: string;
|
|
137
48
|
}): Promise<void>;
|
|
138
49
|
/** Record that a wake-up nudge was accepted for the conversation. */
|
|
139
50
|
export declare function markConversationWorkEnqueued(args: {
|
|
140
51
|
conversationId: string;
|
|
52
|
+
conversationStore?: ConversationStore;
|
|
141
53
|
nowMs?: number;
|
|
142
54
|
state?: StateAdapter;
|
|
143
55
|
}): Promise<void>;
|
|
144
56
|
/** Try to acquire the durable execution lease for one conversation. */
|
|
145
57
|
export declare function startConversationWork(args: {
|
|
146
58
|
conversationId: string;
|
|
59
|
+
conversationStore?: ConversationStore;
|
|
147
60
|
nowMs?: number;
|
|
148
61
|
state?: StateAdapter;
|
|
149
|
-
}): Promise<StartConversationWorkResult>;
|
|
62
|
+
}): Promise<workState.StartConversationWorkResult>;
|
|
150
63
|
/** Extend the durable execution lease when the worker checks in. */
|
|
151
64
|
export declare function checkInConversationWork(args: {
|
|
152
65
|
conversationId: string;
|
|
153
66
|
leaseToken: string;
|
|
67
|
+
conversationStore?: ConversationStore;
|
|
154
68
|
nowMs?: number;
|
|
155
69
|
state?: StateAdapter;
|
|
156
70
|
}): Promise<boolean>;
|
|
157
71
|
/** Drain pending mailbox entries after the caller has durably injected them. */
|
|
158
|
-
export declare function drainConversationMailbox(args: {
|
|
159
|
-
|
|
160
|
-
inject: (messages: InboundMessage[]) => Promise<void>;
|
|
161
|
-
leaseToken: string;
|
|
162
|
-
nowMs?: number;
|
|
72
|
+
export declare function drainConversationMailbox(args: Parameters<typeof workState.drainConversationMailbox>[0] & {
|
|
73
|
+
conversationStore?: ConversationStore;
|
|
163
74
|
state?: StateAdapter;
|
|
164
|
-
}): Promise<InboundMessage[]>;
|
|
75
|
+
}): Promise<workState.InboundMessage[]>;
|
|
165
76
|
/** Mark selected leased mailbox entries after their session-log injection succeeds. */
|
|
166
77
|
export declare function markConversationMessagesInjected(args: {
|
|
167
78
|
conversationId: string;
|
|
168
79
|
inboundMessageIds: string[];
|
|
169
80
|
leaseToken: string;
|
|
81
|
+
conversationStore?: ConversationStore;
|
|
170
82
|
nowMs?: number;
|
|
171
83
|
state?: StateAdapter;
|
|
172
84
|
}): Promise<boolean>;
|
|
173
85
|
/** Mark the leased conversation as needing another queue-delivered slice. */
|
|
174
86
|
export declare function requestConversationContinuation(args: {
|
|
175
87
|
conversationId: string;
|
|
176
|
-
destination:
|
|
88
|
+
destination: InboundMessage["destination"];
|
|
177
89
|
leaseToken: string;
|
|
90
|
+
conversationStore?: ConversationStore;
|
|
178
91
|
nowMs?: number;
|
|
179
92
|
state?: StateAdapter;
|
|
180
93
|
}): Promise<boolean>;
|
|
@@ -182,6 +95,7 @@ export declare function requestConversationContinuation(args: {
|
|
|
182
95
|
export declare function releaseConversationWork(args: {
|
|
183
96
|
conversationId: string;
|
|
184
97
|
leaseToken: string;
|
|
98
|
+
conversationStore?: ConversationStore;
|
|
185
99
|
nowMs?: number;
|
|
186
100
|
state?: StateAdapter;
|
|
187
101
|
}): Promise<boolean>;
|
|
@@ -189,12 +103,14 @@ export declare function releaseConversationWork(args: {
|
|
|
189
103
|
export declare function completeConversationWork(args: {
|
|
190
104
|
conversationId: string;
|
|
191
105
|
leaseToken: string;
|
|
106
|
+
conversationStore?: ConversationStore;
|
|
192
107
|
nowMs?: number;
|
|
193
108
|
state?: StateAdapter;
|
|
194
|
-
}): Promise<"
|
|
109
|
+
}): Promise<"pending" | "completed" | "lost_lease">;
|
|
195
110
|
/** Clear an expired durable lease so a later worker can resume safely. */
|
|
196
111
|
export declare function clearExpiredConversationLease(args: {
|
|
197
112
|
conversationId: string;
|
|
113
|
+
conversationStore?: ConversationStore;
|
|
198
114
|
nowMs?: number;
|
|
199
115
|
state?: StateAdapter;
|
|
200
116
|
}): Promise<boolean>;
|
|
@@ -213,4 +129,4 @@ export declare function listActiveConversationIds(args?: {
|
|
|
213
129
|
export declare function listConversationsByActivity(args?: {
|
|
214
130
|
limit?: number;
|
|
215
131
|
state?: StateAdapter;
|
|
216
|
-
}): Promise<Conversation[]>;
|
|
132
|
+
}): Promise<workState.Conversation[]>;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { StateAdapter } from "chat";
|
|
2
|
+
import type { ConversationStore } from "@/chat/conversations/store";
|
|
2
3
|
import { type ConversationWorkQueue } from "./queue";
|
|
3
4
|
import { type ConversationWorkProcessResult, type ConversationWorkerResult, type ConversationWorkerContext } from "./worker";
|
|
4
5
|
export declare const CONVERSATION_WORK_VISIBILITY_TIMEOUT_BUFFER_SECONDS = 30;
|
|
5
6
|
export declare const CONVERSATION_WORK_DEV_CONSUMER_GROUP = "junior_conversation_work_dev";
|
|
6
7
|
export interface ProcessConversationQueueMessageOptions {
|
|
7
8
|
checkInIntervalMs?: number;
|
|
9
|
+
conversationStore?: ConversationStore;
|
|
8
10
|
nowMs?: () => number;
|
|
9
11
|
queue?: ConversationWorkQueue;
|
|
10
12
|
run(context: ConversationWorkerContext): Promise<ConversationWorkerResult>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { StateAdapter } from "chat";
|
|
2
2
|
import type { Destination } from "@sentry/junior-plugin-api";
|
|
3
|
+
import type { ConversationStore } from "@/chat/conversations/store";
|
|
3
4
|
import { type ConversationQueueMessage, type ConversationWorkQueue } from "./queue";
|
|
4
5
|
import { type InboundMessage } from "./store";
|
|
5
6
|
export declare const CONVERSATION_WORK_DEFER_DELAY_MS = 15000;
|
|
@@ -20,6 +21,7 @@ export interface ConversationWorkProcessResult {
|
|
|
20
21
|
}
|
|
21
22
|
export interface ProcessConversationWorkOptions {
|
|
22
23
|
checkInIntervalMs?: number;
|
|
24
|
+
conversationStore?: ConversationStore;
|
|
23
25
|
nowMs?: () => number;
|
|
24
26
|
queue: ConversationWorkQueue;
|
|
25
27
|
run(context: ConversationWorkerContext): Promise<ConversationWorkerResult>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
normalizeSlackConversationId
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-YRDS7VKO.js";
|
|
4
4
|
import {
|
|
5
5
|
getStateAdapter
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-F6HWCPOC.js";
|
|
7
7
|
import {
|
|
8
8
|
parseSlackThreadId
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-GM7HTXYC.js";
|
|
10
10
|
import {
|
|
11
11
|
parseStoredSlackRequester
|
|
12
12
|
} from "./chunk-CYUI7JU5.js";
|
|
@@ -7,10 +7,10 @@ import {
|
|
|
7
7
|
} from "./chunk-7Q5YOUUT.js";
|
|
8
8
|
import {
|
|
9
9
|
getStateAdapter
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-F6HWCPOC.js";
|
|
11
11
|
import {
|
|
12
12
|
toOptionalTrimmed
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-GM7HTXYC.js";
|
|
14
14
|
import {
|
|
15
15
|
withSpan
|
|
16
16
|
} from "./chunk-3BYAPS6B.js";
|
|
@@ -980,10 +980,16 @@ function readBotConfig(env) {
|
|
|
980
980
|
advisor: readAdvisorConfig(env)
|
|
981
981
|
};
|
|
982
982
|
}
|
|
983
|
+
function readJuniorDatabaseUrl(env) {
|
|
984
|
+
return toOptionalTrimmed(env.JUNIOR_DATABASE_URL) ?? toOptionalTrimmed(env.DATABASE_URL);
|
|
985
|
+
}
|
|
983
986
|
function readChatConfig(env = process.env) {
|
|
984
987
|
return {
|
|
985
988
|
bot: readBotConfig(env),
|
|
986
989
|
functionMaxDurationSeconds: resolveFunctionMaxDurationSeconds(env),
|
|
990
|
+
sql: {
|
|
991
|
+
databaseUrl: readJuniorDatabaseUrl(env)
|
|
992
|
+
},
|
|
987
993
|
slack: {
|
|
988
994
|
botToken: toOptionalTrimmed(env.SLACK_BOT_TOKEN) ?? toOptionalTrimmed(env.SLACK_BOT_USER_TOKEN),
|
|
989
995
|
clientId: toOptionalTrimmed(env.SLACK_CLIENT_ID),
|