@sentry/junior 0.75.0 → 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/README.md +1 -1
- package/bin/junior.mjs +4 -66
- package/dist/agent-hooks-ZOE7RIED.js +37 -0
- package/dist/api-reference.d.ts +2 -0
- package/dist/app.js +317 -118
- package/dist/build/virtual-config.d.ts +2 -2
- package/dist/chat/agent-dispatch/runner.d.ts +2 -0
- package/dist/chat/config.d.ts +1 -0
- package/dist/chat/credentials/state-adapter-token-store.d.ts +2 -0
- package/dist/chat/credentials/user-token-store.d.ts +17 -12
- package/dist/chat/db.d.ts +8 -0
- package/dist/chat/mcp/auth-store.d.ts +2 -1
- package/dist/chat/mcp/oauth.d.ts +2 -1
- package/dist/chat/oauth-flow.d.ts +3 -1
- package/dist/chat/pi/client.d.ts +15 -7
- package/dist/chat/plugins/agent-hooks.d.ts +7 -0
- package/dist/chat/plugins/auth/oauth-request.d.ts +11 -7
- package/dist/chat/plugins/model.d.ts +9 -0
- package/dist/chat/plugins/prompt.d.ts +5 -0
- package/dist/chat/plugins/task-callback.d.ts +5 -0
- package/dist/chat/plugins/task-message.d.ts +23 -0
- package/dist/chat/plugins/task-queue.d.ts +5 -0
- package/dist/chat/plugins/task-runner.d.ts +12 -0
- package/dist/chat/plugins/task-signing.d.ts +31 -0
- package/dist/chat/prompt.d.ts +4 -0
- package/dist/chat/requester.d.ts +6 -5
- package/dist/chat/respond-helpers.d.ts +2 -0
- package/dist/chat/respond.d.ts +4 -2
- package/dist/chat/runtime/agent-continue-runner.d.ts +4 -0
- package/dist/chat/runtime/reply-executor.d.ts +5 -1
- package/dist/chat/runtime/slack-resume.d.ts +10 -2
- package/dist/chat/sentry.d.ts +1 -0
- package/dist/chat/services/mcp-auth-orchestration.d.ts +2 -1
- package/dist/chat/services/plugin-auth-orchestration.d.ts +2 -1
- package/dist/chat/services/subscribed-decision.d.ts +2 -2
- package/dist/chat/services/turn-session-record.d.ts +11 -7
- package/dist/chat/state/turn-session.d.ts +8 -5
- package/dist/chat/tools/agent-tools.d.ts +8 -1
- package/dist/chat/tools/slack/context.d.ts +2 -2
- package/dist/chat/tools/types.d.ts +4 -4
- package/dist/chat/vercel-queue-client.d.ts +3 -0
- package/dist/{chunk-C3AM4Z4J.js → chunk-2ECJXSVQ.js} +5 -5
- package/dist/{chunk-OJODNL2P.js → chunk-4SCWV7TJ.js} +2 -2
- package/dist/chunk-4UO6FK4G.js +64 -0
- package/dist/{chunk-BNJIEFQC.js → chunk-56TBVRJG.js} +2 -2
- package/dist/{chunk-OK4KKR7B.js → chunk-EJN6G5A2.js} +28 -12
- package/dist/{chunk-TQ74BATR.js → chunk-HHDUKWVG.js} +428 -111
- package/dist/{chunk-XJHDZUGD.js → chunk-JBASI5VV.js} +4 -4
- package/dist/chunk-KNFROR7R.js +127 -0
- package/dist/{chunk-VNTLUFTY.js → chunk-KOIMO7S3.js} +126 -87
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/{chunk-NPVUAXUE.js → chunk-NFTMTIP3.js} +303 -33
- package/dist/chunk-NYKJ3KON.js +1082 -0
- package/dist/{chunk-SJHUF3DP.js → chunk-OJ53FYVG.js} +2 -10
- package/dist/{chunk-62FUNJYS.js → chunk-Q6XFTRV5.js} +54 -3
- package/dist/{chunk-UJ7OTHPO.js → chunk-R6Z5XWY3.js} +12 -670
- package/dist/chunk-RV5RYIJW.js +56 -0
- package/dist/{chunk-EE6PJWY4.js → chunk-SG5WAA7H.js} +7 -5
- package/dist/chunk-ST6YNAXG.js +54 -0
- package/dist/{chunk-FCZO7LAR.js → chunk-T77LUIX3.js} +139 -153
- package/dist/{chunk-EIYL7I4S.js → chunk-VALUBQ7R.js} +22 -30
- package/dist/{chunk-OZSPLAQ4.js → chunk-XBBC6W45.js} +1 -1
- package/dist/{chunk-ZNNTSPNF.js → chunk-Y5OFBCBZ.js} +1 -1
- package/dist/{chunk-74HO27II.js → chunk-Z4CIQ3EB.js} +5 -1
- package/dist/{chunk-2RWFUS5F.js → chunk-ZLMBNBUG.js} +101 -44
- package/dist/{chunk-JEELK46E.js → chunk-ZQB37HUX.js} +11 -11
- package/dist/cli/chat.js +52 -23
- package/dist/cli/check.js +7 -7
- package/dist/cli/env.js +4 -53
- package/dist/cli/init.js +6 -1
- package/dist/cli/main.js +84 -0
- package/dist/cli/plugins.js +244 -0
- package/dist/cli/run.js +5 -52
- package/dist/cli/snapshot-warmup.js +9 -9
- package/dist/cli/upgrade.js +167 -48
- package/dist/db-7A7PFRGL.js +17 -0
- package/dist/deployment.d.ts +1 -0
- package/dist/instrumentation.js +14 -18
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +43 -22
- package/dist/plugins-PZMDS7AT.js +15 -0
- package/dist/plugins.d.ts +4 -2
- package/dist/{registry-NLZFIW23.js → registry-OIPAJU2O.js} +6 -6
- package/dist/reporting.js +34 -26
- package/dist/{runner-LUQZ5G67.js → runner-KPLNHDCV.js} +76 -23
- package/dist/sentry-4CP5NNQ5.js +31 -0
- package/dist/validation-SLA6IGF7.js +15 -0
- package/dist/vercel.js +1 -1
- package/package.json +7 -6
- package/dist/agent-hooks-2HEB4C3Q.js +0 -33
- package/dist/chat/conversations/configured.d.ts +0 -7
- package/dist/chat/conversations/state.d.ts +0 -4
- package/dist/chat/plugins/db.d.ts +0 -31
- package/dist/chunk-2KG3PWR4.js +0 -17
- package/dist/chunk-D7NFH5GD.js +0 -570
- package/dist/chunk-MCMROINU.js +0 -12
- package/dist/chunk-WBZ4M5N5.js +0 -59
- package/dist/db-A3ILH67H.js +0 -20
- package/dist/plugins-OMJKLRJ2.js +0 -13
- package/dist/validation-VMCPP3YO.js +0 -15
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import {
|
|
2
|
+
validatePluginEgressCredentialHooks,
|
|
3
|
+
validatePluginRegistrations
|
|
4
|
+
} from "../chunk-XBBC6W45.js";
|
|
5
|
+
import {
|
|
6
|
+
pluginCatalogConfigFromPluginSet,
|
|
7
|
+
pluginCliRegistrationsFromPluginSet,
|
|
8
|
+
pluginRuntimeRegistrationsFromPluginSet
|
|
9
|
+
} from "../chunk-SG5WAA7H.js";
|
|
10
|
+
import {
|
|
11
|
+
setPlugins,
|
|
12
|
+
validatePlugins
|
|
13
|
+
} from "../chunk-NFTMTIP3.js";
|
|
14
|
+
import {
|
|
15
|
+
createPluginLogger
|
|
16
|
+
} from "../chunk-56TBVRJG.js";
|
|
17
|
+
import {
|
|
18
|
+
getDb
|
|
19
|
+
} from "../chunk-NYKJ3KON.js";
|
|
20
|
+
import "../chunk-G3E7SCME.js";
|
|
21
|
+
import "../chunk-Y5OFBCBZ.js";
|
|
22
|
+
import "../chunk-Q6XFTRV5.js";
|
|
23
|
+
import "../chunk-T77LUIX3.js";
|
|
24
|
+
import {
|
|
25
|
+
loadAppPluginSet
|
|
26
|
+
} from "../chunk-Y2CM7HXH.js";
|
|
27
|
+
import {
|
|
28
|
+
setPluginCatalogConfig
|
|
29
|
+
} from "../chunk-ZLMBNBUG.js";
|
|
30
|
+
import "../chunk-VALUBQ7R.js";
|
|
31
|
+
import "../chunk-Q3XNY442.js";
|
|
32
|
+
import "../chunk-EJN6G5A2.js";
|
|
33
|
+
import "../chunk-OJ53FYVG.js";
|
|
34
|
+
import "../chunk-ST6YNAXG.js";
|
|
35
|
+
import "../chunk-MLKGABMK.js";
|
|
36
|
+
|
|
37
|
+
// src/cli/plugins.ts
|
|
38
|
+
import { stderr as defaultStderr, stdout as defaultStdout } from "process";
|
|
39
|
+
import { createJiti } from "jiti";
|
|
40
|
+
import { Command, CommanderError } from "commander";
|
|
41
|
+
var pluginCliLoader = createJiti(import.meta.url, { moduleCache: false });
|
|
42
|
+
var CORE_COMMAND_NAMES = /* @__PURE__ */ new Set([
|
|
43
|
+
"chat",
|
|
44
|
+
"check",
|
|
45
|
+
"init",
|
|
46
|
+
"snapshot",
|
|
47
|
+
"upgrade"
|
|
48
|
+
]);
|
|
49
|
+
var PLUGIN_COMMAND_NAME_RE = /^[a-z][a-z0-9-]*$/;
|
|
50
|
+
var DEFAULT_IO = {
|
|
51
|
+
writeError: (text) => writeStream(defaultStderr, text),
|
|
52
|
+
writeOutput: (text) => writeStream(defaultStdout, text)
|
|
53
|
+
};
|
|
54
|
+
function writeStream(stream, text) {
|
|
55
|
+
return new Promise((resolve, reject) => {
|
|
56
|
+
stream.write(text, (error) => {
|
|
57
|
+
if (error) {
|
|
58
|
+
reject(error);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
resolve();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
async function loadCliPluginSet() {
|
|
66
|
+
return await loadAppPluginSet(
|
|
67
|
+
process.cwd(),
|
|
68
|
+
async (moduleRef) => pluginCliLoader.import(moduleRef.importPath)
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
function findPluginCommand(plugins, commandName) {
|
|
72
|
+
for (const plugin of plugins) {
|
|
73
|
+
const command = plugin.cli?.commands.find(
|
|
74
|
+
(candidate) => candidate.name === commandName
|
|
75
|
+
);
|
|
76
|
+
if (command) {
|
|
77
|
+
return { command, plugin };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return void 0;
|
|
81
|
+
}
|
|
82
|
+
function createPluginCliHost(args) {
|
|
83
|
+
return {
|
|
84
|
+
action(handler) {
|
|
85
|
+
return async (...actionArgs) => {
|
|
86
|
+
const pluginName = args.plugin.manifest.name;
|
|
87
|
+
const result = await handler(
|
|
88
|
+
{
|
|
89
|
+
db: getDb(),
|
|
90
|
+
command: {
|
|
91
|
+
name: args.command.name,
|
|
92
|
+
summary: args.command.summary
|
|
93
|
+
},
|
|
94
|
+
io: args.io,
|
|
95
|
+
log: createPluginLogger(pluginName),
|
|
96
|
+
plugin: { name: pluginName }
|
|
97
|
+
},
|
|
98
|
+
...actionArgs
|
|
99
|
+
);
|
|
100
|
+
args.setExitCode(result ?? 0);
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function createPluginCommanderCommand(args) {
|
|
106
|
+
const command = new Command(args.command.name).description(args.command.summary).exitOverride().showHelpAfterError().showSuggestionAfterError().configureOutput({
|
|
107
|
+
writeOut: (text) => {
|
|
108
|
+
void args.io.writeOutput(text);
|
|
109
|
+
},
|
|
110
|
+
writeErr: (text) => {
|
|
111
|
+
void args.io.writeError(text);
|
|
112
|
+
},
|
|
113
|
+
outputError: (text, write) => {
|
|
114
|
+
write(text);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
args.command.configure(command, createPluginCliHost(args));
|
|
118
|
+
return command;
|
|
119
|
+
}
|
|
120
|
+
function validateConfiguredPluginCommand(args) {
|
|
121
|
+
const pluginName = args.plugin.manifest.name;
|
|
122
|
+
if (args.command.name() !== args.definition.name) {
|
|
123
|
+
throw new Error(
|
|
124
|
+
`Plugin CLI command "${args.definition.name}" from plugin "${pluginName}" must not rename its top-level command`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
if (args.command.commands.length === 0) {
|
|
128
|
+
throw new Error(
|
|
129
|
+
`Plugin CLI command "${args.definition.name}" from plugin "${pluginName}" must define at least one subcommand`
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
if (args.command.aliases().length > 0) {
|
|
133
|
+
throw new Error(
|
|
134
|
+
`Plugin CLI command "${args.definition.name}" from plugin "${pluginName}" must not define top-level aliases`
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function validateConfiguredPluginCommands(plugins) {
|
|
139
|
+
const ownerByName = /* @__PURE__ */ new Map();
|
|
140
|
+
const validationIo = DEFAULT_IO;
|
|
141
|
+
for (const plugin of plugins) {
|
|
142
|
+
for (const definition of plugin.cli?.commands ?? []) {
|
|
143
|
+
const pluginName = plugin.manifest.name;
|
|
144
|
+
const existingOwner = ownerByName.get(definition.name);
|
|
145
|
+
if (!PLUGIN_COMMAND_NAME_RE.test(definition.name)) {
|
|
146
|
+
throw new Error(
|
|
147
|
+
`Plugin CLI command "${definition.name}" from plugin "${pluginName}" must be a lowercase command identifier`
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
if (CORE_COMMAND_NAMES.has(definition.name)) {
|
|
151
|
+
throw new Error(
|
|
152
|
+
`Plugin CLI command "${definition.name}" from plugin "${pluginName}" conflicts with a core command`
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
if (existingOwner) {
|
|
156
|
+
throw new Error(
|
|
157
|
+
`Plugin CLI command "${definition.name}" from plugin "${pluginName}" conflicts with plugin "${existingOwner}"`
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
ownerByName.set(definition.name, pluginName);
|
|
161
|
+
if (typeof definition.configure !== "function") {
|
|
162
|
+
throw new Error(
|
|
163
|
+
`Plugin CLI command "${definition.name}" from plugin "${pluginName}" must define a configure function`
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
let exitCode = 0;
|
|
167
|
+
validateConfiguredPluginCommand({
|
|
168
|
+
command: createPluginCommanderCommand({
|
|
169
|
+
command: definition,
|
|
170
|
+
io: validationIo,
|
|
171
|
+
plugin,
|
|
172
|
+
setExitCode: (nextExitCode) => {
|
|
173
|
+
exitCode = nextExitCode;
|
|
174
|
+
}
|
|
175
|
+
}),
|
|
176
|
+
definition,
|
|
177
|
+
plugin
|
|
178
|
+
});
|
|
179
|
+
void exitCode;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
async function loadPluginRegistrations(args) {
|
|
184
|
+
const pluginSet = args.pluginSet;
|
|
185
|
+
if (!pluginSet) {
|
|
186
|
+
return { cliPlugins: [], runtimePlugins: [] };
|
|
187
|
+
}
|
|
188
|
+
const cliPlugins = pluginCliRegistrationsFromPluginSet(pluginSet);
|
|
189
|
+
const runtimePlugins = pluginRuntimeRegistrationsFromPluginSet(pluginSet);
|
|
190
|
+
const pluginConfig = pluginCatalogConfigFromPluginSet(pluginSet);
|
|
191
|
+
validatePlugins(runtimePlugins);
|
|
192
|
+
const previousPluginCatalogConfig = setPluginCatalogConfig(pluginConfig);
|
|
193
|
+
try {
|
|
194
|
+
validatePluginRegistrations(pluginSet.registrations);
|
|
195
|
+
validatePluginEgressCredentialHooks(pluginSet.registrations);
|
|
196
|
+
args.validateConfiguredCommands?.(cliPlugins);
|
|
197
|
+
setPlugins(runtimePlugins);
|
|
198
|
+
return { cliPlugins, runtimePlugins };
|
|
199
|
+
} catch (error) {
|
|
200
|
+
setPluginCatalogConfig(previousPluginCatalogConfig);
|
|
201
|
+
throw error;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
async function loadCliPluginCommands(pluginSet) {
|
|
205
|
+
const resolvedPluginSet = pluginSet === void 0 ? await loadCliPluginSet() : pluginSet ?? void 0;
|
|
206
|
+
const { cliPlugins } = await loadPluginRegistrations({
|
|
207
|
+
pluginSet: resolvedPluginSet,
|
|
208
|
+
validateConfiguredCommands: validateConfiguredPluginCommands
|
|
209
|
+
});
|
|
210
|
+
const commandNames = cliPlugins.flatMap(
|
|
211
|
+
(plugin) => (plugin.cli?.commands ?? []).map((command) => command.name)
|
|
212
|
+
);
|
|
213
|
+
return {
|
|
214
|
+
commandNames,
|
|
215
|
+
async run(commandName, argv, io = DEFAULT_IO) {
|
|
216
|
+
const resolved = findPluginCommand(cliPlugins, commandName);
|
|
217
|
+
if (!resolved) {
|
|
218
|
+
return void 0;
|
|
219
|
+
}
|
|
220
|
+
let exitCode = 0;
|
|
221
|
+
const command = createPluginCommanderCommand({
|
|
222
|
+
command: resolved.command,
|
|
223
|
+
io,
|
|
224
|
+
plugin: resolved.plugin,
|
|
225
|
+
setExitCode: (nextExitCode) => {
|
|
226
|
+
exitCode = nextExitCode;
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
try {
|
|
230
|
+
await command.parseAsync(argv, { from: "user" });
|
|
231
|
+
} catch (error) {
|
|
232
|
+
if (error instanceof CommanderError) {
|
|
233
|
+
return error.exitCode;
|
|
234
|
+
}
|
|
235
|
+
throw error;
|
|
236
|
+
}
|
|
237
|
+
return exitCode;
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
export {
|
|
242
|
+
loadCliPluginCommands,
|
|
243
|
+
loadCliPluginSet
|
|
244
|
+
};
|
package/dist/cli/run.js
CHANGED
|
@@ -1,55 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
error: console.error
|
|
7
|
-
};
|
|
8
|
-
function normalizeCliArgv(argv) {
|
|
9
|
-
return argv[0] === "--" ? argv.slice(1) : argv;
|
|
10
|
-
}
|
|
11
|
-
async function runCli(argv, handlers, io = DEFAULT_IO) {
|
|
12
|
-
const [command, subcommand, ...rest] = normalizeCliArgv(argv);
|
|
13
|
-
if (command === "chat") {
|
|
14
|
-
return await handlers.runChat(
|
|
15
|
-
subcommand === void 0 ? [] : [subcommand, ...rest]
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
if (command === "init") {
|
|
19
|
-
if (!subcommand || rest.length > 0) {
|
|
20
|
-
io.error(CLI_USAGE);
|
|
21
|
-
return 1;
|
|
22
|
-
}
|
|
23
|
-
await handlers.runInit(subcommand);
|
|
24
|
-
return 0;
|
|
25
|
-
}
|
|
26
|
-
if (command === "snapshot" && subcommand === "create") {
|
|
27
|
-
if (rest.length > 0) {
|
|
28
|
-
io.error(CLI_USAGE);
|
|
29
|
-
return 1;
|
|
30
|
-
}
|
|
31
|
-
await handlers.runSnapshotCreate();
|
|
32
|
-
return 0;
|
|
33
|
-
}
|
|
34
|
-
if (command === "check") {
|
|
35
|
-
if (rest.length > 0) {
|
|
36
|
-
io.error(CLI_USAGE);
|
|
37
|
-
return 1;
|
|
38
|
-
}
|
|
39
|
-
await handlers.runCheck(subcommand);
|
|
40
|
-
return 0;
|
|
41
|
-
}
|
|
42
|
-
if (command === "upgrade") {
|
|
43
|
-
if (subcommand || rest.length > 0) {
|
|
44
|
-
io.error(CLI_USAGE);
|
|
45
|
-
return 1;
|
|
46
|
-
}
|
|
47
|
-
await handlers.runUpgrade();
|
|
48
|
-
return 0;
|
|
49
|
-
}
|
|
50
|
-
io.error(CLI_USAGE);
|
|
51
|
-
return 1;
|
|
52
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
CLI_USAGE,
|
|
3
|
+
runCli
|
|
4
|
+
} from "../chunk-4UO6FK4G.js";
|
|
5
|
+
import "../chunk-MLKGABMK.js";
|
|
53
6
|
export {
|
|
54
7
|
CLI_USAGE,
|
|
55
8
|
runCli
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveRuntimeDependencySnapshot
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-JBASI5VV.js";
|
|
4
4
|
import "../chunk-G3E7SCME.js";
|
|
5
5
|
import {
|
|
6
6
|
disconnectStateAdapter
|
|
7
|
-
} from "../chunk-
|
|
8
|
-
import "../chunk-
|
|
7
|
+
} from "../chunk-Y5OFBCBZ.js";
|
|
8
|
+
import "../chunk-T77LUIX3.js";
|
|
9
9
|
import {
|
|
10
10
|
getPluginProviders,
|
|
11
11
|
getPluginRuntimeDependencies,
|
|
12
12
|
getPluginRuntimePostinstall
|
|
13
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-ZLMBNBUG.js";
|
|
14
|
+
import "../chunk-VALUBQ7R.js";
|
|
14
15
|
import "../chunk-Q3XNY442.js";
|
|
15
|
-
import "../chunk-
|
|
16
|
-
import "../chunk-
|
|
17
|
-
import "../chunk-
|
|
18
|
-
import "../chunk-
|
|
19
|
-
import "../chunk-2KG3PWR4.js";
|
|
16
|
+
import "../chunk-EJN6G5A2.js";
|
|
17
|
+
import "../chunk-OJ53FYVG.js";
|
|
18
|
+
import "../chunk-ST6YNAXG.js";
|
|
19
|
+
import "../chunk-MLKGABMK.js";
|
|
20
20
|
|
|
21
21
|
// src/cli/snapshot-warmup.ts
|
|
22
22
|
var DEFAULT_RUNTIME = "node22";
|
package/dist/cli/upgrade.js
CHANGED
|
@@ -1,59 +1,56 @@
|
|
|
1
1
|
import {
|
|
2
|
+
getConversation,
|
|
3
|
+
listConversationsByActivity,
|
|
4
|
+
recordConversationActivity,
|
|
5
|
+
requestConversationWork
|
|
6
|
+
} from "../chunk-R6Z5XWY3.js";
|
|
7
|
+
import {
|
|
8
|
+
JUNIOR_THREAD_STATE_TTL_MS,
|
|
2
9
|
coerceThreadConversationState
|
|
3
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-Z4CIQ3EB.js";
|
|
4
11
|
import {
|
|
5
12
|
defineJuniorPlugins,
|
|
6
13
|
pluginCatalogConfigFromEnv,
|
|
7
14
|
pluginCatalogConfigFromPluginSet,
|
|
8
|
-
|
|
9
|
-
} from "../chunk-
|
|
10
|
-
import {
|
|
11
|
-
JUNIOR_THREAD_STATE_TTL_MS,
|
|
12
|
-
createSqlStore,
|
|
13
|
-
createStateConversationStore,
|
|
14
|
-
getConversation,
|
|
15
|
-
requestConversationWork
|
|
16
|
-
} from "../chunk-UJ7OTHPO.js";
|
|
17
|
-
import {
|
|
18
|
-
parseDestination,
|
|
19
|
-
sameDestination
|
|
20
|
-
} from "../chunk-WBZ4M5N5.js";
|
|
15
|
+
pluginRuntimeRegistrationsFromPluginSet
|
|
16
|
+
} from "../chunk-SG5WAA7H.js";
|
|
21
17
|
import {
|
|
22
18
|
createPluginLogger,
|
|
23
19
|
createPluginState
|
|
24
|
-
} from "../chunk-
|
|
25
|
-
import "../chunk-62FUNJYS.js";
|
|
20
|
+
} from "../chunk-56TBVRJG.js";
|
|
26
21
|
import {
|
|
27
22
|
createJuniorSqlExecutor,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
readPluginMigrations
|
|
32
|
-
} from "../chunk-D7NFH5GD.js";
|
|
33
|
-
import {
|
|
34
|
-
loadAppPluginSet
|
|
35
|
-
} from "../chunk-Y2CM7HXH.js";
|
|
23
|
+
createSqlStore,
|
|
24
|
+
getDb
|
|
25
|
+
} from "../chunk-NYKJ3KON.js";
|
|
36
26
|
import {
|
|
37
27
|
disconnectStateAdapter,
|
|
38
28
|
getConnectedStateContext
|
|
39
|
-
} from "../chunk-
|
|
29
|
+
} from "../chunk-Y5OFBCBZ.js";
|
|
30
|
+
import {
|
|
31
|
+
parseDestination,
|
|
32
|
+
sameDestination
|
|
33
|
+
} from "../chunk-Q6XFTRV5.js";
|
|
40
34
|
import {
|
|
41
35
|
getChatConfig
|
|
42
|
-
} from "../chunk-
|
|
36
|
+
} from "../chunk-T77LUIX3.js";
|
|
37
|
+
import {
|
|
38
|
+
loadAppPluginSet
|
|
39
|
+
} from "../chunk-Y2CM7HXH.js";
|
|
43
40
|
import {
|
|
44
41
|
getPluginMigrationRoots,
|
|
45
42
|
setPluginCatalogConfig
|
|
46
|
-
} from "../chunk-
|
|
43
|
+
} from "../chunk-ZLMBNBUG.js";
|
|
44
|
+
import "../chunk-VALUBQ7R.js";
|
|
47
45
|
import "../chunk-Q3XNY442.js";
|
|
48
|
-
import "../chunk-EIYL7I4S.js";
|
|
49
|
-
import "../chunk-MCMROINU.js";
|
|
50
46
|
import {
|
|
51
47
|
isRecord,
|
|
52
48
|
toOptionalNumber,
|
|
53
49
|
toOptionalString
|
|
54
|
-
} from "../chunk-
|
|
55
|
-
import "../chunk-
|
|
56
|
-
import "../chunk-
|
|
50
|
+
} from "../chunk-EJN6G5A2.js";
|
|
51
|
+
import "../chunk-OJ53FYVG.js";
|
|
52
|
+
import "../chunk-ST6YNAXG.js";
|
|
53
|
+
import "../chunk-MLKGABMK.js";
|
|
57
54
|
|
|
58
55
|
// src/cli/upgrade.ts
|
|
59
56
|
import { createJiti } from "jiti";
|
|
@@ -73,6 +70,17 @@ async function backfillToSql(args) {
|
|
|
73
70
|
};
|
|
74
71
|
}
|
|
75
72
|
|
|
73
|
+
// src/chat/conversations/state.ts
|
|
74
|
+
function createStateConversationStore(state) {
|
|
75
|
+
return {
|
|
76
|
+
get: (args) => getConversation({ ...args, state }),
|
|
77
|
+
recordActivity: (args) => recordConversationActivity({ ...args, state }),
|
|
78
|
+
recordExecution: async () => {
|
|
79
|
+
},
|
|
80
|
+
listByActivity: (args) => listConversationsByActivity({ ...args, state })
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
76
84
|
// src/cli/upgrade/migrations/conversations-sql.ts
|
|
77
85
|
var CONVERSATION_BACKFILL_LIMIT = 1e4;
|
|
78
86
|
var REQUIRED_SQL_DATABASE_URL_MESSAGE = "Junior SQL database URL is required for conversation metadata upgrade. Set JUNIOR_DATABASE_URL or DATABASE_URL.";
|
|
@@ -202,11 +210,8 @@ function addResult(left, right) {
|
|
|
202
210
|
...left.skipped !== void 0 || right.skipped !== void 0 ? { skipped: (left.skipped ?? 0) + (right.skipped ?? 0) } : {}
|
|
203
211
|
};
|
|
204
212
|
}
|
|
205
|
-
function dbForPlugin(context,
|
|
206
|
-
|
|
207
|
-
return void 0;
|
|
208
|
-
}
|
|
209
|
-
return context.pluginDb ?? sqlUrlDb ?? getPluginDbForRegistration(plugin);
|
|
213
|
+
function dbForPlugin(context, sqlUrlDb) {
|
|
214
|
+
return context.db ?? sqlUrlDb ?? getDb();
|
|
210
215
|
}
|
|
211
216
|
async function runPluginStorageMigrations(context) {
|
|
212
217
|
const { pluginCatalogConfig, pluginSet } = await resolveUpgradePlugins(context);
|
|
@@ -214,14 +219,14 @@ async function runPluginStorageMigrations(context) {
|
|
|
214
219
|
return emptyResult();
|
|
215
220
|
}
|
|
216
221
|
const previousConfig = setPluginCatalogConfig(pluginCatalogConfig);
|
|
217
|
-
const ownedExecutor = context.
|
|
222
|
+
const ownedExecutor = context.db || !context.sqlDatabaseUrl ? void 0 : createJuniorSqlExecutor({
|
|
218
223
|
connectionString: context.sqlDatabaseUrl,
|
|
219
224
|
driver: context.sqlDriver ?? getChatConfig().sql.driver
|
|
220
225
|
});
|
|
221
|
-
const sqlUrlDb = ownedExecutor ?
|
|
226
|
+
const sqlUrlDb = ownedExecutor ? ownedExecutor.db() : void 0;
|
|
222
227
|
try {
|
|
223
228
|
let result = emptyResult();
|
|
224
|
-
const plugins =
|
|
229
|
+
const plugins = pluginRuntimeRegistrationsFromPluginSet(pluginSet).filter((plugin) => plugin.hooks?.migrateStorage).sort(
|
|
225
230
|
(left, right) => left.manifest.name.localeCompare(right.manifest.name)
|
|
226
231
|
);
|
|
227
232
|
for (const plugin of plugins) {
|
|
@@ -230,12 +235,7 @@ async function runPluginStorageMigrations(context) {
|
|
|
230
235
|
if (!hook) {
|
|
231
236
|
continue;
|
|
232
237
|
}
|
|
233
|
-
const db = dbForPlugin(context,
|
|
234
|
-
if (!db) {
|
|
235
|
-
throw new Error(
|
|
236
|
-
`Plugin "${pluginName}" storage migration requires database access`
|
|
237
|
-
);
|
|
238
|
-
}
|
|
238
|
+
const db = dbForPlugin(context, sqlUrlDb);
|
|
239
239
|
const pluginResult = await hook({
|
|
240
240
|
db,
|
|
241
241
|
log: createPluginLogger(pluginName),
|
|
@@ -257,6 +257,125 @@ var pluginStorageMigration = {
|
|
|
257
257
|
run: runPluginStorageMigrations
|
|
258
258
|
};
|
|
259
259
|
|
|
260
|
+
// src/chat/plugins/db.ts
|
|
261
|
+
import { createHash } from "crypto";
|
|
262
|
+
import { readdirSync, readFileSync, statSync } from "fs";
|
|
263
|
+
import path from "path";
|
|
264
|
+
import { z } from "zod";
|
|
265
|
+
var PLUGIN_SCHEMA_LOCK_NAME = "junior_plugin_schema";
|
|
266
|
+
var MIGRATION_FILENAME_RE = /^[0-9]{4}_[a-z0-9_]+\.sql$/;
|
|
267
|
+
var migrationRecordSchema = z.object({
|
|
268
|
+
id: z.string().min(1),
|
|
269
|
+
checksum: z.string().min(1)
|
|
270
|
+
}).strict();
|
|
271
|
+
function checksumSql(sql) {
|
|
272
|
+
return createHash("sha256").update(sql).digest("hex");
|
|
273
|
+
}
|
|
274
|
+
function parseStoredMigrationRecord(value) {
|
|
275
|
+
return migrationRecordSchema.parse(value);
|
|
276
|
+
}
|
|
277
|
+
function assertMigrationFilename(filename) {
|
|
278
|
+
if (!filename || filename !== path.basename(filename) || !MIGRATION_FILENAME_RE.test(filename)) {
|
|
279
|
+
throw new Error(`Plugin migration filename "${filename}" is invalid`);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
function assertUniqueMigrationIds(migrations) {
|
|
283
|
+
const seen = /* @__PURE__ */ new Set();
|
|
284
|
+
for (const migration of migrations) {
|
|
285
|
+
if (seen.has(migration.id)) {
|
|
286
|
+
throw new Error(`Duplicate plugin migration id ${migration.id}`);
|
|
287
|
+
}
|
|
288
|
+
seen.add(migration.id);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function migrationId(pluginName, filename) {
|
|
292
|
+
return `plugin:${pluginName}/${filename}`;
|
|
293
|
+
}
|
|
294
|
+
function createMigrationTableSql() {
|
|
295
|
+
return `
|
|
296
|
+
CREATE TABLE IF NOT EXISTS junior_schema_migrations (
|
|
297
|
+
id TEXT PRIMARY KEY,
|
|
298
|
+
checksum TEXT NOT NULL,
|
|
299
|
+
applied_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
300
|
+
)
|
|
301
|
+
`;
|
|
302
|
+
}
|
|
303
|
+
async function listAppliedMigrations(executor) {
|
|
304
|
+
const rows = await executor.query(
|
|
305
|
+
"SELECT id, checksum FROM junior_schema_migrations ORDER BY id ASC"
|
|
306
|
+
);
|
|
307
|
+
const records = /* @__PURE__ */ new Map();
|
|
308
|
+
for (const row of rows) {
|
|
309
|
+
const record = parseStoredMigrationRecord(row);
|
|
310
|
+
records.set(record.id, record);
|
|
311
|
+
}
|
|
312
|
+
return records;
|
|
313
|
+
}
|
|
314
|
+
async function applyPluginMigration(executor, migration) {
|
|
315
|
+
await executor.transaction(async () => {
|
|
316
|
+
await executor.execute(migration.sql);
|
|
317
|
+
await executor.execute(
|
|
318
|
+
"INSERT INTO junior_schema_migrations (id, checksum) VALUES ($1, $2)",
|
|
319
|
+
[migration.id, migration.checksum]
|
|
320
|
+
);
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
function readPluginMigrations(root) {
|
|
324
|
+
const migrationsDir = root.dir;
|
|
325
|
+
let stat;
|
|
326
|
+
try {
|
|
327
|
+
stat = statSync(migrationsDir);
|
|
328
|
+
} catch {
|
|
329
|
+
return [];
|
|
330
|
+
}
|
|
331
|
+
if (!stat.isDirectory()) {
|
|
332
|
+
throw new Error(
|
|
333
|
+
`Plugin "${root.pluginName}" migrations path is not a directory`
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
return readdirSync(migrationsDir).filter((filename) => filename.endsWith(".sql")).sort((left, right) => left.localeCompare(right)).map((filename) => {
|
|
337
|
+
assertMigrationFilename(filename);
|
|
338
|
+
const sql = readFileSync(path.join(migrationsDir, filename), "utf8");
|
|
339
|
+
if (!sql.trim()) {
|
|
340
|
+
throw new Error(
|
|
341
|
+
`Plugin "${root.pluginName}" migration "${filename}" is empty`
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
return {
|
|
345
|
+
checksum: checksumSql(sql),
|
|
346
|
+
filename,
|
|
347
|
+
id: migrationId(root.pluginName, filename),
|
|
348
|
+
pluginName: root.pluginName,
|
|
349
|
+
sql
|
|
350
|
+
};
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
async function migratePluginSchemas(executor, migrations) {
|
|
354
|
+
assertUniqueMigrationIds(migrations);
|
|
355
|
+
const result = {
|
|
356
|
+
existing: 0,
|
|
357
|
+
migrated: 0,
|
|
358
|
+
scanned: migrations.length
|
|
359
|
+
};
|
|
360
|
+
await executor.withLock(PLUGIN_SCHEMA_LOCK_NAME, async () => {
|
|
361
|
+
await executor.execute(createMigrationTableSql());
|
|
362
|
+
const applied = await listAppliedMigrations(executor);
|
|
363
|
+
for (const migration of migrations) {
|
|
364
|
+
const existing = applied.get(migration.id);
|
|
365
|
+
if (existing) {
|
|
366
|
+
if (existing.checksum !== migration.checksum) {
|
|
367
|
+
throw new Error(`Plugin migration ${migration.id} checksum changed`);
|
|
368
|
+
}
|
|
369
|
+
result.existing++;
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
await applyPluginMigration(executor, migration);
|
|
373
|
+
result.migrated++;
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
return result;
|
|
377
|
+
}
|
|
378
|
+
|
|
260
379
|
// src/cli/upgrade/migrations/plugin-sql.ts
|
|
261
380
|
var REQUIRED_SQL_DATABASE_URL_MESSAGE2 = "Junior SQL database URL is required for plugin schema migration. Set JUNIOR_DATABASE_URL or DATABASE_URL.";
|
|
262
381
|
function requirePluginSqlDatabaseUrl(context) {
|
|
@@ -886,10 +1005,10 @@ async function runUpgradeMigrations(context) {
|
|
|
886
1005
|
}
|
|
887
1006
|
return results;
|
|
888
1007
|
}
|
|
889
|
-
async function runUpgrade(io = DEFAULT_IO) {
|
|
1008
|
+
async function runUpgrade(io = DEFAULT_IO, options = {}) {
|
|
890
1009
|
try {
|
|
891
1010
|
const { redisStateAdapter, stateAdapter } = await getConnectedStateContext();
|
|
892
|
-
const pluginSet = await resolveUpgradePluginSet();
|
|
1011
|
+
const pluginSet = options.pluginSet === void 0 ? await resolveUpgradePluginSet() : options.pluginSet ?? void 0;
|
|
893
1012
|
io.info("Running Junior upgrade migrations...");
|
|
894
1013
|
await runUpgradeMigrations({
|
|
895
1014
|
io,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
closeDb,
|
|
3
|
+
getConversationStore,
|
|
4
|
+
getDb
|
|
5
|
+
} from "./chunk-NYKJ3KON.js";
|
|
6
|
+
import "./chunk-Q6XFTRV5.js";
|
|
7
|
+
import "./chunk-T77LUIX3.js";
|
|
8
|
+
import "./chunk-VALUBQ7R.js";
|
|
9
|
+
import "./chunk-EJN6G5A2.js";
|
|
10
|
+
import "./chunk-OJ53FYVG.js";
|
|
11
|
+
import "./chunk-ST6YNAXG.js";
|
|
12
|
+
import "./chunk-MLKGABMK.js";
|
|
13
|
+
export {
|
|
14
|
+
closeDb,
|
|
15
|
+
getConversationStore,
|
|
16
|
+
getDb
|
|
17
|
+
};
|
package/dist/deployment.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const JUNIOR_HEARTBEAT_ROUTE = "/api/internal/heartbeat";
|
|
2
2
|
export declare const JUNIOR_HEARTBEAT_CRON_SCHEDULE = "* * * * *";
|
|
3
3
|
export declare const JUNIOR_CONVERSATION_WORK_CALLBACK_ROUTE = "/api/internal/agent/continue";
|
|
4
|
+
export declare const JUNIOR_PLUGIN_TASK_CALLBACK_ROUTE = "/api/internal/plugin/tasks";
|
|
4
5
|
export declare const LEGACY_JUNIOR_CONVERSATION_WORK_FUNCTION = "api/internal/agent/continue.ts";
|
|
5
6
|
/** Resolve the deployment version used for release and telemetry correlation. */
|
|
6
7
|
export declare function getDeploymentServiceVersion(): string | undefined;
|