@sentry/junior 0.203.0 → 0.204.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-CMyTD4DD.js +17509 -0
- package/dist/agent-hooks-Bbcp9e33.js +4040 -0
- package/dist/agent-runner-DNb1A49M.js +678 -0
- package/dist/api/schema.d.ts +2728 -2639
- package/dist/api/schema.js +4 -169
- package/dist/api.d.ts +23 -17
- package/dist/api.js +3881 -5326
- package/dist/app-B1TOqBI8.d.ts +246 -0
- package/dist/app.d.ts +4 -520
- package/dist/app.js +9522 -11875
- package/dist/auth-pause-state-DosEalIG.js +168 -0
- package/dist/catalog-runtime-BReos-D4.js +7 -0
- package/dist/checkpoint-CNrPyRJN.js +2450 -0
- package/dist/cli/chat.d.ts +20 -0
- package/dist/cli/chat.js +229 -336
- package/dist/cli/check.d.ts +8 -0
- package/dist/cli/check.js +513 -806
- package/dist/cli/env.d.ts +13 -0
- package/dist/cli/env.js +63 -12
- package/dist/cli/init.d.ts +3 -0
- package/dist/cli/init.js +90 -159
- package/dist/cli/main.d.ts +6 -0
- package/dist/cli/main.js +43 -64
- package/dist/cli/plugins.d.ts +13 -0
- package/dist/cli/plugins.js +148 -227
- package/dist/cli/run.d.ts +16 -0
- package/dist/cli/run.js +52 -8
- package/dist/cli/snapshot-create.d.ts +4 -0
- package/dist/cli/snapshot-create.js +71 -125
- package/dist/cli/upgrade.d.ts +15 -0
- package/dist/cli/upgrade.js +232 -335
- package/dist/config-nGCW1OTG.js +941 -0
- package/dist/context-B45_WqVX.js +298 -0
- package/dist/conversation-privacy-B4voFRSm.js +182 -0
- package/dist/conversation-work-C6y3T5Hx.js +51 -0
- package/dist/credential-sync-kXr1hvO1.js +2660 -0
- package/dist/db-BeyXKJOI.d.ts +5 -0
- package/dist/destinations-BeBiJeEM.js +29 -0
- package/dist/execution-stats-DWfSihcH.js +373 -0
- package/dist/executor-DcMSlI5c.js +721 -0
- package/dist/experimental-CIXf7Uye.js +46 -0
- package/dist/history-ClE4toxe.d.ts +32 -0
- package/dist/history-CqTuSAdI.js +441 -0
- package/dist/instrumentation.d.ts +3 -3
- package/dist/instrumentation.js +130 -176
- package/dist/job-queue-Drn_LXlM.js +63 -0
- package/dist/logging-BzAk1S_s.js +1210 -0
- package/dist/model-profile-CZmVoGdX.js +49 -0
- package/dist/nitro.d.ts +31 -36
- package/dist/nitro.js +275 -456
- package/dist/oauth-callback-server-JiftokvA.js +130 -0
- package/dist/oauth-relay-CdCnu80W.js +62 -0
- package/dist/package-discovery-7a9YqLhE.js +455 -0
- package/dist/pending-auth-CWmSdZVg.js +185 -0
- package/dist/plugin-module-BKGOXca2.js +81 -0
- package/dist/plugins-BI9A1vKA.d.ts +95 -0
- package/dist/plugins-egKWjgue.js +99 -0
- package/dist/private-trace-result-BLvBjy_e.js +16 -0
- package/dist/profile-CrT5nXbw.js +861 -0
- package/dist/registry-DH1xUo2N.js +1419 -0
- package/dist/reporting-schema-DosTN__Q.js +105 -0
- package/dist/resolve-CZHnfxaS.js +546 -0
- package/dist/rolldown-runtime-B4FMCO8f.js +28 -0
- package/dist/runner-CZV2sC46.js +392 -0
- package/dist/sandbox-egress-signals-bHZfmhbd.js +46 -0
- package/dist/schema-Rn8-XEaN.js +1140 -0
- package/dist/sentry-CD3SdJl-.js +26 -0
- package/dist/skills-CIcDQSgM.js +316 -0
- package/dist/spawn-DdkUFRmq.js +29 -0
- package/dist/stats-DTUbAb88.js +2634 -0
- package/dist/store-C5qxF2ac.d.ts +208 -0
- package/dist/task-queue-CJIR4RF7.js +136 -0
- package/dist/task-runner-D-O3A-Cp.js +639 -0
- package/dist/thread-state-CRc9jTJS.js +431 -0
- package/dist/turn-execution-BkinIdJF.js +47 -0
- package/dist/turn-lifecycle-DQV19VTW.js +54 -0
- package/dist/usage-D3EbSO7w.js +296 -0
- package/dist/usage-schema-CKaDkH_j.js +20 -0
- package/dist/validation-C2CR-OX3.js +40 -0
- package/dist/vercel-queue-DIkVcfK4.js +167 -0
- package/dist/vercel.d.ts +6 -6
- package/dist/vercel.js +14 -6
- package/dist/version-CnXZ614E.d.ts +5 -0
- package/dist/version-DxcWdoKa.js +8 -0
- package/dist/version.d.ts +2 -4
- package/dist/version.js +2 -6
- package/dist/web-authorization-RMBxAR_t.js +76 -0
- package/dist/web-input-3EPfpf55.js +494 -0
- package/dist/work-fGofI7Op.js +509 -0
- package/dist/worker-CsOLq-mR.js +625 -0
- package/package.json +8 -8
- package/dist/agent-hooks-GB2VPTNA.js +0 -51
- package/dist/catalog-runtime-UBLIWD3O.js +0 -14
- package/dist/chunk-2LYHWMR4.js +0 -46
- package/dist/chunk-352OWAZH.js +0 -320
- package/dist/chunk-3Y47VMHV.js +0 -6
- package/dist/chunk-3YJSKOWF.js +0 -164
- package/dist/chunk-4KSSKTQ5.js +0 -229
- package/dist/chunk-4UO6FK4G.js +0 -64
- package/dist/chunk-5AHX53NQ.js +0 -717
- package/dist/chunk-5J3E5FWA.js +0 -700
- package/dist/chunk-5PDAG6O3.js +0 -206
- package/dist/chunk-6Y5B5PEX.js +0 -80
- package/dist/chunk-7GWQ5S5R.js +0 -2086
- package/dist/chunk-7H2VZTWN.js +0 -103
- package/dist/chunk-7NL7T6VU.js +0 -406
- package/dist/chunk-A5L27LE4.js +0 -387
- package/dist/chunk-ADIAWL34.js +0 -81
- package/dist/chunk-ASTEMBKJ.js +0 -519
- package/dist/chunk-CEMMLV5L.js +0 -98
- package/dist/chunk-CM5HNV2W.js +0 -131
- package/dist/chunk-CRTRBBRI.js +0 -105
- package/dist/chunk-DA2KGZZI.js +0 -13
- package/dist/chunk-DIB4GX3G.js +0 -8
- package/dist/chunk-DKIJ2RP5.js +0 -68
- package/dist/chunk-DWPN6SCH.js +0 -172
- package/dist/chunk-EDKUFGPL.js +0 -64
- package/dist/chunk-ENY6SKIU.js +0 -1228
- package/dist/chunk-F4MGCZOX.js +0 -2943
- package/dist/chunk-FA6POGLH.js +0 -70
- package/dist/chunk-FSUR7GTG.js +0 -20475
- package/dist/chunk-GKEOHJL5.js +0 -1856
- package/dist/chunk-GMCB6W5Y.js +0 -333
- package/dist/chunk-IE2VPG7O.js +0 -1135
- package/dist/chunk-IZ5B5IHQ.js +0 -3656
- package/dist/chunk-JAL3CH4G.js +0 -27
- package/dist/chunk-KIIEUXD3.js +0 -1764
- package/dist/chunk-KXU4NIL7.js +0 -692
- package/dist/chunk-MTM5IFCY.js +0 -1190
- package/dist/chunk-N7TMSOZH.js +0 -235
- package/dist/chunk-NCEBK6PH.js +0 -36
- package/dist/chunk-NHJU2ZAL.js +0 -56
- package/dist/chunk-P6KTRNVC.js +0 -321
- package/dist/chunk-PDO5BLNM.js +0 -22
- package/dist/chunk-PDRNLLFT.js +0 -3295
- package/dist/chunk-PEQXYSSE.js +0 -45
- package/dist/chunk-PKEX2AQX.js +0 -198
- package/dist/chunk-PSJCGIGO.js +0 -1163
- package/dist/chunk-PZUSUL55.js +0 -506
- package/dist/chunk-R45M4TUS.js +0 -37
- package/dist/chunk-RC745GGZ.js +0 -122
- package/dist/chunk-SP3QKZXJ.js +0 -820
- package/dist/chunk-TXKUKMVO.js +0 -417
- package/dist/chunk-UE4GPWSD.js +0 -931
- package/dist/chunk-UIE3R5XU.js +0 -17
- package/dist/chunk-UXPG6ZIN.js +0 -84
- package/dist/chunk-VFUK3X5B.js +0 -50
- package/dist/chunk-VNMJWREK.js +0 -787
- package/dist/chunk-VZ7CSOX2.js +0 -706
- package/dist/chunk-WCNQJKFT.js +0 -10
- package/dist/chunk-WDZR3QQM.js +0 -135
- package/dist/chunk-WLYVJCHV.js +0 -1433
- package/dist/chunk-WS7NAFTM.js +0 -1520
- package/dist/chunk-X6GDDWQH.js +0 -60
- package/dist/chunk-XPDEYNQI.js +0 -102
- package/dist/chunk-XRW44VGM.js +0 -58
- package/dist/chunk-Y2CM7HXH.js +0 -111
- package/dist/chunk-Y7X25LFY.js +0 -15
- package/dist/conversation-work-VIOQ5ZF3.js +0 -54
- package/dist/db-NGDJV7YH.js +0 -26
- package/dist/discovery-DWVDM7UK.js +0 -44
- package/dist/experimental-P5FZM4CU.js +0 -12
- package/dist/oauth-callback-server-YFY7YEGK.js +0 -243
- package/dist/oauth-relay-5XPVRPYB.js +0 -8
- package/dist/plugins-YTYJMMJF.js +0 -14
- package/dist/runner-ORTNSB2Q.js +0 -522
- package/dist/sandbox-egress-signals-FIL7EGPR.js +0 -73
- package/dist/sentry-MB3NL3IR.js +0 -42
- package/dist/skills-H376WQOH.js +0 -27
- package/dist/spawn-T43WHLOS.js +0 -42
- package/dist/task-runner-LBZWF32V.js +0 -36
- package/dist/validation-REJLRKI6.js +0 -17
- package/dist/work-3KJ3RE76.js +0 -51
- package/dist/worker-QFEBU72E.js +0 -24
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { Destination, Source, locationSchema } from "@sentry/junior-plugin-api";
|
|
3
|
+
import "@earendil-works/pi-ai";
|
|
4
|
+
//#region src/chat/conversation-privacy.d.ts
|
|
5
|
+
type ConversationPrivacy = "public" | "private";
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/chat/conversations/location.d.ts
|
|
8
|
+
/** Validated Location associated with a Conversation. */
|
|
9
|
+
type Location = z.output<typeof locationSchema>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/chat/actor.d.ts
|
|
12
|
+
declare const storedSlackActorSchema: z.ZodObject<{
|
|
13
|
+
email: z.ZodOptional<z.ZodString>;
|
|
14
|
+
fullName: z.ZodOptional<z.ZodString>;
|
|
15
|
+
platform: z.ZodOptional<z.ZodLiteral<"slack">>;
|
|
16
|
+
slackUserId: z.ZodOptional<z.ZodString>;
|
|
17
|
+
slackUserName: z.ZodOptional<z.ZodString>;
|
|
18
|
+
teamId: z.ZodOptional<z.ZodString>;
|
|
19
|
+
}, z.core.$strict>;
|
|
20
|
+
type StoredSlackActor = z.output<typeof storedSlackActorSchema>;
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/chat/source.d.ts
|
|
23
|
+
/** Legacy provider Source fields stored on a Conversation. */
|
|
24
|
+
type SessionSource = Extract<Source, {
|
|
25
|
+
kind: "web";
|
|
26
|
+
}> | Extract<Source, {
|
|
27
|
+
kind: "local";
|
|
28
|
+
}> | Omit<Extract<Source, {
|
|
29
|
+
kind: "slack";
|
|
30
|
+
}>, "messageTs">;
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/usage-schema.d.ts
|
|
33
|
+
declare const usageSchema: z.ZodObject<{
|
|
34
|
+
inputTokens: z.ZodOptional<z.ZodNumber>;
|
|
35
|
+
outputTokens: z.ZodOptional<z.ZodNumber>;
|
|
36
|
+
cachedInputTokens: z.ZodOptional<z.ZodNumber>;
|
|
37
|
+
cacheCreationTokens: z.ZodOptional<z.ZodNumber>;
|
|
38
|
+
reasoningTokens: z.ZodOptional<z.ZodNumber>;
|
|
39
|
+
totalTokens: z.ZodOptional<z.ZodNumber>;
|
|
40
|
+
cost: z.ZodOptional<z.ZodObject<{
|
|
41
|
+
input: z.ZodOptional<z.ZodNumber>;
|
|
42
|
+
output: z.ZodOptional<z.ZodNumber>;
|
|
43
|
+
cacheRead: z.ZodOptional<z.ZodNumber>;
|
|
44
|
+
cacheWrite: z.ZodOptional<z.ZodNumber>;
|
|
45
|
+
total: z.ZodOptional<z.ZodNumber>;
|
|
46
|
+
}, z.core.$strict>>;
|
|
47
|
+
}, z.core.$strict>;
|
|
48
|
+
type Usage = z.output<typeof usageSchema>;
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/chat/usage.d.ts
|
|
51
|
+
/**
|
|
52
|
+
* Structured token and cost usage captured for a single agent turn.
|
|
53
|
+
*
|
|
54
|
+
* Mirrors the fields pi-ai emits on `AssistantMessage.usage` (see
|
|
55
|
+
* `@earendil-works/pi-ai` `Usage`) so diagnostics carry every counter the
|
|
56
|
+
* provider normalizes into the pi-ai shape as its own item. Renderers decide
|
|
57
|
+
* whether to display a breakdown or a single aggregate.
|
|
58
|
+
*/
|
|
59
|
+
type AgentTurnUsage = Usage;
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/chat/conversations/store.d.ts
|
|
62
|
+
type ConversationSource = "api" | "internal" | "local" | "plugin" | "resource_event" | "scheduler" | "slack" | "web";
|
|
63
|
+
type ConversationStatus = "paused" | "failed" | "idle" | "pending" | "running";
|
|
64
|
+
interface ConversationExecution {
|
|
65
|
+
lastCheckpointAtMs?: number;
|
|
66
|
+
lastEnqueuedAtMs?: number;
|
|
67
|
+
runId?: string;
|
|
68
|
+
status: ConversationStatus;
|
|
69
|
+
updatedAtMs?: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Durable Conversation owned by Junior.
|
|
73
|
+
*
|
|
74
|
+
* The final interface stores zero or one complete Location here. No Location
|
|
75
|
+
* means the Conversation stays in Junior's API and UI. A Location names the
|
|
76
|
+
* outside place where a provider can deliver the Conversation. A Run carries
|
|
77
|
+
* this Location when the agent or tools need it. Source stays about the input.
|
|
78
|
+
* Delivery is created for the Location and allows output to be sent there.
|
|
79
|
+
*
|
|
80
|
+
* `destination` and `sessionSource` temporarily duplicate parts of that model.
|
|
81
|
+
* Their field TODOs state when each legacy copy can be removed.
|
|
82
|
+
*/
|
|
83
|
+
interface Conversation {
|
|
84
|
+
channelName?: string;
|
|
85
|
+
conversationId: string;
|
|
86
|
+
createdAtMs: number;
|
|
87
|
+
destination?: Destination;
|
|
88
|
+
execution: ConversationExecution;
|
|
89
|
+
executionMetrics?: {
|
|
90
|
+
durationMs: number;
|
|
91
|
+
runId?: string;
|
|
92
|
+
usage?: AgentTurnUsage;
|
|
93
|
+
};
|
|
94
|
+
lastActivityAtMs: number;
|
|
95
|
+
/** Immutable parent Conversation. */
|
|
96
|
+
parentConversationId?: string;
|
|
97
|
+
/** Optional provider coordinates associated with this Conversation. */
|
|
98
|
+
location?: Location;
|
|
99
|
+
actor?: StoredSlackActor;
|
|
100
|
+
schemaVersion: 1;
|
|
101
|
+
source?: ConversationSource;
|
|
102
|
+
/**
|
|
103
|
+
* Structured inbound Source locator for this conversation session.
|
|
104
|
+
* Session-stable (threaded Slack keeps threadTs; channel-level turns omit
|
|
105
|
+
* it; never stores per-message ts). Set-once.
|
|
106
|
+
*/
|
|
107
|
+
sessionSource?: SessionSource;
|
|
108
|
+
title?: string;
|
|
109
|
+
updatedAtMs: number;
|
|
110
|
+
/**
|
|
111
|
+
* When retention purged this conversation's content. Set means messages and
|
|
112
|
+
* events were deleted wholesale; reporting presents the transcript as expired
|
|
113
|
+
* rather than privacy-redacted (`../../../../../policies/data-redaction.md`).
|
|
114
|
+
*/
|
|
115
|
+
transcriptPurgedAtMs?: number;
|
|
116
|
+
/** Confirmed Conversation visibility. Undefined means no confirmation exists. */
|
|
117
|
+
visibility?: ConversationPrivacy;
|
|
118
|
+
}
|
|
119
|
+
/** Persist and read durable conversation metadata for reporting surfaces. */
|
|
120
|
+
interface ConversationStore {
|
|
121
|
+
/** Create one Conversation with an immutable parent. */
|
|
122
|
+
createChild(args: {
|
|
123
|
+
childConversationId: string;
|
|
124
|
+
parentConversationId: string;
|
|
125
|
+
nowMs?: number;
|
|
126
|
+
source?: ConversationSource;
|
|
127
|
+
}): Promise<void>;
|
|
128
|
+
get(args: {
|
|
129
|
+
conversationId: string;
|
|
130
|
+
}): Promise<Conversation | undefined>;
|
|
131
|
+
/** Resolve the durable conversation bound to one provider conversation. */
|
|
132
|
+
getConversationIdByProviderConversation(args: {
|
|
133
|
+
provider: string;
|
|
134
|
+
providerDestinationId: string;
|
|
135
|
+
providerTenantId: string;
|
|
136
|
+
providerConversationId: string;
|
|
137
|
+
}): Promise<string | undefined>;
|
|
138
|
+
/** Bind one provider conversation to its pre-existing durable conversation. */
|
|
139
|
+
bindProviderConversation(args: {
|
|
140
|
+
conversationId: string;
|
|
141
|
+
provider: string;
|
|
142
|
+
providerDestinationId: string;
|
|
143
|
+
providerTenantId: string;
|
|
144
|
+
providerConversationId: string;
|
|
145
|
+
}): Promise<void>;
|
|
146
|
+
/** Read confirmed public/private visibility for one destination. */
|
|
147
|
+
getDestinationVisibility(args: {
|
|
148
|
+
provider: string;
|
|
149
|
+
providerDestinationId: string;
|
|
150
|
+
providerTenantId?: string;
|
|
151
|
+
}): Promise<ConversationPrivacy | undefined>;
|
|
152
|
+
/**
|
|
153
|
+
* Resolve one Slack channel id from a known destination display name.
|
|
154
|
+
*
|
|
155
|
+
* Matches only destinations Junior already stored for this workspace. Exact
|
|
156
|
+
* name match after stripping a leading `#`. Returns undefined when missing
|
|
157
|
+
* or ambiguous. Does not scan Slack.
|
|
158
|
+
*/
|
|
159
|
+
findSlackDestinationByName(args: {
|
|
160
|
+
channelName: string;
|
|
161
|
+
teamId: string;
|
|
162
|
+
}): Promise<{
|
|
163
|
+
channelId: string;
|
|
164
|
+
channelName?: string;
|
|
165
|
+
} | undefined>;
|
|
166
|
+
recordActivity(args: {
|
|
167
|
+
activityAtMs?: number;
|
|
168
|
+
channelName?: string;
|
|
169
|
+
conversationId: string;
|
|
170
|
+
destination?: Destination;
|
|
171
|
+
nowMs?: number;
|
|
172
|
+
actor?: StoredSlackActor;
|
|
173
|
+
source?: ConversationSource;
|
|
174
|
+
/** Source normalized to a stable session locator; set-once when absent. */
|
|
175
|
+
sessionSource?: Source;
|
|
176
|
+
title?: string;
|
|
177
|
+
/** Confirmed destination visibility; omit when unavailable. */
|
|
178
|
+
visibility?: ConversationPrivacy;
|
|
179
|
+
}): Promise<void>;
|
|
180
|
+
/**
|
|
181
|
+
* Materialize execution and usage aggregates beside canonical metadata.
|
|
182
|
+
* These fields serve reporting and runtime control, never history hydration.
|
|
183
|
+
*/
|
|
184
|
+
recordExecution(args: {
|
|
185
|
+
channelName?: string;
|
|
186
|
+
conversationId: string;
|
|
187
|
+
createdAtMs: number;
|
|
188
|
+
destination?: Destination;
|
|
189
|
+
execution: ConversationExecution;
|
|
190
|
+
lastActivityAtMs: number;
|
|
191
|
+
metrics: {
|
|
192
|
+
durationMs: number;
|
|
193
|
+
usage?: AgentTurnUsage;
|
|
194
|
+
} | null;
|
|
195
|
+
actor?: StoredSlackActor;
|
|
196
|
+
source?: ConversationSource;
|
|
197
|
+
title?: string;
|
|
198
|
+
updatedAtMs: number;
|
|
199
|
+
/** Confirmed destination visibility; omit when unavailable. */
|
|
200
|
+
visibility?: ConversationPrivacy;
|
|
201
|
+
}): Promise<void>;
|
|
202
|
+
listByActivity(args?: {
|
|
203
|
+
limit?: number;
|
|
204
|
+
offset?: number;
|
|
205
|
+
}): Promise<Conversation[]>;
|
|
206
|
+
}
|
|
207
|
+
//#endregion
|
|
208
|
+
export { ConversationStore as t };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { f as logWarn } from "./logging-BzAk1S_s.js";
|
|
2
|
+
import { a as signQueueMessage, i as QUEUE_SIGNATURE_MAX_AGE_MS, o as verifyQueueMessage, s as createVercelQueueClient } from "./vercel-queue-DIkVcfK4.js";
|
|
3
|
+
import { o as runWithTurnRequestDeadline } from "./job-queue-Drn_LXlM.js";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
import { handleCallback, registerDevConsumer } from "@vercel/queue";
|
|
7
|
+
//#region src/chat/queue/callback.ts
|
|
8
|
+
/** Shared Vercel Queue callback wiring for signed messages. */
|
|
9
|
+
/** Build the HTTP callback and local-dev consumer for one signed queue. */
|
|
10
|
+
function queueCallback(options) {
|
|
11
|
+
const handler = async (value, metadata) => {
|
|
12
|
+
if (options.skip?.(metadata)) return;
|
|
13
|
+
const checked = options.verify(value);
|
|
14
|
+
if (checked.status === "rejected") {
|
|
15
|
+
options.onRejected(checked.reason, metadata);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (checked.status === "unavailable") throw new Error(`Queue message verification unavailable: ${checked.reason}`);
|
|
19
|
+
try {
|
|
20
|
+
await runWithTurnRequestDeadline(() => options.run(checked.message, metadata));
|
|
21
|
+
} catch (error) {
|
|
22
|
+
const reason = options.permanentError?.(error);
|
|
23
|
+
if (!reason) throw error;
|
|
24
|
+
options.onRejected(reason, metadata, error);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const retry = (error, metadata) => {
|
|
28
|
+
const reason = options.permanentError?.(error);
|
|
29
|
+
if (reason) {
|
|
30
|
+
options.onRejected(reason, metadata, error);
|
|
31
|
+
return { acknowledge: true };
|
|
32
|
+
}
|
|
33
|
+
if (options.maxDeliveries !== null && metadata.deliveryCount >= options.maxDeliveries) return { acknowledge: true };
|
|
34
|
+
};
|
|
35
|
+
const visibility = options.visibilityTimeoutSeconds === void 0 ? {} : { visibilityTimeoutSeconds: options.visibilityTimeoutSeconds };
|
|
36
|
+
return {
|
|
37
|
+
create: () => handleCallback(handler, {
|
|
38
|
+
retry,
|
|
39
|
+
...visibility
|
|
40
|
+
}),
|
|
41
|
+
registerDev: () => {
|
|
42
|
+
if (process.env.NODE_ENV !== "development") return;
|
|
43
|
+
return registerDevConsumer({
|
|
44
|
+
client: createVercelQueueClient(),
|
|
45
|
+
consumerGroup: options.consumerGroup,
|
|
46
|
+
handler,
|
|
47
|
+
retry,
|
|
48
|
+
topic: options.topic,
|
|
49
|
+
...visibility
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/chat/plugins/task-queue.ts
|
|
56
|
+
/**
|
|
57
|
+
* Delivery for plugin-registered tasks.
|
|
58
|
+
*
|
|
59
|
+
* Plugins register named tasks. This module owns the shared signed message,
|
|
60
|
+
* send path, and HTTP/local callback. Core keeps one topic and one runner.
|
|
61
|
+
*/
|
|
62
|
+
/** Deploy topic name. Keep stable for Vercel queue wiring. */
|
|
63
|
+
const PLUGIN_TASK_QUEUE_TOPIC = "junior_plugin_tasks";
|
|
64
|
+
const PLUGIN_TASK_DEV_CONSUMER_GROUP = "junior_plugin_tasks_dev";
|
|
65
|
+
const PLUGIN_TASK_MAX_DELIVERIES = 5;
|
|
66
|
+
const PLUGIN_TASK_SIGN_CONTEXT = "junior.plugin_task_queue.v1";
|
|
67
|
+
const PLUGIN_TASK_SIGN_VERSION = "v1";
|
|
68
|
+
const pluginTaskParamsSchema = z.object({
|
|
69
|
+
conversationId: z.string().min(1),
|
|
70
|
+
sessionId: z.string().min(1)
|
|
71
|
+
}).strict();
|
|
72
|
+
const pluginTaskSign = {
|
|
73
|
+
context: PLUGIN_TASK_SIGN_CONTEXT,
|
|
74
|
+
schema: z.object({
|
|
75
|
+
name: z.string().min(1),
|
|
76
|
+
params: pluginTaskParamsSchema,
|
|
77
|
+
plugin: z.string().min(1)
|
|
78
|
+
}).strict(),
|
|
79
|
+
signatureVersion: PLUGIN_TASK_SIGN_VERSION,
|
|
80
|
+
parts: (message) => [
|
|
81
|
+
message.plugin,
|
|
82
|
+
message.name,
|
|
83
|
+
message.params.conversationId,
|
|
84
|
+
message.params.sessionId
|
|
85
|
+
]
|
|
86
|
+
};
|
|
87
|
+
/** Build the stable id used for delivery dedupe and tracing. */
|
|
88
|
+
function pluginTaskId(args) {
|
|
89
|
+
return `plugin-task_${createHash("sha256").update(args.plugin).update("\0").update(args.name).update("\0").update(args.params.conversationId).update("\0").update(args.params.sessionId).digest("hex").slice(0, 32)}`;
|
|
90
|
+
}
|
|
91
|
+
/** Sign a plugin task message for tests and local checks. */
|
|
92
|
+
function signPluginTaskQueueMessage(message, nowMs = Date.now()) {
|
|
93
|
+
return signQueueMessage(pluginTaskSign, message, nowMs);
|
|
94
|
+
}
|
|
95
|
+
function verifyPluginTaskQueueMessage(value, nowMs = Date.now()) {
|
|
96
|
+
return verifyQueueMessage(pluginTaskSign, value, nowMs);
|
|
97
|
+
}
|
|
98
|
+
function logPluginTaskQueueMessageRejected(reason, metadata) {
|
|
99
|
+
logWarn("plugin.task.queue_message.rejected", {
|
|
100
|
+
"app.queue.consumer_group": metadata.consumerGroup,
|
|
101
|
+
"app.queue.delivery_count": metadata.deliveryCount,
|
|
102
|
+
"app.queue.message_id": metadata.messageId,
|
|
103
|
+
"app.queue.reject_reason": reason,
|
|
104
|
+
"app.queue.topic_name": metadata.topicName
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function pluginTaskCallback() {
|
|
108
|
+
return queueCallback({
|
|
109
|
+
consumerGroup: PLUGIN_TASK_DEV_CONSUMER_GROUP,
|
|
110
|
+
maxDeliveries: PLUGIN_TASK_MAX_DELIVERIES,
|
|
111
|
+
onRejected: logPluginTaskQueueMessageRejected,
|
|
112
|
+
run: async (message) => {
|
|
113
|
+
const { processPluginTask } = await import("./task-runner-D-O3A-Cp.js").then((n) => n.r);
|
|
114
|
+
await processPluginTask(message);
|
|
115
|
+
},
|
|
116
|
+
topic: PLUGIN_TASK_QUEUE_TOPIC,
|
|
117
|
+
verify: verifyPluginTaskQueueMessage
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/** Send one plugin task through the shared signed delivery path. */
|
|
121
|
+
async function sendVercelPluginTask(message) {
|
|
122
|
+
await createVercelQueueClient().send(PLUGIN_TASK_QUEUE_TOPIC, signPluginTaskQueueMessage(message), {
|
|
123
|
+
idempotencyKey: pluginTaskId(message),
|
|
124
|
+
retentionSeconds: QUEUE_SIGNATURE_MAX_AGE_MS / 1e3
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/** Create the HTTP callback for plugin tasks. */
|
|
128
|
+
function createVercelPluginTaskCallback() {
|
|
129
|
+
return pluginTaskCallback().create();
|
|
130
|
+
}
|
|
131
|
+
/** Register the local-dev consumer for plugin tasks. */
|
|
132
|
+
function registerVercelPluginTaskDevConsumer() {
|
|
133
|
+
return pluginTaskCallback().registerDev();
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
136
|
+
export { registerVercelPluginTaskDevConsumer as a, pluginTaskParamsSchema as i, createVercelPluginTaskCallback as n, sendVercelPluginTask as o, pluginTaskId as r, queueCallback as s, PLUGIN_TASK_QUEUE_TOPIC as t };
|