@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.
Files changed (174) hide show
  1. package/dist/agent-CMyTD4DD.js +17509 -0
  2. package/dist/agent-hooks-Bbcp9e33.js +4040 -0
  3. package/dist/agent-runner-DNb1A49M.js +678 -0
  4. package/dist/api/schema.d.ts +2728 -2639
  5. package/dist/api/schema.js +4 -169
  6. package/dist/api.d.ts +23 -17
  7. package/dist/api.js +3881 -5326
  8. package/dist/app-B1TOqBI8.d.ts +246 -0
  9. package/dist/app.d.ts +4 -520
  10. package/dist/app.js +9522 -11875
  11. package/dist/auth-pause-state-DosEalIG.js +168 -0
  12. package/dist/catalog-runtime-BReos-D4.js +7 -0
  13. package/dist/checkpoint-CNrPyRJN.js +2450 -0
  14. package/dist/cli/chat.d.ts +20 -0
  15. package/dist/cli/chat.js +229 -336
  16. package/dist/cli/check.d.ts +8 -0
  17. package/dist/cli/check.js +513 -806
  18. package/dist/cli/env.d.ts +13 -0
  19. package/dist/cli/env.js +63 -12
  20. package/dist/cli/init.d.ts +3 -0
  21. package/dist/cli/init.js +90 -159
  22. package/dist/cli/main.d.ts +6 -0
  23. package/dist/cli/main.js +43 -64
  24. package/dist/cli/plugins.d.ts +13 -0
  25. package/dist/cli/plugins.js +148 -227
  26. package/dist/cli/run.d.ts +16 -0
  27. package/dist/cli/run.js +52 -8
  28. package/dist/cli/snapshot-create.d.ts +4 -0
  29. package/dist/cli/snapshot-create.js +71 -125
  30. package/dist/cli/upgrade.d.ts +15 -0
  31. package/dist/cli/upgrade.js +232 -335
  32. package/dist/config-nGCW1OTG.js +941 -0
  33. package/dist/context-B45_WqVX.js +298 -0
  34. package/dist/conversation-privacy-B4voFRSm.js +182 -0
  35. package/dist/conversation-work-C6y3T5Hx.js +51 -0
  36. package/dist/credential-sync-kXr1hvO1.js +2660 -0
  37. package/dist/db-BeyXKJOI.d.ts +5 -0
  38. package/dist/destinations-BeBiJeEM.js +29 -0
  39. package/dist/execution-stats-DWfSihcH.js +373 -0
  40. package/dist/executor-DcMSlI5c.js +721 -0
  41. package/dist/experimental-CIXf7Uye.js +46 -0
  42. package/dist/history-ClE4toxe.d.ts +32 -0
  43. package/dist/history-CqTuSAdI.js +441 -0
  44. package/dist/instrumentation.d.ts +3 -3
  45. package/dist/instrumentation.js +130 -176
  46. package/dist/job-queue-Drn_LXlM.js +63 -0
  47. package/dist/logging-BzAk1S_s.js +1210 -0
  48. package/dist/model-profile-CZmVoGdX.js +49 -0
  49. package/dist/nitro.d.ts +31 -36
  50. package/dist/nitro.js +275 -456
  51. package/dist/oauth-callback-server-JiftokvA.js +130 -0
  52. package/dist/oauth-relay-CdCnu80W.js +62 -0
  53. package/dist/package-discovery-7a9YqLhE.js +455 -0
  54. package/dist/pending-auth-CWmSdZVg.js +185 -0
  55. package/dist/plugin-module-BKGOXca2.js +81 -0
  56. package/dist/plugins-BI9A1vKA.d.ts +95 -0
  57. package/dist/plugins-egKWjgue.js +99 -0
  58. package/dist/private-trace-result-BLvBjy_e.js +16 -0
  59. package/dist/profile-CrT5nXbw.js +861 -0
  60. package/dist/registry-DH1xUo2N.js +1419 -0
  61. package/dist/reporting-schema-DosTN__Q.js +105 -0
  62. package/dist/resolve-CZHnfxaS.js +546 -0
  63. package/dist/rolldown-runtime-B4FMCO8f.js +28 -0
  64. package/dist/runner-CZV2sC46.js +392 -0
  65. package/dist/sandbox-egress-signals-bHZfmhbd.js +46 -0
  66. package/dist/schema-Rn8-XEaN.js +1140 -0
  67. package/dist/sentry-CD3SdJl-.js +26 -0
  68. package/dist/skills-CIcDQSgM.js +316 -0
  69. package/dist/spawn-DdkUFRmq.js +29 -0
  70. package/dist/stats-DTUbAb88.js +2634 -0
  71. package/dist/store-C5qxF2ac.d.ts +208 -0
  72. package/dist/task-queue-CJIR4RF7.js +136 -0
  73. package/dist/task-runner-D-O3A-Cp.js +639 -0
  74. package/dist/thread-state-CRc9jTJS.js +431 -0
  75. package/dist/turn-execution-BkinIdJF.js +47 -0
  76. package/dist/turn-lifecycle-DQV19VTW.js +54 -0
  77. package/dist/usage-D3EbSO7w.js +296 -0
  78. package/dist/usage-schema-CKaDkH_j.js +20 -0
  79. package/dist/validation-C2CR-OX3.js +40 -0
  80. package/dist/vercel-queue-DIkVcfK4.js +167 -0
  81. package/dist/vercel.d.ts +6 -6
  82. package/dist/vercel.js +14 -6
  83. package/dist/version-CnXZ614E.d.ts +5 -0
  84. package/dist/version-DxcWdoKa.js +8 -0
  85. package/dist/version.d.ts +2 -4
  86. package/dist/version.js +2 -6
  87. package/dist/web-authorization-RMBxAR_t.js +76 -0
  88. package/dist/web-input-3EPfpf55.js +494 -0
  89. package/dist/work-fGofI7Op.js +509 -0
  90. package/dist/worker-CsOLq-mR.js +625 -0
  91. package/package.json +8 -8
  92. package/dist/agent-hooks-GB2VPTNA.js +0 -51
  93. package/dist/catalog-runtime-UBLIWD3O.js +0 -14
  94. package/dist/chunk-2LYHWMR4.js +0 -46
  95. package/dist/chunk-352OWAZH.js +0 -320
  96. package/dist/chunk-3Y47VMHV.js +0 -6
  97. package/dist/chunk-3YJSKOWF.js +0 -164
  98. package/dist/chunk-4KSSKTQ5.js +0 -229
  99. package/dist/chunk-4UO6FK4G.js +0 -64
  100. package/dist/chunk-5AHX53NQ.js +0 -717
  101. package/dist/chunk-5J3E5FWA.js +0 -700
  102. package/dist/chunk-5PDAG6O3.js +0 -206
  103. package/dist/chunk-6Y5B5PEX.js +0 -80
  104. package/dist/chunk-7GWQ5S5R.js +0 -2086
  105. package/dist/chunk-7H2VZTWN.js +0 -103
  106. package/dist/chunk-7NL7T6VU.js +0 -406
  107. package/dist/chunk-A5L27LE4.js +0 -387
  108. package/dist/chunk-ADIAWL34.js +0 -81
  109. package/dist/chunk-ASTEMBKJ.js +0 -519
  110. package/dist/chunk-CEMMLV5L.js +0 -98
  111. package/dist/chunk-CM5HNV2W.js +0 -131
  112. package/dist/chunk-CRTRBBRI.js +0 -105
  113. package/dist/chunk-DA2KGZZI.js +0 -13
  114. package/dist/chunk-DIB4GX3G.js +0 -8
  115. package/dist/chunk-DKIJ2RP5.js +0 -68
  116. package/dist/chunk-DWPN6SCH.js +0 -172
  117. package/dist/chunk-EDKUFGPL.js +0 -64
  118. package/dist/chunk-ENY6SKIU.js +0 -1228
  119. package/dist/chunk-F4MGCZOX.js +0 -2943
  120. package/dist/chunk-FA6POGLH.js +0 -70
  121. package/dist/chunk-FSUR7GTG.js +0 -20475
  122. package/dist/chunk-GKEOHJL5.js +0 -1856
  123. package/dist/chunk-GMCB6W5Y.js +0 -333
  124. package/dist/chunk-IE2VPG7O.js +0 -1135
  125. package/dist/chunk-IZ5B5IHQ.js +0 -3656
  126. package/dist/chunk-JAL3CH4G.js +0 -27
  127. package/dist/chunk-KIIEUXD3.js +0 -1764
  128. package/dist/chunk-KXU4NIL7.js +0 -692
  129. package/dist/chunk-MTM5IFCY.js +0 -1190
  130. package/dist/chunk-N7TMSOZH.js +0 -235
  131. package/dist/chunk-NCEBK6PH.js +0 -36
  132. package/dist/chunk-NHJU2ZAL.js +0 -56
  133. package/dist/chunk-P6KTRNVC.js +0 -321
  134. package/dist/chunk-PDO5BLNM.js +0 -22
  135. package/dist/chunk-PDRNLLFT.js +0 -3295
  136. package/dist/chunk-PEQXYSSE.js +0 -45
  137. package/dist/chunk-PKEX2AQX.js +0 -198
  138. package/dist/chunk-PSJCGIGO.js +0 -1163
  139. package/dist/chunk-PZUSUL55.js +0 -506
  140. package/dist/chunk-R45M4TUS.js +0 -37
  141. package/dist/chunk-RC745GGZ.js +0 -122
  142. package/dist/chunk-SP3QKZXJ.js +0 -820
  143. package/dist/chunk-TXKUKMVO.js +0 -417
  144. package/dist/chunk-UE4GPWSD.js +0 -931
  145. package/dist/chunk-UIE3R5XU.js +0 -17
  146. package/dist/chunk-UXPG6ZIN.js +0 -84
  147. package/dist/chunk-VFUK3X5B.js +0 -50
  148. package/dist/chunk-VNMJWREK.js +0 -787
  149. package/dist/chunk-VZ7CSOX2.js +0 -706
  150. package/dist/chunk-WCNQJKFT.js +0 -10
  151. package/dist/chunk-WDZR3QQM.js +0 -135
  152. package/dist/chunk-WLYVJCHV.js +0 -1433
  153. package/dist/chunk-WS7NAFTM.js +0 -1520
  154. package/dist/chunk-X6GDDWQH.js +0 -60
  155. package/dist/chunk-XPDEYNQI.js +0 -102
  156. package/dist/chunk-XRW44VGM.js +0 -58
  157. package/dist/chunk-Y2CM7HXH.js +0 -111
  158. package/dist/chunk-Y7X25LFY.js +0 -15
  159. package/dist/conversation-work-VIOQ5ZF3.js +0 -54
  160. package/dist/db-NGDJV7YH.js +0 -26
  161. package/dist/discovery-DWVDM7UK.js +0 -44
  162. package/dist/experimental-P5FZM4CU.js +0 -12
  163. package/dist/oauth-callback-server-YFY7YEGK.js +0 -243
  164. package/dist/oauth-relay-5XPVRPYB.js +0 -8
  165. package/dist/plugins-YTYJMMJF.js +0 -14
  166. package/dist/runner-ORTNSB2Q.js +0 -522
  167. package/dist/sandbox-egress-signals-FIL7EGPR.js +0 -73
  168. package/dist/sentry-MB3NL3IR.js +0 -42
  169. package/dist/skills-H376WQOH.js +0 -27
  170. package/dist/spawn-T43WHLOS.js +0 -42
  171. package/dist/task-runner-LBZWF32V.js +0 -36
  172. package/dist/validation-REJLRKI6.js +0 -17
  173. package/dist/work-3KJ3RE76.js +0 -51
  174. package/dist/worker-QFEBU72E.js +0 -24
