@sentry/junior 0.202.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 +9 -9
- package/dist/agent-hooks-UXITLYOK.js +0 -51
- package/dist/catalog-runtime-BG3JLLK2.js +0 -14
- package/dist/chunk-2LYHWMR4.js +0 -46
- package/dist/chunk-2MK3QBGA.js +0 -321
- package/dist/chunk-3PGQSKJV.js +0 -692
- package/dist/chunk-3UI3WFTX.js +0 -519
- package/dist/chunk-3Y47VMHV.js +0 -6
- package/dist/chunk-4UO6FK4G.js +0 -64
- package/dist/chunk-5NOPO64K.js +0 -198
- package/dist/chunk-5PKWYPFT.js +0 -2943
- package/dist/chunk-63NKKFJL.js +0 -1228
- package/dist/chunk-6AYH6252.js +0 -787
- package/dist/chunk-6Y5B5PEX.js +0 -80
- package/dist/chunk-7DHZP5KJ.js +0 -333
- package/dist/chunk-7H2VZTWN.js +0 -103
- package/dist/chunk-7NL7T6VU.js +0 -406
- package/dist/chunk-A76OIMYN.js +0 -102
- package/dist/chunk-AWMS3SPP.js +0 -58
- package/dist/chunk-B3LY5RCL.js +0 -229
- package/dist/chunk-BD2KT3OB.js +0 -36
- package/dist/chunk-BXCX5QKA.js +0 -2086
- package/dist/chunk-C6VVF43U.js +0 -81
- package/dist/chunk-CEMMLV5L.js +0 -98
- package/dist/chunk-CM5HNV2W.js +0 -131
- package/dist/chunk-DA2KGZZI.js +0 -13
- package/dist/chunk-DBVY6HLX.js +0 -64
- package/dist/chunk-DIB4GX3G.js +0 -8
- package/dist/chunk-DKIJ2RP5.js +0 -68
- package/dist/chunk-DL2KLKVH.js +0 -931
- package/dist/chunk-DWPN6SCH.js +0 -172
- package/dist/chunk-ELWOYVOY.js +0 -206
- package/dist/chunk-EWT7H65X.js +0 -506
- package/dist/chunk-FA6POGLH.js +0 -70
- package/dist/chunk-HMREVIO2.js +0 -135
- package/dist/chunk-IIWUT4FO.js +0 -820
- package/dist/chunk-JAL3CH4G.js +0 -27
- package/dist/chunk-JSJQEWBJ.js +0 -3295
- package/dist/chunk-KHKKHDLD.js +0 -387
- package/dist/chunk-LA6R4A7Q.js +0 -706
- package/dist/chunk-LOOU2DUR.js +0 -20428
- package/dist/chunk-M6FHWXE3.js +0 -700
- package/dist/chunk-M76HMB7M.js +0 -1856
- package/dist/chunk-MAGNK5J4.js +0 -1520
- package/dist/chunk-MTM5IFCY.js +0 -1190
- package/dist/chunk-N7TMSOZH.js +0 -235
- package/dist/chunk-NHJU2ZAL.js +0 -56
- package/dist/chunk-NSXKRGRT.js +0 -717
- package/dist/chunk-OWMPFXJA.js +0 -1764
- package/dist/chunk-PDO5BLNM.js +0 -22
- package/dist/chunk-PEQXYSSE.js +0 -45
- package/dist/chunk-PW4P4JYF.js +0 -1135
- package/dist/chunk-QB54UQUS.js +0 -320
- package/dist/chunk-QP3OGJXF.js +0 -105
- package/dist/chunk-RC745GGZ.js +0 -122
- package/dist/chunk-REOIRYPR.js +0 -37
- package/dist/chunk-SCOZRLZ4.js +0 -164
- package/dist/chunk-TXJSXBV5.js +0 -1433
- package/dist/chunk-TXKUKMVO.js +0 -417
- package/dist/chunk-U2GPUYAL.js +0 -3656
- package/dist/chunk-UIE3R5XU.js +0 -17
- package/dist/chunk-UXPG6ZIN.js +0 -84
- package/dist/chunk-VFUK3X5B.js +0 -50
- package/dist/chunk-WQSHDTTI.js +0 -1163
- package/dist/chunk-X6GDDWQH.js +0 -60
- package/dist/chunk-Y2CM7HXH.js +0 -111
- package/dist/chunk-Y7X25LFY.js +0 -15
- package/dist/chunk-YDUR3ZYW.js +0 -10
- package/dist/conversation-work-VIOQ5ZF3.js +0 -54
- package/dist/db-3L2MCVRI.js +0 -26
- package/dist/discovery-DWVDM7UK.js +0 -44
- package/dist/experimental-P5FZM4CU.js +0 -12
- package/dist/oauth-callback-server-YVV6C6T2.js +0 -243
- package/dist/oauth-relay-5XPVRPYB.js +0 -8
- package/dist/plugins-YTYJMMJF.js +0 -14
- package/dist/runner-LQ7RETDP.js +0 -522
- package/dist/sandbox-egress-signals-FIL7EGPR.js +0 -73
- package/dist/sentry-MB3NL3IR.js +0 -42
- package/dist/skills-XRWYEDCD.js +0 -27
- package/dist/spawn-RC6SJUAI.js +0 -42
- package/dist/task-runner-7DY7ARYH.js +0 -36
- package/dist/validation-7MNQGCJA.js +0 -17
- package/dist/work-COALHUCG.js +0 -51
- package/dist/worker-6MURZIPD.js +0 -24
package/dist/chunk-3UI3WFTX.js
DELETED
|
@@ -1,519 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
persistConversationMessages
|
|
3
|
-
} from "./chunk-5PKWYPFT.js";
|
|
4
|
-
import {
|
|
5
|
-
JUNIOR_THREAD_STATE_TTL_MS
|
|
6
|
-
} from "./chunk-3Y47VMHV.js";
|
|
7
|
-
import {
|
|
8
|
-
getDb
|
|
9
|
-
} from "./chunk-M76HMB7M.js";
|
|
10
|
-
import {
|
|
11
|
-
juniorLocationConfigurations
|
|
12
|
-
} from "./chunk-PW4P4JYF.js";
|
|
13
|
-
import {
|
|
14
|
-
getStateAdapter
|
|
15
|
-
} from "./chunk-2MK3QBGA.js";
|
|
16
|
-
import {
|
|
17
|
-
juniorDestinations
|
|
18
|
-
} from "./chunk-VFUK3X5B.js";
|
|
19
|
-
import {
|
|
20
|
-
isRecord,
|
|
21
|
-
toOptionalNumber,
|
|
22
|
-
toOptionalString
|
|
23
|
-
} from "./chunk-MAGNK5J4.js";
|
|
24
|
-
|
|
25
|
-
// src/chat/state/conversation.ts
|
|
26
|
-
function defaultConversationState() {
|
|
27
|
-
return {
|
|
28
|
-
schemaVersion: 1,
|
|
29
|
-
messages: [],
|
|
30
|
-
compactions: [],
|
|
31
|
-
processing: {},
|
|
32
|
-
vision: {
|
|
33
|
-
byFileId: {}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function coercePendingAuthState(value) {
|
|
38
|
-
if (!isRecord(value)) {
|
|
39
|
-
return void 0;
|
|
40
|
-
}
|
|
41
|
-
const kind = value.kind;
|
|
42
|
-
const provider = toOptionalString(value.provider);
|
|
43
|
-
const actorId = toOptionalString(value.actorId);
|
|
44
|
-
const authSessionId = toOptionalString(value.authSessionId);
|
|
45
|
-
const scope = toOptionalString(value.scope);
|
|
46
|
-
const sessionId = toOptionalString(value.sessionId);
|
|
47
|
-
const linkSentAtMs = toOptionalNumber(value.linkSentAtMs);
|
|
48
|
-
if (kind !== "mcp" && kind !== "plugin" || !provider || !actorId || kind === "mcp" && !authSessionId || !sessionId || typeof linkSentAtMs !== "number") {
|
|
49
|
-
return void 0;
|
|
50
|
-
}
|
|
51
|
-
const base = {
|
|
52
|
-
provider,
|
|
53
|
-
actorId,
|
|
54
|
-
...scope ? { scope } : void 0,
|
|
55
|
-
sessionId,
|
|
56
|
-
linkSentAtMs
|
|
57
|
-
};
|
|
58
|
-
return kind === "mcp" ? { ...base, authSessionId, kind } : { ...base, kind };
|
|
59
|
-
}
|
|
60
|
-
function coerceThreadConversationState(value) {
|
|
61
|
-
if (!isRecord(value)) {
|
|
62
|
-
return defaultConversationState();
|
|
63
|
-
}
|
|
64
|
-
const root = value;
|
|
65
|
-
const rawConversation = isRecord(root.conversation) ? root.conversation : {};
|
|
66
|
-
const messages = [];
|
|
67
|
-
const compactions = [];
|
|
68
|
-
const rawProcessing = isRecord(rawConversation.processing) ? rawConversation.processing : {};
|
|
69
|
-
const processing = {
|
|
70
|
-
activeTurnId: toOptionalString(rawProcessing.activeTurnId),
|
|
71
|
-
lastCompletedAtMs: toOptionalNumber(rawProcessing.lastCompletedAtMs),
|
|
72
|
-
pendingAuth: coercePendingAuthState(rawProcessing.pendingAuth)
|
|
73
|
-
};
|
|
74
|
-
const rawVision = isRecord(rawConversation.vision) ? rawConversation.vision : {};
|
|
75
|
-
const rawVisionByFileId = isRecord(rawVision.byFileId) ? rawVision.byFileId : {};
|
|
76
|
-
const byFileId = {};
|
|
77
|
-
for (const [fileId, value2] of Object.entries(rawVisionByFileId)) {
|
|
78
|
-
if (typeof fileId !== "string" || fileId.trim().length === 0) continue;
|
|
79
|
-
if (!isRecord(value2)) continue;
|
|
80
|
-
const summary = toOptionalString(value2.summary);
|
|
81
|
-
const analyzedAtMs = toOptionalNumber(value2.analyzedAtMs);
|
|
82
|
-
if (!summary || !analyzedAtMs) continue;
|
|
83
|
-
byFileId[fileId] = {
|
|
84
|
-
summary,
|
|
85
|
-
analyzedAtMs
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
return {
|
|
89
|
-
schemaVersion: 1,
|
|
90
|
-
messages,
|
|
91
|
-
compactions,
|
|
92
|
-
processing,
|
|
93
|
-
vision: {
|
|
94
|
-
backfillCompletedAtMs: toOptionalNumber(rawVision.backfillCompletedAtMs),
|
|
95
|
-
byFileId
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
function buildConversationStatePatch(conversation) {
|
|
100
|
-
return {
|
|
101
|
-
conversation: {
|
|
102
|
-
schemaVersion: 1,
|
|
103
|
-
processing: { ...conversation.processing }
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// src/chat/configuration/sql.ts
|
|
109
|
-
import { randomUUID } from "crypto";
|
|
110
|
-
import { and, eq, sql } from "drizzle-orm";
|
|
111
|
-
|
|
112
|
-
// src/chat/configuration/types.ts
|
|
113
|
-
import { z } from "zod";
|
|
114
|
-
var configValueSchema = z.json();
|
|
115
|
-
|
|
116
|
-
// src/chat/configuration/validation.ts
|
|
117
|
-
var CONFIG_KEY_RE = /^[a-z0-9]+(?:\.[a-z0-9-]+)+$/;
|
|
118
|
-
var SECRET_KEY_RE = /(?:^|[_.-])(token|secret|password|passphrase|api[-_]?key|private[-_]?key|credential|auth)(?:$|[_.-])/i;
|
|
119
|
-
var SECRET_VALUE_PATTERNS = [
|
|
120
|
-
/\bBearer\s+[A-Za-z0-9._-]{16,}\b/i,
|
|
121
|
-
/-----BEGIN [A-Z ]*PRIVATE KEY-----/,
|
|
122
|
-
/\b(?:ghp|ghs|github_pat)_[A-Za-z0-9_]{20,}\b/,
|
|
123
|
-
/\bxox[baprs]-[A-Za-z0-9-]{10,}\b/i,
|
|
124
|
-
/\bsk-[A-Za-z0-9]{20,}\b/,
|
|
125
|
-
/\bAIza[0-9A-Za-z\-_]{30,}\b/,
|
|
126
|
-
/\bAKIA[0-9A-Z]{16}\b/,
|
|
127
|
-
/\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/
|
|
128
|
-
];
|
|
129
|
-
function validateConfigKey(key) {
|
|
130
|
-
const trimmed = key.trim();
|
|
131
|
-
if (!trimmed) {
|
|
132
|
-
return "Configuration key must not be empty";
|
|
133
|
-
}
|
|
134
|
-
if (!CONFIG_KEY_RE.test(trimmed)) {
|
|
135
|
-
return `Invalid configuration key "${key}"; expected dotted lowercase namespace (for example "provider.repo")`;
|
|
136
|
-
}
|
|
137
|
-
if (SECRET_KEY_RE.test(trimmed)) {
|
|
138
|
-
return `Configuration key "${key}" appears to be secret-related and is not allowed`;
|
|
139
|
-
}
|
|
140
|
-
return void 0;
|
|
141
|
-
}
|
|
142
|
-
function collectStringValues(value, output, depth = 0) {
|
|
143
|
-
if (depth > 5) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
if (typeof value === "string") {
|
|
147
|
-
output.push(value);
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
if (Array.isArray(value)) {
|
|
151
|
-
for (const item of value) {
|
|
152
|
-
collectStringValues(item, output, depth + 1);
|
|
153
|
-
}
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
if (value && typeof value === "object") {
|
|
157
|
-
for (const [key, nested] of Object.entries(
|
|
158
|
-
value
|
|
159
|
-
)) {
|
|
160
|
-
output.push(key);
|
|
161
|
-
collectStringValues(nested, output, depth + 1);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
function validateConfigValue(value) {
|
|
166
|
-
const stringValues = [];
|
|
167
|
-
collectStringValues(value, stringValues);
|
|
168
|
-
for (const text of stringValues) {
|
|
169
|
-
for (const pattern of SECRET_VALUE_PATTERNS) {
|
|
170
|
-
if (pattern.test(text)) {
|
|
171
|
-
return "Configuration value appears to contain secret material and is not allowed";
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return void 0;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// src/chat/configuration/service.ts
|
|
179
|
-
function sanitizeEntry(value) {
|
|
180
|
-
if (!isRecord(value)) {
|
|
181
|
-
return void 0;
|
|
182
|
-
}
|
|
183
|
-
const key = toOptionalString(value.key);
|
|
184
|
-
if (!key || validateConfigKey(key)) {
|
|
185
|
-
return void 0;
|
|
186
|
-
}
|
|
187
|
-
const updatedAt = toOptionalString(value.updatedAt);
|
|
188
|
-
if (!updatedAt) {
|
|
189
|
-
return void 0;
|
|
190
|
-
}
|
|
191
|
-
if (value.scope !== "channel" && value.scope !== "conversation" && value.scope !== "location") {
|
|
192
|
-
return void 0;
|
|
193
|
-
}
|
|
194
|
-
const parsedValue = configValueSchema.safeParse(value.value);
|
|
195
|
-
if (!parsedValue.success) {
|
|
196
|
-
return void 0;
|
|
197
|
-
}
|
|
198
|
-
return {
|
|
199
|
-
key,
|
|
200
|
-
value: parsedValue.data,
|
|
201
|
-
scope: "location",
|
|
202
|
-
updatedAt,
|
|
203
|
-
updatedBy: toOptionalString(value.updatedBy),
|
|
204
|
-
source: toOptionalString(value.source),
|
|
205
|
-
expiresAt: toOptionalString(value.expiresAt)
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
function coerceLegacyLocationConfig(raw) {
|
|
209
|
-
const rawConfig = isRecord(raw) && isRecord(raw.configuration) ? raw.configuration : {};
|
|
210
|
-
const rawEntries = isRecord(rawConfig.entries) ? rawConfig.entries : {};
|
|
211
|
-
return Object.values(rawEntries).flatMap((value) => {
|
|
212
|
-
const entry = sanitizeEntry(value);
|
|
213
|
-
return entry ? [entry] : [];
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
function createLocationConfigurationService(storage) {
|
|
217
|
-
const get = async (key) => await storage.get(key.trim());
|
|
218
|
-
const set = async (input) => {
|
|
219
|
-
const normalizedKey = input.key.trim();
|
|
220
|
-
const keyError = validateConfigKey(normalizedKey);
|
|
221
|
-
if (keyError) {
|
|
222
|
-
throw new Error(keyError);
|
|
223
|
-
}
|
|
224
|
-
const value = configValueSchema.parse(input.value);
|
|
225
|
-
const valueError = validateConfigValue(value);
|
|
226
|
-
if (valueError) {
|
|
227
|
-
throw new Error(valueError);
|
|
228
|
-
}
|
|
229
|
-
const entry = {
|
|
230
|
-
key: normalizedKey,
|
|
231
|
-
value,
|
|
232
|
-
scope: "location",
|
|
233
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
234
|
-
updatedBy: toOptionalString(input.updatedBy),
|
|
235
|
-
source: toOptionalString(input.source),
|
|
236
|
-
expiresAt: toOptionalString(input.expiresAt)
|
|
237
|
-
};
|
|
238
|
-
await storage.set(entry);
|
|
239
|
-
return entry;
|
|
240
|
-
};
|
|
241
|
-
const unset = async (key) => await storage.unset(key.trim());
|
|
242
|
-
const list = async (options = {}) => {
|
|
243
|
-
const prefix = options.prefix?.trim();
|
|
244
|
-
return (await storage.list()).filter((entry) => prefix ? entry.key.startsWith(prefix) : true).sort((a, b) => a.key.localeCompare(b.key));
|
|
245
|
-
};
|
|
246
|
-
const resolve = async (key) => (await get(key))?.value;
|
|
247
|
-
const resolveValues = async (options = {}) => {
|
|
248
|
-
const keys = options.keys?.map((key) => key.trim()).filter(Boolean);
|
|
249
|
-
const entries = await list(options.prefix ? { prefix: options.prefix } : {});
|
|
250
|
-
return Object.fromEntries(
|
|
251
|
-
entries.filter((entry) => !keys || keys.includes(entry.key)).map((entry) => [entry.key, entry.value])
|
|
252
|
-
);
|
|
253
|
-
};
|
|
254
|
-
return { get, set, unset, list, resolve, resolveValues };
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// src/chat/configuration/sql.ts
|
|
258
|
-
async function resolveLocationId(db, destination) {
|
|
259
|
-
const channelId = destination.channelId;
|
|
260
|
-
const now = /* @__PURE__ */ new Date();
|
|
261
|
-
const rows = await db.insert(juniorDestinations).values({
|
|
262
|
-
id: randomUUID(),
|
|
263
|
-
provider: "slack",
|
|
264
|
-
providerTenantId: destination.teamId,
|
|
265
|
-
providerDestinationId: channelId,
|
|
266
|
-
kind: channelId.startsWith("D") ? "dm" : channelId.startsWith("G") ? "group" : "channel",
|
|
267
|
-
parentDestinationId: null,
|
|
268
|
-
displayName: null,
|
|
269
|
-
visibility: "unknown",
|
|
270
|
-
metadata: { platform: "slack" },
|
|
271
|
-
createdAt: now,
|
|
272
|
-
updatedAt: now
|
|
273
|
-
}).onConflictDoUpdate({
|
|
274
|
-
target: [
|
|
275
|
-
juniorDestinations.provider,
|
|
276
|
-
juniorDestinations.providerTenantId,
|
|
277
|
-
juniorDestinations.providerDestinationId
|
|
278
|
-
],
|
|
279
|
-
set: { id: sql`${juniorDestinations.id}` }
|
|
280
|
-
}).returning({ id: juniorDestinations.id });
|
|
281
|
-
const location = rows[0];
|
|
282
|
-
if (!location) {
|
|
283
|
-
throw new Error("Location upsert returned no row");
|
|
284
|
-
}
|
|
285
|
-
return location.id;
|
|
286
|
-
}
|
|
287
|
-
function createSqlLocationConfigurationStorage(db, destination) {
|
|
288
|
-
const locationWhere = and(
|
|
289
|
-
eq(juniorDestinations.provider, "slack"),
|
|
290
|
-
eq(juniorDestinations.providerTenantId, destination.teamId),
|
|
291
|
-
eq(juniorDestinations.providerDestinationId, destination.channelId)
|
|
292
|
-
);
|
|
293
|
-
const selectEntries = () => db.select({
|
|
294
|
-
key: juniorLocationConfigurations.key,
|
|
295
|
-
value: juniorLocationConfigurations.value,
|
|
296
|
-
updatedAt: juniorLocationConfigurations.updatedAt,
|
|
297
|
-
updatedBy: juniorLocationConfigurations.updatedBy,
|
|
298
|
-
source: juniorLocationConfigurations.source,
|
|
299
|
-
expiresAt: juniorLocationConfigurations.expiresAt
|
|
300
|
-
}).from(juniorLocationConfigurations).innerJoin(
|
|
301
|
-
juniorDestinations,
|
|
302
|
-
eq(juniorDestinations.id, juniorLocationConfigurations.locationId)
|
|
303
|
-
);
|
|
304
|
-
const entryFromRow = (row) => ({
|
|
305
|
-
key: row.key,
|
|
306
|
-
value: configValueSchema.parse(JSON.parse(row.value)),
|
|
307
|
-
scope: "location",
|
|
308
|
-
updatedAt: row.updatedAt.toISOString(),
|
|
309
|
-
updatedBy: row.updatedBy ?? void 0,
|
|
310
|
-
source: row.source ?? void 0,
|
|
311
|
-
expiresAt: row.expiresAt ?? void 0
|
|
312
|
-
});
|
|
313
|
-
const list = async () => (await selectEntries().where(locationWhere)).map(entryFromRow);
|
|
314
|
-
const set = async (entry) => {
|
|
315
|
-
const locationId = await resolveLocationId(db, destination);
|
|
316
|
-
await db.insert(juniorLocationConfigurations).values({
|
|
317
|
-
locationId,
|
|
318
|
-
key: entry.key,
|
|
319
|
-
value: JSON.stringify(entry.value),
|
|
320
|
-
updatedAt: new Date(entry.updatedAt),
|
|
321
|
-
updatedBy: entry.updatedBy,
|
|
322
|
-
source: entry.source,
|
|
323
|
-
expiresAt: entry.expiresAt
|
|
324
|
-
}).onConflictDoUpdate({
|
|
325
|
-
target: [
|
|
326
|
-
juniorLocationConfigurations.locationId,
|
|
327
|
-
juniorLocationConfigurations.key
|
|
328
|
-
],
|
|
329
|
-
set: {
|
|
330
|
-
value: JSON.stringify(entry.value),
|
|
331
|
-
updatedAt: new Date(entry.updatedAt),
|
|
332
|
-
updatedBy: entry.updatedBy,
|
|
333
|
-
source: entry.source,
|
|
334
|
-
expiresAt: entry.expiresAt
|
|
335
|
-
}
|
|
336
|
-
});
|
|
337
|
-
};
|
|
338
|
-
return {
|
|
339
|
-
get: async (key) => {
|
|
340
|
-
const rows = await selectEntries().where(and(locationWhere, eq(juniorLocationConfigurations.key, key))).limit(1);
|
|
341
|
-
return rows[0] ? entryFromRow(rows[0]) : void 0;
|
|
342
|
-
},
|
|
343
|
-
list,
|
|
344
|
-
set,
|
|
345
|
-
unset: async (key) => {
|
|
346
|
-
const locationId = await resolveLocationId(db, destination);
|
|
347
|
-
const rows = await db.delete(juniorLocationConfigurations).where(
|
|
348
|
-
and(
|
|
349
|
-
eq(juniorLocationConfigurations.locationId, locationId),
|
|
350
|
-
eq(juniorLocationConfigurations.key, key)
|
|
351
|
-
)
|
|
352
|
-
).returning({ key: juniorLocationConfigurations.key });
|
|
353
|
-
return rows.length > 0;
|
|
354
|
-
},
|
|
355
|
-
insertLegacy: async (entries) => {
|
|
356
|
-
if (entries.length === 0) {
|
|
357
|
-
return;
|
|
358
|
-
}
|
|
359
|
-
const locationId = await resolveLocationId(db, destination);
|
|
360
|
-
await db.insert(juniorLocationConfigurations).values(
|
|
361
|
-
entries.map((entry) => ({
|
|
362
|
-
locationId,
|
|
363
|
-
key: entry.key,
|
|
364
|
-
value: JSON.stringify(entry.value),
|
|
365
|
-
updatedAt: new Date(entry.updatedAt),
|
|
366
|
-
updatedBy: entry.updatedBy,
|
|
367
|
-
source: entry.source,
|
|
368
|
-
expiresAt: entry.expiresAt
|
|
369
|
-
}))
|
|
370
|
-
).onConflictDoNothing();
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
function createDurableLocationConfigurationService(args) {
|
|
375
|
-
const storage = createSqlLocationConfigurationStorage(
|
|
376
|
-
args.db,
|
|
377
|
-
args.destination
|
|
378
|
-
);
|
|
379
|
-
let cutover;
|
|
380
|
-
const ensureCutover = () => cutover ??= (async () => {
|
|
381
|
-
if ((await storage.list()).length > 0) {
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
const legacy = coerceLegacyLocationConfig(await args.loadLegacy());
|
|
385
|
-
await storage.insertLegacy(legacy);
|
|
386
|
-
})();
|
|
387
|
-
return createLocationConfigurationService({
|
|
388
|
-
get: async (key) => {
|
|
389
|
-
await ensureCutover();
|
|
390
|
-
return await storage.get(key);
|
|
391
|
-
},
|
|
392
|
-
list: async () => {
|
|
393
|
-
await ensureCutover();
|
|
394
|
-
return await storage.list();
|
|
395
|
-
},
|
|
396
|
-
set: async (entry) => {
|
|
397
|
-
await ensureCutover();
|
|
398
|
-
await storage.set(entry);
|
|
399
|
-
},
|
|
400
|
-
unset: async (key) => {
|
|
401
|
-
await ensureCutover();
|
|
402
|
-
return await storage.unset(key);
|
|
403
|
-
}
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
// src/chat/runtime/thread-state.ts
|
|
408
|
-
function threadStateKey(threadId) {
|
|
409
|
-
return `thread-state:${threadId}`;
|
|
410
|
-
}
|
|
411
|
-
function channelStateKey(channelId) {
|
|
412
|
-
return `channel-state:${channelId}`;
|
|
413
|
-
}
|
|
414
|
-
function buildThreadStatePayload(patch) {
|
|
415
|
-
const payload = {};
|
|
416
|
-
if (patch.conversation) {
|
|
417
|
-
Object.assign(payload, buildConversationStatePatch(patch.conversation));
|
|
418
|
-
}
|
|
419
|
-
if (patch.sandboxRef !== void 0) {
|
|
420
|
-
payload.app_sandbox_id = patch.sandboxRef?.id ?? "";
|
|
421
|
-
payload.app_sandbox_dependency_profile_hash = patch.sandboxRef?.profileHash ?? "";
|
|
422
|
-
payload.app_sandbox_workspace_id = patch.sandboxRef?.workspaceId ?? "";
|
|
423
|
-
}
|
|
424
|
-
return payload;
|
|
425
|
-
}
|
|
426
|
-
async function mergePersistedState(key, payload) {
|
|
427
|
-
if (Object.keys(payload).length === 0) {
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
430
|
-
const stateAdapter = getStateAdapter();
|
|
431
|
-
await stateAdapter.connect();
|
|
432
|
-
const existing = await stateAdapter.get(key) ?? {};
|
|
433
|
-
await stateAdapter.set(
|
|
434
|
-
key,
|
|
435
|
-
{ ...existing, ...payload },
|
|
436
|
-
JUNIOR_THREAD_STATE_TTL_MS
|
|
437
|
-
);
|
|
438
|
-
}
|
|
439
|
-
function getPersistedSandboxState(state) {
|
|
440
|
-
const id = toOptionalString(state.app_sandbox_id);
|
|
441
|
-
if (!id) {
|
|
442
|
-
return void 0;
|
|
443
|
-
}
|
|
444
|
-
const profileHash = toOptionalString(
|
|
445
|
-
state.app_sandbox_dependency_profile_hash
|
|
446
|
-
);
|
|
447
|
-
const workspaceId = toOptionalString(state.app_sandbox_workspace_id);
|
|
448
|
-
return {
|
|
449
|
-
id,
|
|
450
|
-
...profileHash ? { profileHash } : void 0,
|
|
451
|
-
...workspaceId ? { workspaceId } : void 0
|
|
452
|
-
};
|
|
453
|
-
}
|
|
454
|
-
async function persistThreadState(thread, patch) {
|
|
455
|
-
if (patch.conversation) {
|
|
456
|
-
await persistConversationMessages({
|
|
457
|
-
conversation: patch.conversation,
|
|
458
|
-
conversationId: toOptionalString(thread.id) ?? toOptionalString(thread.runId)
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
await persistThreadRuntimeState(thread, patch);
|
|
462
|
-
}
|
|
463
|
-
async function persistThreadRuntimeState(thread, patch) {
|
|
464
|
-
const threadId = toOptionalString(thread.id) ?? toOptionalString(thread.runId);
|
|
465
|
-
if (!threadId) {
|
|
466
|
-
throw new Error("thread id is required to persist runtime scratch");
|
|
467
|
-
}
|
|
468
|
-
await mergePersistedState(
|
|
469
|
-
threadStateKey(threadId),
|
|
470
|
-
buildThreadStatePayload(patch)
|
|
471
|
-
);
|
|
472
|
-
}
|
|
473
|
-
async function getPersistedThreadState(threadId) {
|
|
474
|
-
const stateAdapter = getStateAdapter();
|
|
475
|
-
await stateAdapter.connect();
|
|
476
|
-
return await stateAdapter.get(
|
|
477
|
-
threadStateKey(threadId)
|
|
478
|
-
) ?? {};
|
|
479
|
-
}
|
|
480
|
-
async function persistThreadStateById(threadId, patch) {
|
|
481
|
-
if (patch.conversation) {
|
|
482
|
-
await persistConversationMessages({
|
|
483
|
-
conversation: patch.conversation,
|
|
484
|
-
conversationId: threadId
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
await mergePersistedState(
|
|
488
|
-
threadStateKey(threadId),
|
|
489
|
-
buildThreadStatePayload(patch)
|
|
490
|
-
);
|
|
491
|
-
}
|
|
492
|
-
async function getLegacyChannelState(channelId) {
|
|
493
|
-
const stateAdapter = getStateAdapter();
|
|
494
|
-
await stateAdapter.connect();
|
|
495
|
-
return await stateAdapter.get(
|
|
496
|
-
channelStateKey(channelId)
|
|
497
|
-
) ?? {};
|
|
498
|
-
}
|
|
499
|
-
function getLocationConfigurationService(destination) {
|
|
500
|
-
if (destination.platform !== "slack") {
|
|
501
|
-
throw new Error("Location configuration requires a Slack Location");
|
|
502
|
-
}
|
|
503
|
-
return createDurableLocationConfigurationService({
|
|
504
|
-
destination,
|
|
505
|
-
db: getDb(),
|
|
506
|
-
loadLegacy: async () => await getLegacyChannelState(destination.channelId)
|
|
507
|
-
});
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
export {
|
|
511
|
-
configValueSchema,
|
|
512
|
-
coerceThreadConversationState,
|
|
513
|
-
getPersistedSandboxState,
|
|
514
|
-
persistThreadState,
|
|
515
|
-
persistThreadRuntimeState,
|
|
516
|
-
getPersistedThreadState,
|
|
517
|
-
persistThreadStateById,
|
|
518
|
-
getLocationConfigurationService
|
|
519
|
-
};
|
package/dist/chunk-3Y47VMHV.js
DELETED
package/dist/chunk-4UO6FK4G.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
// src/cli/run.ts
|
|
2
|
-
var CLI_USAGE = "usage: junior init <dir>\n junior snapshot create\n junior check [dir]\n junior upgrade\n junior chat\n junior chat -p <message>";
|
|
3
|
-
var DEFAULT_IO = {
|
|
4
|
-
error: console.error
|
|
5
|
-
};
|
|
6
|
-
function normalizeCliArgv(argv) {
|
|
7
|
-
return argv[0] === "--" ? argv.slice(1) : argv;
|
|
8
|
-
}
|
|
9
|
-
async function runCli(argv, handlers, io = DEFAULT_IO) {
|
|
10
|
-
const [command, subcommand, ...rest] = normalizeCliArgv(argv);
|
|
11
|
-
if (command === "chat") {
|
|
12
|
-
return await handlers.runChat(
|
|
13
|
-
subcommand === void 0 ? [] : [subcommand, ...rest]
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
if (command === "init") {
|
|
17
|
-
if (!subcommand || rest.length > 0) {
|
|
18
|
-
io.error(CLI_USAGE);
|
|
19
|
-
return 1;
|
|
20
|
-
}
|
|
21
|
-
await handlers.runInit(subcommand);
|
|
22
|
-
return 0;
|
|
23
|
-
}
|
|
24
|
-
if (command === "snapshot" && subcommand === "create") {
|
|
25
|
-
if (rest.length > 0) {
|
|
26
|
-
io.error(CLI_USAGE);
|
|
27
|
-
return 1;
|
|
28
|
-
}
|
|
29
|
-
await handlers.runSnapshotCreate();
|
|
30
|
-
return 0;
|
|
31
|
-
}
|
|
32
|
-
if (command === "check") {
|
|
33
|
-
if (rest.length > 0) {
|
|
34
|
-
io.error(CLI_USAGE);
|
|
35
|
-
return 1;
|
|
36
|
-
}
|
|
37
|
-
await handlers.runCheck(subcommand);
|
|
38
|
-
return 0;
|
|
39
|
-
}
|
|
40
|
-
if (command === "upgrade") {
|
|
41
|
-
if (subcommand || rest.length > 0) {
|
|
42
|
-
io.error(CLI_USAGE);
|
|
43
|
-
return 1;
|
|
44
|
-
}
|
|
45
|
-
await handlers.runUpgrade();
|
|
46
|
-
return 0;
|
|
47
|
-
}
|
|
48
|
-
if (command && handlers.runPluginCommand) {
|
|
49
|
-
const exitCode = await handlers.runPluginCommand(
|
|
50
|
-
command,
|
|
51
|
-
subcommand === void 0 ? [] : [subcommand, ...rest]
|
|
52
|
-
);
|
|
53
|
-
if (exitCode !== void 0) {
|
|
54
|
-
return exitCode;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
io.error(CLI_USAGE);
|
|
58
|
-
return 1;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export {
|
|
62
|
-
CLI_USAGE,
|
|
63
|
-
runCli
|
|
64
|
-
};
|