@@ -1,131 +0,0 @@
1
- // src/plugins.ts
2
- function cloneManifests(manifests) {
3
- return manifests ? structuredClone(manifests) : void 0;
4
- }
5
- function cloneInlineManifests(registrations) {
6
- const inlineManifests = registrations.flatMap(
7
- (plugin) => plugin.manifest ? [
8
- {
9
- manifest: {
10
- ...structuredClone(plugin.manifest),
11
- configKeys: plugin.manifest.configKeys?.map(
12
- (key) => key.includes(".") ? key : `${plugin.manifest.name}.${key}`
13
- ) ?? [],
14
- ...plugin.manifest.target ? {
15
- target: {
16
- ...plugin.manifest.target,
17
- configKey: plugin.manifest.target.configKey.includes(".") ? plugin.manifest.target.configKey : `${plugin.manifest.name}.${plugin.manifest.target.configKey}`
18
- }
19
- } : void 0
20
- },
21
- ...plugin.packageName ? { packageName: plugin.packageName } : void 0
22
- }
23
- ] : []
24
- );
25
- return inlineManifests.length > 0 ? inlineManifests : void 0;
26
- }
27
- function assertUniquePluginNames(registrations) {
28
- const seen = /* @__PURE__ */ new Set();
29
- for (const plugin of registrations) {
30
- const name = plugin.manifest.name;
31
- if (seen.has(name)) {
32
- throw new Error(`Duplicate plugin registration name "${name}"`);
33
- }
34
- seen.add(name);
35
- }
36
- }
37
- function assertUniquePackageNames(packageNames) {
38
- const seen = /* @__PURE__ */ new Set();
39
- for (const packageName of packageNames) {
40
- if (seen.has(packageName)) {
41
- throw new Error(`Duplicate plugin package name "${packageName}"`);
42
- }
43
- seen.add(packageName);
44
- }
45
- }
46
- function normalizePluginInput(input) {
47
- if (typeof input === "string") {
48
- return { packageName: input };
49
- }
50
- return { registration: input };
51
- }
52
- function defineJuniorPlugins(inputs, options = {}) {
53
- const normalized = inputs.map(normalizePluginInput);
54
- const packageNames = normalized.flatMap(
55
- (input) => input.packageName ? [input.packageName] : []
56
- );
57
- const registrations = normalized.flatMap(
58
- (input) => input.registration ? [input.registration] : []
59
- );
60
- assertUniquePackageNames(packageNames);
61
- assertUniquePluginNames(registrations);
62
- const manifests = cloneManifests(options.manifests);
63
- return {
64
- packageNames,
65
- registrations: registrations.map((plugin) => ({ ...plugin })),
66
- ...manifests ? { manifests } : void 0
67
- };
68
- }
69
- function pluginCatalogConfigFromPluginSet(pluginSet) {
70
- if (!pluginSet) {
71
- return void 0;
72
- }
73
- const packages = [
74
- .../* @__PURE__ */ new Set([
75
- ...pluginSet.packageNames,
76
- ...pluginSet.registrations.flatMap(
77
- (plugin) => plugin.packageName ? [plugin.packageName] : []
78
- )
79
- ])
80
- ];
81
- const manifests = cloneManifests(pluginSet.manifests);
82
- const inlineManifests = cloneInlineManifests(pluginSet.registrations);
83
- if (packages.length === 0 && !manifests && !inlineManifests) {
84
- return void 0;
85
- }
86
- return {
87
- ...inlineManifests ? { inlineManifests } : void 0,
88
- ...packages.length > 0 ? { packages } : void 0,
89
- ...manifests ? { manifests } : void 0
90
- };
91
- }
92
- function readEnvPluginPackages(env = process.env) {
93
- const value = env.JUNIOR_PLUGIN_PACKAGES;
94
- if (!value) {
95
- return void 0;
96
- }
97
- let parsed;
98
- try {
99
- parsed = JSON.parse(value);
100
- } catch (error) {
101
- throw new Error("JUNIOR_PLUGIN_PACKAGES must be valid JSON", {
102
- cause: error
103
- });
104
- }
105
- if (!Array.isArray(parsed) || parsed.some((item) => typeof item !== "string" || !item.trim())) {
106
- throw new Error(
107
- "JUNIOR_PLUGIN_PACKAGES must be a JSON array of package names"
108
- );
109
- }
110
- return parsed;
111
- }
112
- function pluginCatalogConfigFromEnv(env = process.env) {
113
- const packages = readEnvPluginPackages(env);
114
- return packages ? { packages } : void 0;
115
- }
116
- function pluginRuntimeRegistrationsFromPluginSet(pluginSet) {
117
- return pluginSet?.registrations.filter(
118
- (plugin) => plugin.hooks || plugin.tasks || plugin.userPages?.length
119
- ) ?? [];
120
- }
121
- function pluginCliRegistrationsFromPluginSet(pluginSet) {
122
- return pluginSet?.registrations.filter((plugin) => plugin.cli) ?? [];
123
- }
124
-
125
- export {
126
- defineJuniorPlugins,
127
- pluginCatalogConfigFromPluginSet,
128
- pluginCatalogConfigFromEnv,
129
- pluginRuntimeRegistrationsFromPluginSet,
130
- pluginCliRegistrationsFromPluginSet
131
- };
@@ -1,105 +0,0 @@
1
- import {
2
- getStateAdapter
3
- } from "./chunk-P6KTRNVC.js";
4
- import {
5
- getClient
6
- } from "./chunk-PEQXYSSE.js";
7
-
8
- // src/chat/conversations/web-authorization.ts
9
- import { randomUUID } from "crypto";
10
- var WEB_AUTHORIZATION_PREFIX = "junior:web_authorization:v1";
11
- var WEB_AUTHORIZATION_TTL_MS = 24 * 60 * 60 * 1e3;
12
- function authorizationKey(conversationId, actorId) {
13
- return `${WEB_AUTHORIZATION_PREFIX}:${conversationId}:${actorId}`;
14
- }
15
- function createWebAuthorization(args) {
16
- return {
17
- createState: async () => randomUUID(),
18
- deliver: async (request) => {
19
- await getStateAdapter().set(
20
- authorizationKey(args.conversationId, args.actorId),
21
- JSON.stringify({ ...request, ...args }),
22
- WEB_AUTHORIZATION_TTL_MS
23
- );
24
- }
25
- };
26
- }
27
- async function getWebAuthorization(args) {
28
- const value = await getStateAdapter().get(
29
- authorizationKey(args.conversationId, args.actorId)
30
- );
31
- if (typeof value !== "string") return void 0;
32
- try {
33
- const parsed = JSON.parse(value);
34
- if (parsed.actorId !== args.actorId || parsed.conversationId !== args.conversationId || typeof parsed.authorizationUrl !== "string" || typeof parsed.label !== "string" || typeof parsed.completionText !== "string") {
35
- return void 0;
36
- }
37
- return parsed;
38
- } catch {
39
- return void 0;
40
- }
41
- }
42
- async function deleteWebAuthorization(args) {
43
- await getStateAdapter().delete(
44
- authorizationKey(args.conversationId, args.actorId)
45
- );
46
- }
47
-
48
- // src/chat/sentry-links.ts
49
- function getSentryOrgSlug() {
50
- const slug = process.env.SENTRY_ORG_SLUG?.trim();
51
- return slug || void 0;
52
- }
53
- function isSentrySaasDsnHost(host) {
54
- return host === "sentry.io" || host.endsWith(".sentry.io");
55
- }
56
- function buildSentryWebBaseUrl(dsn) {
57
- if (isSentrySaasDsnHost(dsn.host)) {
58
- return "https://sentry.io";
59
- }
60
- const port = dsn.port ? `:${dsn.port}` : "";
61
- const path = dsn.path ? `/${dsn.path}` : "";
62
- return `${dsn.protocol}://${dsn.host}${port}${path}`;
63
- }
64
- function buildSentryOrgPath(args) {
65
- const client = getClient();
66
- const dsn = client?.getDsn();
67
- if (!dsn?.host || !dsn.projectId) {
68
- return void 0;
69
- }
70
- const orgSlug = getSentryOrgSlug();
71
- if (!orgSlug) {
72
- return void 0;
73
- }
74
- const params = new URLSearchParams();
75
- params.set("project", dsn.projectId);
76
- if (args.query) {
77
- for (const [key, value] of Object.entries(args.query)) {
78
- params.set(key, value);
79
- }
80
- }
81
- const path = `${args.path}?${params.toString()}`;
82
- if (isSentrySaasDsnHost(dsn.host)) {
83
- return `https://${orgSlug}.sentry.io/${path}`;
84
- }
85
- return `${buildSentryWebBaseUrl(dsn)}/organizations/${orgSlug}/${path}`;
86
- }
87
- function buildSentryConversationUrl(conversationId) {
88
- return buildSentryOrgPath({
89
- path: `explore/conversations/${encodeURIComponent(conversationId)}/`
90
- });
91
- }
92
- function buildSentryEventUrl(eventId) {
93
- return buildSentryOrgPath({
94
- path: "issues/",
95
- query: { query: eventId }
96
- });
97
- }
98
-
99
- export {
100
- buildSentryConversationUrl,
101
- buildSentryEventUrl,
102
- createWebAuthorization,
103
- getWebAuthorization,
104
- deleteWebAuthorization
105
- };
@@ -1,13 +0,0 @@
1
- // src/chat/state/turn-id.ts
2
- function buildDeterministicTurnId(messageId) {
3
- const sanitized = messageId.replace(/[^a-zA-Z0-9_-]/g, "_");
4
- return `turn_${sanitized}`;
5
- }
6
- function buildDeterministicAssistantMessageId(turnId) {
7
- return `${turnId}:assistant:1`;
8
- }
9
-
10
- export {
11
- buildDeterministicTurnId,
12
- buildDeterministicAssistantMessageId
13
- };
@@ -1,8 +0,0 @@
1
- // src/chat/oauth-authorization.ts
2
- function authorizationId(args) {
3
- return `${args.sessionId}:${args.kind}:${args.provider}`;
4
- }
5
-
6
- export {
7
- authorizationId
8
- };
@@ -1,68 +0,0 @@
1
- import {
2
- conversationQueueMessageSchema
3
- } from "./chunk-JAL3CH4G.js";
4
- import {
5
- QUEUE_SIGNATURE_MAX_AGE_MS,
6
- createVercelQueueClient,
7
- signQueueMessage,
8
- verifyQueueMessage
9
- } from "./chunk-7H2VZTWN.js";
10
-
11
- // src/chat/task-execution/queue-signing.ts
12
- var conversationQueueSign = {
13
- context: "junior.conversation_work_queue.v2",
14
- schema: conversationQueueMessageSchema,
15
- separator: ":",
16
- signatureVersion: "v2",
17
- parts: (message) => [message.conversationId]
18
- };
19
- var CONVERSATION_WORK_QUEUE_SIGNATURE_MAX_SKEW_MS = QUEUE_SIGNATURE_MAX_AGE_MS;
20
- function signConversationQueueMessage(message, nowMs = Date.now()) {
21
- return signQueueMessage(conversationQueueSign, message, nowMs);
22
- }
23
- function verifyConversationQueueMessage(value, nowMs = Date.now()) {
24
- return verifyQueueMessage(conversationQueueSign, value, nowMs);
25
- }
26
-
27
- // src/chat/task-execution/vercel-queue.ts
28
- var DEFAULT_CONVERSATION_WORK_QUEUE_TOPIC = "junior_conversation_work";
29
- var CONVERSATION_WORK_QUEUE_RETENTION_SECONDS = CONVERSATION_WORK_QUEUE_SIGNATURE_MAX_SKEW_MS / 1e3;
30
- var defaultQueue;
31
- function resolveConversationWorkQueueTopic(options = {}) {
32
- const topic = options.topic?.trim();
33
- return topic || process.env.JUNIOR_CONVERSATION_WORK_QUEUE_TOPIC?.trim() || DEFAULT_CONVERSATION_WORK_QUEUE_TOPIC;
34
- }
35
- function toDelaySeconds(options) {
36
- if (!options?.delayMs || options.delayMs <= 0) {
37
- return void 0;
38
- }
39
- return Math.ceil(options.delayMs / 1e3);
40
- }
41
- function createVercelConversationWorkQueue(options = {}) {
42
- const topic = resolveConversationWorkQueueTopic(options);
43
- const client = options.client ?? createVercelQueueClient();
44
- return {
45
- async send(message, sendOptions) {
46
- const result = await client.send(
47
- topic,
48
- signConversationQueueMessage(message),
49
- {
50
- idempotencyKey: sendOptions?.idempotencyKey,
51
- delaySeconds: toDelaySeconds(sendOptions),
52
- retentionSeconds: options.retentionSeconds ?? CONVERSATION_WORK_QUEUE_RETENTION_SECONDS
53
- }
54
- );
55
- return result.messageId ? { messageId: result.messageId } : {};
56
- }
57
- };
58
- }
59
- function getVercelConversationWorkQueue() {
60
- defaultQueue ??= createVercelConversationWorkQueue();
61
- return defaultQueue;
62
- }
63
-
64
- export {
65
- verifyConversationQueueMessage,
66
- resolveConversationWorkQueueTopic,
67
- getVercelConversationWorkQueue
68
- };
@@ -1,172 +0,0 @@
1
- import {
2
- discoverNodeModulesDirs,
3
- isDirectory,
4
- isFile,
5
- isValidPackageName,
6
- resolvePackageLocation
7
- } from "./chunk-TXKUKMVO.js";
8
-
9
- // src/chat/plugins/package-discovery.ts
10
- import path from "path";
11
- function normalizeForGlob(targetPath) {
12
- return targetPath.split(path.sep).join("/");
13
- }
14
- function uniqueStringsInOrder(values) {
15
- const seen = /* @__PURE__ */ new Set();
16
- const resolved = [];
17
- for (const value of values) {
18
- if (seen.has(value)) {
19
- continue;
20
- }
21
- seen.add(value);
22
- resolved.push(value);
23
- }
24
- return resolved;
25
- }
26
- function pathForTracingInclude(cwd, targetPath) {
27
- const relative = path.relative(cwd, targetPath);
28
- if (!relative || path.isAbsolute(relative) || relative === ".." || relative.startsWith(`..${path.sep}`)) {
29
- return null;
30
- }
31
- const normalized = normalizeForGlob(relative);
32
- return normalized.startsWith(".") ? normalized : `./${normalized}`;
33
- }
34
- function normalizePluginPackageNames(packageNames) {
35
- if (packageNames === void 0) {
36
- return [];
37
- }
38
- if (!Array.isArray(packageNames)) {
39
- throw new Error("Plugin package names must be an array");
40
- }
41
- const normalized = [];
42
- const seen = /* @__PURE__ */ new Set();
43
- for (const packageName of packageNames) {
44
- const normalizedPackageName = typeof packageName === "string" ? packageName.trim() : "";
45
- if (!normalizedPackageName || !isValidPackageName(normalizedPackageName)) {
46
- throw new Error("Plugin package names must be valid npm package names");
47
- }
48
- if (seen.has(normalizedPackageName)) {
49
- continue;
50
- }
51
- seen.add(normalizedPackageName);
52
- normalized.push(normalizedPackageName);
53
- }
54
- return normalized;
55
- }
56
- function formatNodeModulesDirs(candidateNodeModulesDirs) {
57
- return candidateNodeModulesDirs.length > 0 ? candidateNodeModulesDirs.join(", ") : "none found";
58
- }
59
- function resolvePackageDirFromName(cwd, packageName, candidateNodeModulesDirs) {
60
- return resolvePackageLocation(cwd, packageName, {
61
- nodeModulesDirs: candidateNodeModulesDirs
62
- }) ?? null;
63
- }
64
- function readPluginPackageFlags(dir) {
65
- const hasRootPluginManifest = isFile(path.join(dir, "plugin.yaml"));
66
- const hasMigrationsDir = isDirectory(path.join(dir, "migrations"));
67
- const hasPluginsDir = isDirectory(path.join(dir, "plugins"));
68
- const hasSkillsDir = isDirectory(path.join(dir, "skills"));
69
- if (!hasRootPluginManifest && !hasMigrationsDir && !hasPluginsDir && !hasSkillsDir) {
70
- return null;
71
- }
72
- return {
73
- hasRootPluginManifest,
74
- hasMigrationsDir,
75
- hasPluginsDir,
76
- hasSkillsDir
77
- };
78
- }
79
- function discoverDeclaredPackages(packageNames, candidateNodeModulesDirs, cwd) {
80
- const discovered = [];
81
- const seenPackageDirs = /* @__PURE__ */ new Set();
82
- for (const packageName of packageNames) {
83
- const resolved = resolvePackageDirFromName(
84
- cwd,
85
- packageName,
86
- candidateNodeModulesDirs
87
- );
88
- if (!resolved) {
89
- throw new Error(
90
- `Plugin package "${packageName}" was configured but could not be resolved from node_modules or package resolution (${formatNodeModulesDirs(candidateNodeModulesDirs)})`
91
- );
92
- }
93
- if (seenPackageDirs.has(resolved.dir)) {
94
- continue;
95
- }
96
- const pluginFlags = readPluginPackageFlags(resolved.dir);
97
- if (!pluginFlags) {
98
- throw new Error(
99
- `Plugin package "${packageName}" was configured but does not contain plugin content; expected plugin.yaml, migrations/, plugins/, or skills/ in ${resolved.dir}`
100
- );
101
- }
102
- seenPackageDirs.add(resolved.dir);
103
- discovered.push({
104
- dir: resolved.dir,
105
- nodeModulesDir: resolved.nodeModulesDir,
106
- packageName,
107
- ...pluginFlags
108
- });
109
- }
110
- return discovered;
111
- }
112
- function discoverInstalledPluginPackageContent(cwd = process.cwd(), options) {
113
- const resolvedCwd = path.resolve(cwd);
114
- const packageNames = normalizePluginPackageNames(options?.packageNames);
115
- const nodeModulesDirs = options?.nodeModulesDirs ?? discoverNodeModulesDirs(resolvedCwd);
116
- const discoveredPackages = discoverDeclaredPackages(
117
- packageNames,
118
- nodeModulesDirs,
119
- resolvedCwd
120
- );
121
- const manifestRoots = [];
122
- const skillRoots = [];
123
- const tracingIncludes = [];
124
- for (const pkg of discoveredPackages) {
125
- const tracingBasePath = pkg.nodeModulesDir ? pathForTracingInclude(
126
- resolvedCwd,
127
- path.join(pkg.nodeModulesDir, ...pkg.packageName.split("/"))
128
- ) : pathForTracingInclude(resolvedCwd, pkg.dir);
129
- if (pkg.hasRootPluginManifest) {
130
- manifestRoots.push(pkg.dir);
131
- if (tracingBasePath) {
132
- tracingIncludes.push(`${tracingBasePath}/plugin.yaml`);
133
- }
134
- }
135
- if (pkg.hasMigrationsDir) {
136
- if (tracingBasePath) {
137
- tracingIncludes.push(`${tracingBasePath}/migrations/**/*`);
138
- }
139
- }
140
- if (pkg.hasPluginsDir) {
141
- manifestRoots.push(path.join(pkg.dir, "plugins"));
142
- if (tracingBasePath) {
143
- tracingIncludes.push(`${tracingBasePath}/plugins/**/*`);
144
- }
145
- }
146
- if (pkg.hasSkillsDir) {
147
- skillRoots.push(path.join(pkg.dir, "skills"));
148
- if (tracingBasePath) {
149
- tracingIncludes.push(`${tracingBasePath}/skills/**/*`);
150
- }
151
- }
152
- }
153
- return {
154
- packageNames: uniqueStringsInOrder(
155
- discoveredPackages.map((pkg) => pkg.packageName)
156
- ),
157
- packages: discoveredPackages.map((pkg) => ({
158
- dir: pkg.dir,
159
- hasMigrationsDir: pkg.hasMigrationsDir,
160
- hasSkillsDir: pkg.hasSkillsDir,
161
- packageName: pkg.packageName
162
- })),
163
- manifestRoots: uniqueStringsInOrder(manifestRoots),
164
- skillRoots: uniqueStringsInOrder(skillRoots),
165
- tracingIncludes: uniqueStringsInOrder(tracingIncludes)
166
- };
167
- }
168
-
169
- export {
170
- normalizePluginPackageNames,
171
- discoverInstalledPluginPackageContent
172
- };
@@ -1,64 +0,0 @@
1
- import {
2
- getConversationEventStore
3
- } from "./chunk-GKEOHJL5.js";
4
-
5
- // src/chat/conversations/turn-lifecycle.ts
6
- var ConversationTurnLifecycleService = class {
7
- constructor(events) {
8
- this.events = events;
9
- }
10
- events;
11
- /** Record the turn start once after every input message is durable. */
12
- async start(input) {
13
- await this.events.append(input.conversationId, [
14
- {
15
- idempotencyKey: `turn:${input.turnId}:started`,
16
- createdAtMs: input.createdAtMs,
17
- data: {
18
- type: "turn_started",
19
- turnId: input.turnId,
20
- inputMessageIds: input.inputMessageIds,
21
- surface: input.surface
22
- }
23
- }
24
- ]);
25
- }
26
- /** Record successful or intentional-silence completion once. */
27
- async complete(input) {
28
- await this.events.append(input.conversationId, [
29
- {
30
- idempotencyKey: `turn:${input.turnId}:terminal`,
31
- createdAtMs: input.createdAtMs,
32
- data: {
33
- type: "turn_completed",
34
- turnId: input.turnId,
35
- outcome: input.outcome
36
- }
37
- }
38
- ]);
39
- }
40
- /** Record a classified failure once. Do not store raw error text. */
41
- async fail(input) {
42
- await this.events.append(input.conversationId, [
43
- {
44
- idempotencyKey: `turn:${input.turnId}:terminal`,
45
- createdAtMs: input.createdAtMs,
46
- data: {
47
- type: "turn_failed",
48
- turnId: input.turnId,
49
- failureCode: input.failureCode,
50
- ...input.failureReason ? { failureReason: input.failureReason } : void 0,
51
- ...input.eventId ? { eventId: input.eventId } : void 0
52
- }
53
- }
54
- ]);
55
- }
56
- };
57
- function getTurnLifecycle() {
58
- return new ConversationTurnLifecycleService(getConversationEventStore());
59
- }
60
-
61
- export {
62
- ConversationTurnLifecycleService,
63
- getTurnLifecycle
64
- };