totem-llm 0.6.0 → 0.8.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/config/totem.features.json +25 -9
- package/lib/launcher.js +45 -1
- package/package.json +4 -1
- package/server/endpoints/scheduledJobs.js +50 -0
- package/server/jobs/helpers/scheduled-job-helper.js +7 -0
- package/server/jobs/run-scheduled-job.js +8 -0
- package/server/models/scheduledJobRun.js +125 -0
- package/server/models/workspace.js +1 -1
- package/server/public/assets/{404-b9e84316.js → 404-2ab68306.js} +1 -1
- package/server/public/assets/{RunDetailPage-f74368e1.js → RunDetailPage-1f31e7a9.js} +1 -1
- package/server/public/assets/RunHistoryPage-ad807d5e.js +1 -0
- package/server/public/assets/{Trans-308f36d6.js → Trans-11790b69.js} +1 -1
- package/server/public/assets/{cron-dfd47d9d.js → cron-db080d69.js} +1 -1
- package/server/public/assets/{files-40998f84.js → files-552bd51c.js} +1 -1
- package/server/public/assets/{index-04b8b272.js → index-01f93883.js} +1 -1
- package/server/public/assets/index-0685ed43.js +1 -0
- package/server/public/assets/index-0b8978d7.js +14 -0
- package/server/public/assets/{index-f696a7cf.js → index-0d8d31dd.js} +1 -1
- package/server/public/assets/{index-34fe9c27.js → index-1167508a.js} +1 -1
- package/server/public/assets/{index-1ee26989.js → index-2757c3d3.js} +2 -2
- package/server/public/assets/{index-387c6117.js → index-2fa21e70.js} +2 -2
- package/server/public/assets/{index-83825216.js → index-437d374f.js} +1 -1
- package/server/public/assets/index-45c8b23a.js +1 -0
- package/server/public/assets/{index-202992ed.js → index-47baac02.js} +1 -1
- package/server/public/assets/{index-2a122ffc.js → index-4b51f44b.js} +1 -1
- package/server/public/assets/{index-620c8910.js → index-4e6c074d.js} +1 -1
- package/server/public/assets/{index-5f918cec.js → index-695fae54.js} +2 -2
- package/server/public/assets/{index-0e2cd529.js → index-6c12b8d5.js} +1 -1
- package/server/public/assets/{index-895c8c16.js → index-6efd2cba.js} +1 -1
- package/server/public/assets/index-6f49fa27.js +3 -0
- package/server/public/assets/{index-aca9b702.js → index-70a76269.js} +1 -1
- package/server/public/assets/{index-823d8660.js → index-810cee6e.js} +1 -1
- package/server/public/assets/{index-826aa41f.js → index-823a5b30.js} +45 -45
- package/server/public/assets/{index-874c0495.js → index-8a7d60cd.js} +1 -1
- package/server/public/assets/{index-41afab73.js → index-8ad07086.js} +1 -1
- package/server/public/assets/{index-b31c3faf.js → index-8dc64a9c.js} +1 -1
- package/server/public/assets/{index-305b79a5.js → index-9c75f06a.js} +1 -1
- package/server/public/assets/{index-a14b4fe3.js → index-a307a2aa.js} +1 -1
- package/server/public/assets/{index-6615fb87.js → index-a436152f.js} +1 -1
- package/server/public/assets/{index-4aa70062.js → index-a437b605.js} +1 -1
- package/server/public/assets/{index-69339b2c.js → index-a855dae6.js} +1 -1
- package/server/public/assets/{index-ffb73080.js → index-a915d236.js} +1 -1
- package/server/public/assets/{index-72879f52.js → index-b89fb953.js} +1 -1
- package/server/public/assets/{index-449280b3.js → index-b9dfd5c2.js} +1 -1
- package/server/public/assets/{index-70110b81.js → index-bc130f9a.js} +1 -1
- package/server/public/assets/{index-28476ae3.js → index-be5cae1a.js} +1 -1
- package/server/public/assets/{index-fc994fe1.js → index-cffe8740.js} +1 -1
- package/server/public/assets/{index-c712996e.js → index-d0dfd05c.js} +1 -1
- package/server/public/assets/{index-2317e7bf.js → index-d859b1c6.js} +1 -1
- package/server/public/assets/{index-988da2b0.js → index-d920d4e6.js} +1 -1
- package/server/public/assets/index-dfb62c39.js +1 -0
- package/server/public/assets/index-e4f41c65.js +1 -0
- package/server/public/assets/{index-36acf56a.js → index-e7e7c547.js} +1 -1
- package/server/public/assets/index-f1520ab9.js +18 -0
- package/server/public/assets/{index-a8fe483a.js → index-f41f305a.js} +1 -1
- package/server/public/assets/{main-34958ff6.js → main-115ace18.js} +1 -1
- package/server/public/assets/{mcpServers-9495fe60.js → mcpServers-d6808fa0.js} +1 -1
- package/server/public/assets/{purify-17c89583.js → purify-bb71c5e8.js} +1 -1
- package/server/public/assets/{react-beautiful-dnd.esm-149a7a55.js → react-beautiful-dnd.esm-51607d6e.js} +1 -1
- package/server/public/assets/{truncate-dd7b0c29.js → truncate-e484143c.js} +1 -1
- package/server/public/assets/usePolling-3b229af5.js +1 -0
- package/server/public/index.css +1 -1
- package/server/public/index.js +54 -54
- package/server/public/logo192.png +0 -0
- package/server/public/logo512.png +0 -0
- package/server/public/manifest.json +14 -1
- package/server/public/service-workers/push-notifications.js +38 -4
- package/server/utils/PushNotifications/index.js +26 -1
- package/server/public/assets/RunHistoryPage-432358df.js +0 -1
- package/server/public/assets/index-166e238c.js +0 -1
- package/server/public/assets/index-5911cdab.js +0 -1
- package/server/public/assets/index-5dd1b6d2.js +0 -3
- package/server/public/assets/index-7a4311ac.js +0 -1
- package/server/public/assets/index-93558484.js +0 -18
- package/server/public/assets/index-ed14fe75.js +0 -14
- package/server/public/assets/index-eed6725c.js +0 -1
- package/server/public/assets/usePolling-417bb099.js +0 -1
|
@@ -75,6 +75,14 @@
|
|
|
75
75
|
"appIntegrations": {
|
|
76
76
|
"label": "3rd Party App Integrations",
|
|
77
77
|
"tier": "L2"
|
|
78
|
+
},
|
|
79
|
+
"agentFlows": {
|
|
80
|
+
"label": "Agent Flows",
|
|
81
|
+
"tier": "L2"
|
|
82
|
+
},
|
|
83
|
+
"mcpServers": {
|
|
84
|
+
"label": "MCP Servers",
|
|
85
|
+
"tier": "L2"
|
|
78
86
|
}
|
|
79
87
|
},
|
|
80
88
|
"PROFILES": {
|
|
@@ -88,16 +96,18 @@
|
|
|
88
96
|
"multiUser": false,
|
|
89
97
|
"browserExtension": false,
|
|
90
98
|
"chatEmbed": false,
|
|
91
|
-
"scheduledJobs":
|
|
99
|
+
"scheduledJobs": true,
|
|
92
100
|
"developerApi": false,
|
|
93
101
|
"mobile": false,
|
|
94
|
-
"agentMode":
|
|
102
|
+
"agentMode": true,
|
|
95
103
|
"memories": false,
|
|
96
|
-
"vectorDB":
|
|
97
|
-
"embedder":
|
|
104
|
+
"vectorDB": true,
|
|
105
|
+
"embedder": true,
|
|
98
106
|
"textSplitter": false,
|
|
99
|
-
"transcription":
|
|
100
|
-
"appIntegrations": false
|
|
107
|
+
"transcription": true,
|
|
108
|
+
"appIntegrations": false,
|
|
109
|
+
"agentFlows": false,
|
|
110
|
+
"mcpServers": false
|
|
101
111
|
},
|
|
102
112
|
"L1": {
|
|
103
113
|
"communityHub": false,
|
|
@@ -118,7 +128,9 @@
|
|
|
118
128
|
"embedder": false,
|
|
119
129
|
"textSplitter": false,
|
|
120
130
|
"transcription": false,
|
|
121
|
-
"appIntegrations": false
|
|
131
|
+
"appIntegrations": false,
|
|
132
|
+
"agentFlows": false,
|
|
133
|
+
"mcpServers": false
|
|
122
134
|
},
|
|
123
135
|
"L2": {
|
|
124
136
|
"communityHub": false,
|
|
@@ -139,7 +151,9 @@
|
|
|
139
151
|
"embedder": false,
|
|
140
152
|
"textSplitter": false,
|
|
141
153
|
"transcription": false,
|
|
142
|
-
"appIntegrations": false
|
|
154
|
+
"appIntegrations": false,
|
|
155
|
+
"agentFlows": false,
|
|
156
|
+
"mcpServers": false
|
|
143
157
|
},
|
|
144
158
|
"source": {
|
|
145
159
|
"communityHub": true,
|
|
@@ -160,7 +174,9 @@
|
|
|
160
174
|
"embedder": false,
|
|
161
175
|
"textSplitter": false,
|
|
162
176
|
"transcription": false,
|
|
163
|
-
"appIntegrations": false
|
|
177
|
+
"appIntegrations": false,
|
|
178
|
+
"agentFlows": false,
|
|
179
|
+
"mcpServers": false
|
|
164
180
|
}
|
|
165
181
|
}
|
|
166
182
|
}
|
package/lib/launcher.js
CHANGED
|
@@ -16,6 +16,9 @@ import {
|
|
|
16
16
|
error,
|
|
17
17
|
divider,
|
|
18
18
|
} from "./formatter.js";
|
|
19
|
+
import os from "os";
|
|
20
|
+
import qrcode from "qrcode-terminal"
|
|
21
|
+
|
|
19
22
|
|
|
20
23
|
/**
|
|
21
24
|
* Create a simple progress bar for terminal output.
|
|
@@ -68,6 +71,23 @@ function spawnService(nodeExe, cwd, env, label, logFile) {
|
|
|
68
71
|
return child;
|
|
69
72
|
}
|
|
70
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Get the local network IPv4 address.
|
|
76
|
+
* @returns {string|null} Local IP address or null if not found
|
|
77
|
+
*/
|
|
78
|
+
function getLocalIP() {
|
|
79
|
+
const interfaces = os.networkInterfaces();
|
|
80
|
+
for (const name of Object.keys(interfaces)) {
|
|
81
|
+
for (const iface of interfaces[name]) {
|
|
82
|
+
// Skip internal (loopback) and non-IPv4 addresses
|
|
83
|
+
if (iface.family === "IPv4" && !iface.internal) {
|
|
84
|
+
return iface.address;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
|
|
71
91
|
/**
|
|
72
92
|
* Launch the server (and optionally the collector), wire up graceful shutdown,
|
|
73
93
|
* and keep the process alive until the user presses Ctrl+C.
|
|
@@ -125,14 +145,38 @@ export async function launch({ packageRoot, noCollector = false, port } = {}) {
|
|
|
125
145
|
}
|
|
126
146
|
}, 300);
|
|
127
147
|
|
|
148
|
+
// Display UI access information
|
|
149
|
+
process.stdout.write(
|
|
150
|
+
highlightBox(
|
|
151
|
+
`Open UI in browser:\n${urlStyle(`http://localhost:${serverPort}/`)}`,
|
|
152
|
+
"brightGreen"
|
|
153
|
+
)
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
// Get local network details
|
|
157
|
+
const localIP = getLocalIP();
|
|
158
|
+
const networkUrl = localIP ? `http://${localIP}:${serverPort}/` : null;
|
|
159
|
+
const localUrlLine = networkUrl ? `\nNetwork: ${urlStyle(networkUrl)}` : "";
|
|
160
|
+
|
|
161
|
+
// Generate QR code for mobile devices if network URL is available
|
|
162
|
+
let qrCodeBox = "";
|
|
163
|
+
if (networkUrl) {
|
|
164
|
+
qrcode.generate(networkUrl, { small: true }, (qrcodeStr) => {
|
|
165
|
+
// Add a small header and spacing around the generated QR code string
|
|
166
|
+
qrCodeBox = `\n\n${info("Scan to open on mobile:")}\n${qrcodeStr}`;
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
128
170
|
// Display UI access information
|
|
129
171
|
process.stdout.write(
|
|
130
172
|
highlightBox(
|
|
131
|
-
`Open UI in browser:\
|
|
173
|
+
`Open UI in browser:\nLocal: ${urlStyle(`http://localhost:${serverPort}/`)}${localUrlLine}${qrCodeBox}`,
|
|
132
174
|
"brightGreen"
|
|
133
175
|
)
|
|
134
176
|
);
|
|
135
177
|
|
|
178
|
+
|
|
179
|
+
|
|
136
180
|
// Display logs information
|
|
137
181
|
process.stdout.write(
|
|
138
182
|
section("Configuration", [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "totem-llm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Totem LLM – Your Private AI. Run a self-hosted AI assistant locally on Linux, macOS, or Windows.",
|
|
5
5
|
"main": "bin/totem-llm.js",
|
|
6
6
|
"type": "module",
|
|
@@ -63,5 +63,8 @@
|
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"concurrently": "^9.1.2",
|
|
65
65
|
"jest": "^29.7.0"
|
|
66
|
+
},
|
|
67
|
+
"dependencies": {
|
|
68
|
+
"qrcode-terminal": "^0.12.0"
|
|
66
69
|
}
|
|
67
70
|
}
|
|
@@ -13,6 +13,56 @@ const backgroundService = new BackgroundService();
|
|
|
13
13
|
function scheduledJobEndpoints(app) {
|
|
14
14
|
if (!app) return;
|
|
15
15
|
|
|
16
|
+
// Count unread (terminal, not-yet-opened) runs — used by the sidebar badge
|
|
17
|
+
app.get(
|
|
18
|
+
"/scheduled-jobs/unread-count",
|
|
19
|
+
[validatedRequest, isSingleUserMode],
|
|
20
|
+
async (_request, response) => {
|
|
21
|
+
try {
|
|
22
|
+
const count = await ScheduledJobRun.countUnread();
|
|
23
|
+
return response.status(200).json({ count });
|
|
24
|
+
} catch (e) {
|
|
25
|
+
console.error(e.message, e);
|
|
26
|
+
return response.status(200).json({ count: 0 });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
// Map of workspace-slug → unread count for each job workspace — used by the
|
|
32
|
+
// workspace list sidebar to show per-workspace notification dots.
|
|
33
|
+
app.get(
|
|
34
|
+
"/scheduled-jobs/unread-workspaces",
|
|
35
|
+
[validatedRequest, isSingleUserMode],
|
|
36
|
+
async (_request, response) => {
|
|
37
|
+
try {
|
|
38
|
+
const unread = await ScheduledJobRun.unreadByJobWorkspace();
|
|
39
|
+
return response.status(200).json({ unread });
|
|
40
|
+
} catch (e) {
|
|
41
|
+
console.error(e.message, e);
|
|
42
|
+
return response.status(200).json({ unread: {} });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
// Mark all unread runs for a job as read — called when the user opens the
|
|
48
|
+
// job's dedicated workspace chat (the default thread view).
|
|
49
|
+
app.post(
|
|
50
|
+
"/scheduled-jobs/jobs/:jobId/mark-read-all",
|
|
51
|
+
[validatedRequest, isSingleUserMode],
|
|
52
|
+
async (request, response) => {
|
|
53
|
+
try {
|
|
54
|
+
const jobId = Number(request.params.jobId);
|
|
55
|
+
if (!jobId || isNaN(jobId))
|
|
56
|
+
return response.status(400).json({ error: "Invalid jobId" });
|
|
57
|
+
await ScheduledJobRun.markAllReadForJob(jobId);
|
|
58
|
+
return response.status(200).json({ success: true });
|
|
59
|
+
} catch (e) {
|
|
60
|
+
console.error(e.message, e);
|
|
61
|
+
return response.status(200).json({ success: false });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
|
|
16
66
|
// List available tools for job configuration
|
|
17
67
|
app.get(
|
|
18
68
|
"/scheduled-jobs/available-tools",
|
|
@@ -83,17 +83,24 @@ async function sendWebPushNotification(job, runId, textResponse, logFn) {
|
|
|
83
83
|
const {
|
|
84
84
|
pushNotificationService,
|
|
85
85
|
} = require("../../utils/PushNotifications/index.js");
|
|
86
|
+
const { ScheduledJobRun } = require("../../models/scheduledJobRun.js");
|
|
87
|
+
|
|
86
88
|
await pushNotificationService.loadSubscriptions();
|
|
87
89
|
|
|
88
90
|
// Strip thinking tags from the text response and then truncate to 100 characters
|
|
89
91
|
// if the response is longer than 100 characters.
|
|
90
92
|
let notificationBody = stripThinkingFromText(textResponse);
|
|
91
93
|
notificationBody = truncateNotificationBody(notificationBody);
|
|
94
|
+
|
|
95
|
+
// Total unread count drives the app-icon badge on PWA/desktop installs.
|
|
96
|
+
const unreadCount = await ScheduledJobRun.countUnread();
|
|
97
|
+
|
|
92
98
|
await pushNotificationService.sendNotification({
|
|
93
99
|
to: "primary",
|
|
94
100
|
payload: {
|
|
95
101
|
title: `${job.name} completed`,
|
|
96
102
|
body: notificationBody,
|
|
103
|
+
badge: unreadCount,
|
|
97
104
|
data: {
|
|
98
105
|
onClickUrl: `/settings/scheduled-jobs/${job.id}/runs/${runId}`,
|
|
99
106
|
},
|
|
@@ -126,6 +126,14 @@ process.on("message", async (payload) => {
|
|
|
126
126
|
},
|
|
127
127
|
});
|
|
128
128
|
log(`Scheduled job "${job.name}" completed in ${duration}ms)`);
|
|
129
|
+
|
|
130
|
+
// Auto-save the prompt + response to the job's dedicated workspace
|
|
131
|
+
await ScheduledJobRun.autoSaveToJobWorkspace(job, {
|
|
132
|
+
text: state.textResponse,
|
|
133
|
+
sources: [],
|
|
134
|
+
outputs,
|
|
135
|
+
});
|
|
136
|
+
|
|
129
137
|
await sendWebPushNotification(job, runId, state.textResponse, log);
|
|
130
138
|
} catch (error) {
|
|
131
139
|
if (error.message === "SCHEDULED_JOB_TIMEOUT") {
|
|
@@ -251,6 +251,29 @@ const ScheduledJobRun = {
|
|
|
251
251
|
}
|
|
252
252
|
},
|
|
253
253
|
|
|
254
|
+
/**
|
|
255
|
+
* Mark all unread terminal runs for a given job as read.
|
|
256
|
+
* Called when the user opens the job's auto-created workspace chat.
|
|
257
|
+
* @param {number} jobId
|
|
258
|
+
* @returns {Promise<number>} Number of rows updated
|
|
259
|
+
*/
|
|
260
|
+
markAllReadForJob: async function (jobId) {
|
|
261
|
+
try {
|
|
262
|
+
const result = await prisma.scheduled_job_runs.updateMany({
|
|
263
|
+
where: {
|
|
264
|
+
jobId: Number(jobId),
|
|
265
|
+
readAt: null,
|
|
266
|
+
status: { in: ["completed", "failed", "timed_out"] },
|
|
267
|
+
},
|
|
268
|
+
data: { readAt: new Date() },
|
|
269
|
+
});
|
|
270
|
+
return result.count;
|
|
271
|
+
} catch (error) {
|
|
272
|
+
console.error("Failed to mark all runs as read for job:", error.message);
|
|
273
|
+
return 0;
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
|
|
254
277
|
markRead: async function (id) {
|
|
255
278
|
try {
|
|
256
279
|
await prisma.scheduled_job_runs.update({
|
|
@@ -264,6 +287,54 @@ const ScheduledJobRun = {
|
|
|
264
287
|
}
|
|
265
288
|
},
|
|
266
289
|
|
|
290
|
+
/**
|
|
291
|
+
* Count terminal runs (completed, failed, timed_out) that have not been
|
|
292
|
+
* read yet. Used by the sidebar badge and push notification badge count.
|
|
293
|
+
* @returns {Promise<number>}
|
|
294
|
+
*/
|
|
295
|
+
countUnread: async function () {
|
|
296
|
+
try {
|
|
297
|
+
return await prisma.scheduled_job_runs.count({
|
|
298
|
+
where: {
|
|
299
|
+
readAt: null,
|
|
300
|
+
status: { in: ["completed", "failed", "timed_out"] },
|
|
301
|
+
},
|
|
302
|
+
});
|
|
303
|
+
} catch (error) {
|
|
304
|
+
console.error("Failed to count unread scheduled job runs:", error.message);
|
|
305
|
+
return 0;
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Return a map of workspace slug → unread run count for every scheduled job
|
|
311
|
+
* that has at least one unread terminal run. The workspace slug for a job is
|
|
312
|
+
* the deterministic `scheduled-job-<jobId>` value used by autoSaveToJobWorkspace.
|
|
313
|
+
*
|
|
314
|
+
* @returns {Promise<Record<string, number>>} e.g. { "scheduled-job-3": 2 }
|
|
315
|
+
*/
|
|
316
|
+
unreadByJobWorkspace: async function () {
|
|
317
|
+
try {
|
|
318
|
+
const rows = await prisma.scheduled_job_runs.groupBy({
|
|
319
|
+
by: ["jobId"],
|
|
320
|
+
where: {
|
|
321
|
+
readAt: null,
|
|
322
|
+
status: { in: ["completed", "failed", "timed_out"] },
|
|
323
|
+
},
|
|
324
|
+
_count: { id: true },
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
const result = {};
|
|
328
|
+
for (const row of rows) {
|
|
329
|
+
result[`scheduled-job-${row.jobId}`] = row._count.id;
|
|
330
|
+
}
|
|
331
|
+
return result;
|
|
332
|
+
} catch (error) {
|
|
333
|
+
console.error("Failed to get unread runs by workspace:", error.message);
|
|
334
|
+
return {};
|
|
335
|
+
}
|
|
336
|
+
},
|
|
337
|
+
|
|
267
338
|
delete: async function (clause = {}) {
|
|
268
339
|
try {
|
|
269
340
|
await prisma.scheduled_job_runs.deleteMany({ where: clause });
|
|
@@ -357,6 +428,60 @@ const ScheduledJobRun = {
|
|
|
357
428
|
};
|
|
358
429
|
}
|
|
359
430
|
},
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Automatically save the prompt and response from a completed run to the
|
|
434
|
+
* job's dedicated workspace (creating it on first run) using the workspace's
|
|
435
|
+
* default thread (threadId = null) so every run appends to the same view.
|
|
436
|
+
*
|
|
437
|
+
* Workspace slug is deterministic: `scheduled-job-<jobId>` so the same
|
|
438
|
+
* workspace is reused across all runs of a job.
|
|
439
|
+
*
|
|
440
|
+
* @param {object} job - scheduled_jobs DB record (must have id, name, prompt)
|
|
441
|
+
* @param {object} result - run result object (text, sources, outputs, etc.)
|
|
442
|
+
* @returns {Promise<void>}
|
|
443
|
+
*/
|
|
444
|
+
autoSaveToJobWorkspace: async function (job, result = {}) {
|
|
445
|
+
try {
|
|
446
|
+
const { Workspace } = require("./workspace");
|
|
447
|
+
const { WorkspaceChats } = require("./workspaceChats");
|
|
448
|
+
|
|
449
|
+
const slug = `scheduled-job-${job.id}`;
|
|
450
|
+
|
|
451
|
+
// Get or create the per-job workspace. Workspace.upsert goes directly
|
|
452
|
+
// to Prisma so we can set `slug` without it being filtered by writable[].
|
|
453
|
+
const { workspace, error: workspaceError } = await Workspace.upsert(
|
|
454
|
+
{ slug },
|
|
455
|
+
{ name: job.name, slug, chatMode: "automatic" },
|
|
456
|
+
{} // no updates on subsequent runs
|
|
457
|
+
);
|
|
458
|
+
if (workspaceError || !workspace) {
|
|
459
|
+
console.error(
|
|
460
|
+
`[ScheduledJobRun] Failed to upsert workspace for job ${job.id}: ${workspaceError}`
|
|
461
|
+
);
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// Write the prompt + response to the default thread (threadId = null)
|
|
466
|
+
await WorkspaceChats.new({
|
|
467
|
+
workspaceId: workspace.id,
|
|
468
|
+
prompt: job.prompt,
|
|
469
|
+
response: {
|
|
470
|
+
text: result.text || "No response was generated.",
|
|
471
|
+
sources: result.sources || [],
|
|
472
|
+
outputs: result.outputs || [],
|
|
473
|
+
type: "chat",
|
|
474
|
+
},
|
|
475
|
+
threadId: null,
|
|
476
|
+
include: true,
|
|
477
|
+
});
|
|
478
|
+
} catch (error) {
|
|
479
|
+
// Non-fatal: log but do not surface to the caller
|
|
480
|
+
console.error(
|
|
481
|
+
`[ScheduledJobRun] autoSaveToJobWorkspace failed for job ${job.id}: ${error.message}`
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
},
|
|
360
485
|
};
|
|
361
486
|
|
|
362
487
|
module.exports = { ScheduledJobRun };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,K as t,X as s,
|
|
1
|
+
import{j as e,K as t,X as s,a5 as a}from"../index.js";function l(){return e.jsxs("div",{className:"flex flex-col items-center justify-center min-h-screen bg-theme-bg-primary text-theme-text-primary gap-4 p-4 md:p-8 w-full",children:[e.jsx(t,{className:"w-16 h-16 text-theme-text-secondary"}),e.jsx("h1",{className:"text-xl md:text-2xl font-bold text-center",children:"404 - Page Not Found"}),e.jsx("p",{className:"text-theme-text-secondary text-center px-4",children:"The page you're looking for doesn't exist or has been moved."}),e.jsx("div",{className:"flex flex-col md:flex-row gap-3 md:gap-4 mt-4 w-full md:w-auto",children:e.jsxs(s,{to:"/",className:"flex items-center justify-center gap-2 px-4 py-2 bg-theme-bg-secondary text-theme-text-primary rounded-lg hover:bg-theme-sidebar-item-hover transition-all duration-300 w-full md:w-auto",children:[e.jsx(a,{className:"w-4 h-4"}),"Go Home"]})})]})}export{l as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as o,j as t,ac as G,aF as $,aN as X,V as C,u as y,aL as I,s as q,a6 as K,a5 as U,bL as V,c0 as B,c as j,l as W,b as Y,p as T,a1 as Q,i as Z,a_ as ee,bH as te,au as D}from"../index.js";import{I as se}from"./Brain-24e386d5.js";import{w as le}from"./ChatText-35275002.js";import{I as ne}from"./File-b92df2f3.js";import{R as ae}from"./Stop-4b47ae05.js";import{S as f,u as re}from"./usePolling-417bb099.js";import{c as ie,S as oe,T as J,a as ce,b as de,r as _}from"./files-40998f84.js";import{C as ue}from"./Copy-d323e545.js";import{H as xe,D as S}from"./purify-17c89583.js";import{t as L}from"./truncate-dd7b0c29.js";import{h as E}from"./moment-49fc1b76.js";/* empty css */function w({title:e,icon:s,children:l,defaultOpen:n=!1,copyableContent:a=null}){const[i,r]=o.useState(n);return t.jsxs("div",{className:"border border-zinc-700 light:border-slate-400 rounded-lg overflow-hidden",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("button",{type:"button",onClick:()=>r(!i),className:"border-none flex-1 h-12 flex items-center gap-2 px-[18px] hover:bg-white/5 light:hover:bg-slate-100 transition-colors text-left",children:[i?t.jsx(G,{className:"h-4 w-4 text-zinc-50 light:text-slate-950"}):t.jsx($,{className:"h-4 w-4 text-zinc-50 light:text-slate-950"}),t.jsx(s,{className:"h-4 w-4 text-zinc-50 light:text-slate-950"}),t.jsx("span",{className:"text-sm font-medium text-zinc-50 light:text-slate-950",children:e})]}),a&&t.jsx(he,{content:a})]}),i&&t.jsx("div",{className:"px-[18px] py-3 border-t border-zinc-700 light:border-slate-400",children:l})]})}function he({content:e}){const[s,l]=o.useState(!1),n=async()=>{await ie(e),l(!0),setTimeout(()=>l(!1),2e3)};return t.jsx("button",{type:"button",onClick:n,disabled:s,className:"h-12 px-4 flex items-center hover:bg-white/5 light:hover:bg-slate-100 transition-colors",children:s?t.jsx(X,{size:20,className:"text-green-500"}):t.jsx(ue,{size:20,className:"text-zinc-50 light:text-slate-950"})})}const F=5e3;function H(e){return e?"github":"github-dark"}function O(e){const s=typeof e=="string"?q(e,e):e;if(typeof s!="object"||s===null)return null;const l=JSON.stringify(s,null,2),n=L(l,F),a=xe.highlight(n,{language:"json"}).value;return{__html:S.sanitize(a)}}function me({toolCall:e}){const[s,l]=o.useState(!1);return t.jsxs("div",{className:"border border-white/5 rounded-lg p-3 bg-theme-bg-primary/30",children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(C,{className:"h-3.5 w-3.5 text-blue-400"}),t.jsx("span",{className:"text-sm font-medium text-theme-text-primary",children:e.toolName})]}),t.jsx(ge,{toolCall:e})]}),t.jsx(pe,{toolCall:e}),t.jsx(be,{toolCall:e,showResult:s,setShowResult:l})]})}function ge({toolCall:e}){return e.timestamp?t.jsx("span",{className:"text-xs text-theme-text-secondary",children:E(e.timestamp).format("LTS")}):null}function pe({toolCall:e}){const{t:s}=y(),{isLight:l}=I();if(!e.arguments)return null;const n=O(e.arguments);return t.jsxs("div",{className:"mb-2",children:[t.jsx("span",{className:"text-xs text-theme-text-secondary",children:s("scheduledJobs.toolCall.arguments")}),n?t.jsx("pre",{className:`text-xs rounded-lg p-2 mt-1 overflow-x-auto white-scrollbar tool-call-scrollbar hljs ${H(l)}`,dangerouslySetInnerHTML:n}):t.jsx("pre",{className:"text-xs text-theme-text-primary bg-theme-bg-primary/50 rounded p-2 mt-1 overflow-x-auto white-scrollbar tool-call-scrollbar",children:typeof e.arguments=="string"?e.arguments:JSON.stringify(e.arguments,null,2)})]})}function be({toolCall:e,showResult:s,setShowResult:l}){const{t:n}=y(),{isLight:a}=I();if(!e.result)return null;const i=typeof e.result=="string"?e.result:JSON.stringify(e.result,null,2),r=L(i,F),c=O(i);return i?t.jsxs("div",{children:[t.jsx("button",{type:"button",onClick:()=>l(!s),className:"border-none text-xs text-blue-400 hover:text-blue-300 transition-colors",children:n(s?"scheduledJobs.toolCall.hideResult":"scheduledJobs.toolCall.showResult")}),s&&(c?t.jsx("pre",{className:`text-xs rounded-lg p-2 mt-1 overflow-x-auto max-h-64 overflow-y-auto whitespace-pre-wrap white-scrollbar tool-call-scrollbar hljs ${H(a)}`,dangerouslySetInnerHTML:c}):t.jsx("pre",{className:"text-xs text-theme-text-primary bg-theme-bg-primary/50 rounded p-2 mt-1 overflow-x-auto max-h-64 overflow-y-auto whitespace-pre-wrap white-scrollbar tool-call-scrollbar",children:r}))]}):null}const R={pptx:{badge:"PPT",bg:"bg-orange-100",text:"text-orange-800",label:e=>e("scheduledJobs.file.types.powerpoint")},ppt:{badge:"PPT",bg:"bg-orange-100",text:"text-orange-800",label:e=>e("scheduledJobs.file.types.powerpoint")},pdf:{badge:"PDF",bg:"bg-red-100",text:"text-red-800",label:e=>e("scheduledJobs.file.types.pdf")},doc:{badge:"DOC",bg:"bg-blue-100",text:"text-blue-800",label:e=>e("scheduledJobs.file.types.word")},docx:{badge:"DOC",bg:"bg-blue-100",text:"text-blue-800",label:e=>e("scheduledJobs.file.types.word")},xls:{badge:"XLS",bg:"bg-green-100",text:"text-green-800",label:e=>e("scheduledJobs.file.types.spreadsheet")},xlsx:{badge:"XLS",bg:"bg-green-100",text:"text-green-800",label:e=>e("scheduledJobs.file.types.spreadsheet")},csv:{badge:"CSV",bg:"bg-green-100",text:"text-green-800",label:e=>e("scheduledJobs.file.types.spreadsheet")},default:{badge:"FILE",bg:"bg-zinc-200",text:"text-zinc-800",label:e=>e("scheduledJobs.file.types.generic")}};function fe(e,s){var a,i;const l=((i=(a=e==null?void 0:e.split("."))==null?void 0:a.pop())==null?void 0:i.toLowerCase())??"txt",n=R[l]||R.default;return{...n,type:n.label(s)}}function je({file:e}){const{t:s}=y(),[l,n]=o.useState(!1),{badge:a,bg:i,text:r,type:c}=fe(e.filename,s),u=async()=>{if(!(l||!e.storageFilename)){n(!0);try{const h=await oe.download(e.storageFilename);if(!h)throw new Error("Failed to download file");const{saveAs:m}=await B(()=>import("../index.js").then(g=>g.F),["index.js","index.css"]);m(h,e.filename||e.storageFilename)}catch{j(s("scheduledJobs.file.downloadFailed"),"error")}finally{n(!1)}}};return t.jsxs("div",{className:"flex items-center justify-between bg-zinc-800 light:bg-slate-100 rounded-lg p-3",children:[t.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[t.jsx("div",{className:`${i} ${r} rounded-lg flex items-center justify-center shrink-0 h-10 w-10 text-xs font-semibold`,children:a}),t.jsxs("div",{className:"flex flex-col min-w-0",children:[t.jsx("p",{className:"text-sm text-white light:text-slate-950 truncate",children:e.filename||s("scheduledJobs.file.unknown")}),t.jsxs("p",{className:"text-sm text-zinc-400 light:text-slate-600",children:[K(e.fileSize,!0,1),e.fileSize&&c?" · ":"",c]})]})]}),t.jsx("button",{type:"button",onClick:u,disabled:l,title:s("scheduledJobs.file.download"),"aria-label":s("scheduledJobs.file.download"),className:"border-none text-zinc-400 light:text-slate-600 hover:text-zinc-50 light:hover:text-slate-950 transition-colors shrink-0 ml-4 disabled:opacity-50",children:l?t.jsx(U,{size:16,weight:"bold",className:"animate-spin"}):t.jsx(V,{size:16,weight:"bold"})})]})}function Me(){const{t:e}=y(),{id:s,runId:l}=W(),n=Y(),[a,i]=o.useState(!0),[r,c]=o.useState(null),[u,h]=o.useState(null),[m,g]=o.useState(!1),[N,p]=o.useState(!1);o.useEffect(()=>{v()},[l]);const v=async()=>{const d=await f.getRun(l);c(d.run),h(d.job),i(!1),d.run&&!d.run.readAt&&f.markRunRead(l)},P=(r==null?void 0:r.status)==="running"||(r==null?void 0:r.status)==="queued";re(v,3e3,P);const M=async()=>{g(!0);const{workspaceSlug:d,threadSlug:b,error:k}=await f.continueInThread(l);if(k||!d||!b){j(k||e("scheduledJobs.runDetail.threadFailed"),"error"),g(!1);return}n(T.workspace.thread(d,b))},A=async()=>{p(!0);const{success:d,error:b}=await f.killRun(l);if(p(!1),!d){j(b||e("scheduledJobs.toast.killFailed"),"error");return}j(e("scheduledJobs.toast.killed"),"success"),v()};if(a)return t.jsx(z,{children:t.jsx("p",{className:"text-zinc-400 light:text-slate-600 text-sm",children:e("scheduledJobs.runDetail.loading")})});if(!r)return t.jsx(z,{children:t.jsx("p",{className:"text-zinc-400 light:text-slate-600 text-sm",children:e("scheduledJobs.runDetail.notFound")})});const x=r.result||{};return t.jsxs(z,{children:[t.jsx(ye,{t:e,job:u,run:r,result:x,continuing:m,killing:N,onBack:()=>n(T.settings.scheduledJobRuns(s)),onContinueInThread:M,onKillRun:A}),t.jsxs("div",{className:"mt-6 space-y-4",children:[t.jsx(we,{t:e,prompt:u==null?void 0:u.prompt}),t.jsx(Ne,{t:e,error:r==null?void 0:r.error}),t.jsx(ve,{t:e,result:x}),t.jsx(Je,{t:e,result:x}),t.jsx(ze,{t:e,result:x}),t.jsx(Se,{t:e,result:x}),t.jsx(ke,{t:e,metrics:x==null?void 0:x.metrics})]})]})}function z({children:e}){return t.jsxs("div",{className:"w-screen h-screen overflow-hidden bg-theme-bg-container flex",children:[t.jsx(Q,{}),t.jsx("div",{style:{height:Z?"100%":"calc(100% - 32px)"},className:"relative md:ml-[2px] md:mr-[16px] md:my-[16px] md:rounded-[16px] bg-theme-bg-secondary w-full h-full overflow-y-scroll p-4 md:p-0",children:t.jsx("div",{className:"flex flex-col w-full px-1 md:pl-6 md:pr-[50px] md:py-6 py-16",children:e})})]})}function ye({t:e,job:s,run:l,result:n,continuing:a,killing:i,onBack:r,onContinueInThread:c,onKillRun:u}){function h(){return{completed:{text:e("scheduledJobs.status.completed"),style:"text-green-400 light:text-green-600"},failed:{text:e("scheduledJobs.status.failed"),style:"text-red-400 light:text-red-600"},timed_out:{text:e("scheduledJobs.status.timed_out"),style:"text-orange-400 light:text-orange-600"},running:{text:e("scheduledJobs.status.running"),style:"text-yellow-400 light:text-yellow-600"},queued:{text:e("scheduledJobs.status.queued"),style:"text-blue-400 light:text-blue-600"},default:{text:"—",style:"text-zinc-400 light:text-slate-600"}}}const m=h(),{text:g,style:N}=m[l.status]||m.default,p=["running","queued"].includes(l.status);return t.jsxs("div",{className:"w-full flex items-end justify-between gap-x-4 pb-6 border-white/10 light:border-zinc-300 border-b-2",children:[t.jsxs("div",{className:"flex flex-col gap-y-2",children:[t.jsxs("button",{type:"button",onClick:r,className:"border-none flex items-center gap-2 text-zinc-400 light:text-slate-600 hover:text-zinc-50 light:hover:text-slate-950 text-sm transition-colors w-fit",children:[t.jsx(ee,{className:"h-4 w-4"}),e("scheduledJobs.runDetail.back")]}),t.jsx("p",{className:"text-lg leading-7 font-semibold text-zinc-50 light:text-slate-950",children:e("scheduledJobs.runDetail.runHeading",{name:(s==null?void 0:s.name)||e("scheduledJobs.runDetail.unknownJob"),id:l.id})}),t.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[t.jsx("span",{className:N,children:g}),t.jsx("span",{className:"text-zinc-400 light:text-slate-600",children:E(l.startedAt).format("LTS")}),n.duration&&t.jsx("span",{className:"text-zinc-400 light:text-slate-600",children:e("scheduledJobs.runDetail.duration",{value:te(n.duration/1e3)})})]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[p&&t.jsxs("button",{type:"button",onClick:u,disabled:i,title:e("scheduledJobs.runDetail.stopJob"),className:"border-none h-9 px-5 rounded-lg bg-red-500/20 text-red-400 light:bg-red-100 light:text-red-600 text-sm font-medium hover:bg-red-500/30 light:hover:bg-red-200 transition-colors disabled:opacity-50 shrink-0 flex items-center gap-2",children:[t.jsx(ae,{className:"h-4 w-4",weight:"bold"}),e(i?"scheduledJobs.runDetail.killing":"scheduledJobs.runDetail.stopJob")]}),l.status==="completed"&&t.jsx("button",{type:"button",onClick:c,disabled:a,className:"border-none h-9 px-5 rounded-lg bg-zinc-50 text-zinc-950 light:bg-slate-900 light:text-white text-sm font-medium hover:bg-zinc-200 light:hover:bg-slate-800 transition-colors disabled:opacity-50 shrink-0",children:e(a?"scheduledJobs.runDetail.creating":"scheduledJobs.runDetail.continueInThread")})]})]})}function we({t:e,prompt:s}){return t.jsxs("div",{className:"border border-zinc-700 light:border-slate-400 rounded-lg p-[18px]",children:[t.jsx("p",{className:"text-sm font-medium text-white light:text-slate-950 uppercase tracking-[1.4px] mb-1",children:e("scheduledJobs.runDetail.sections.prompt")}),t.jsx("p",{className:"text-sm text-zinc-400 light:text-slate-600 whitespace-pre-wrap",children:s||"—"})]})}function Ne({t:e,error:s}){return s?t.jsxs("div",{className:"border border-red-500/20 light:border-red-300 rounded-lg p-[18px] bg-red-500/5 light:bg-red-50",children:[t.jsx("p",{className:"text-sm font-medium text-red-400 light:text-red-600 uppercase tracking-[1.4px] mb-1",children:e("scheduledJobs.runDetail.sections.error")}),t.jsx("p",{className:"text-sm text-red-300 light:text-red-700",children:s})]}):null}function ve({t:e,result:s}){return!s.thoughts||s.thoughts.length===0?null:t.jsx(w,{title:e("scheduledJobs.runDetail.sections.thinking",{count:s.thoughts.length}),icon:se,children:t.jsx("div",{className:"space-y-2",children:s.thoughts.map((l,n)=>t.jsxs("div",{className:"flex items-start gap-2 text-sm text-theme-text-secondary",children:[t.jsxs("span",{className:"text-xs text-theme-text-secondary/50 mt-0.5 min-w-[20px]",children:[n+1,"."]}),t.jsx("span",{children:l})]},n))})})}function Je({t:e,result:s}){return!s.toolCalls||s.toolCalls.length===0?null:t.jsx(w,{title:e("scheduledJobs.runDetail.sections.toolCalls",{count:s.toolCalls.length}),icon:C,children:t.jsx("div",{className:"space-y-3",children:s.toolCalls.map((l,n)=>t.jsx(me,{toolCall:l},n))})})}function ze({t:e,result:s}){const l=s.outputs||[];return l.length===0?null:t.jsx(w,{title:e("scheduledJobs.runDetail.sections.files",{count:l.length}),icon:ne,defaultOpen:!0,children:t.jsx("div",{className:"space-y-2",children:l.map((n,a)=>t.jsx(je,{file:n.payload,type:n.type},a))})})}function Se({t:e,result:s}){var a;if(!s.text)return null;let l=null,n=s.text;return s.text.match(J)&&(l=(a=s.text.match(J))==null?void 0:a[0],l&&(l=l.replace(ce,"").replace(de,"").trim()),n=s.text.replace(J,"")),t.jsxs(w,{title:e("scheduledJobs.runDetail.sections.response"),icon:le,defaultOpen:!0,copyableContent:n,children:[l&&t.jsx("div",{className:"text-sm text-zinc-50/50 light:text-slate-950/50 markdown border-l-2 border-zinc-700 light:border-slate-400 pl-2 mb-4",children:t.jsx("span",{dangerouslySetInnerHTML:{__html:S.sanitize(_(l))}})}),t.jsx("div",{className:"text-sm text-zinc-50 light:text-slate-950 markdown",dangerouslySetInnerHTML:{__html:S.sanitize(_(n))}})]})}function ke({t:e,metrics:s}){if(!s||Object.keys(s).length===0||!s.prompt_tokens||!s.completion_tokens)return null;function l(n){return n.model?t.jsxs("span",{className:"font-mono text-xs font-normal text-zinc-50/50 light:text-slate-950/50",children:["(",n.model,")"]}):null}return t.jsxs("div",{className:"border border-zinc-700 light:border-slate-400 rounded-lg p-[18px]",children:[t.jsxs("p",{className:"text-sm font-semibold text-zinc-400 light:text-slate-600 uppercase tracking-[1.4px] mb-1",children:[e("scheduledJobs.runDetail.sections.metrics")," ",l(s)]}),t.jsxs("div",{className:"flex gap-6 text-sm text-zinc-400 light:text-slate-600",children:[s.prompt_tokens!=null&&t.jsxs("span",{children:[e("scheduledJobs.runDetail.metrics.promptTokens")," ",t.jsx("span",{className:"text-zinc-50 light:text-slate-950",children:D(s.prompt_tokens)})]}),s.completion_tokens!=null&&t.jsxs("span",{children:[e("scheduledJobs.runDetail.metrics.completionTokens")," ",t.jsx("span",{className:"text-zinc-50 light:text-slate-950",children:D(s.completion_tokens)})]})]})]})}export{Me as default};
|
|
1
|
+
import{r as o,j as t,ad as G,aG as $,aO as X,V as C,u as y,aM as I,s as q,a7 as K,a6 as U,bL as V,ca as B,c as j,l as Y,b as W,Y as f,p as T,a2 as Q,i as Z,a$ as ee,bH as te,av as D}from"../index.js";import{I as se}from"./Brain-24e386d5.js";import{w as le}from"./ChatText-35275002.js";import{I as ne}from"./File-b92df2f3.js";import{R as ae}from"./Stop-4b47ae05.js";import{u as re}from"./usePolling-3b229af5.js";import{c as ie,S as oe,T as J,a as de,b as ce,r as _}from"./files-552bd51c.js";import{C as ue}from"./Copy-d323e545.js";import{H as xe,D as S}from"./purify-bb71c5e8.js";import{t as L}from"./truncate-e484143c.js";import{h as E}from"./moment-49fc1b76.js";/* empty css */function w({title:e,icon:s,children:l,defaultOpen:n=!1,copyableContent:a=null}){const[i,r]=o.useState(n);return t.jsxs("div",{className:"border border-zinc-700 light:border-slate-400 rounded-lg overflow-hidden",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("button",{type:"button",onClick:()=>r(!i),className:"border-none flex-1 h-12 flex items-center gap-2 px-[18px] hover:bg-white/5 light:hover:bg-slate-100 transition-colors text-left",children:[i?t.jsx(G,{className:"h-4 w-4 text-zinc-50 light:text-slate-950"}):t.jsx($,{className:"h-4 w-4 text-zinc-50 light:text-slate-950"}),t.jsx(s,{className:"h-4 w-4 text-zinc-50 light:text-slate-950"}),t.jsx("span",{className:"text-sm font-medium text-zinc-50 light:text-slate-950",children:e})]}),a&&t.jsx(he,{content:a})]}),i&&t.jsx("div",{className:"px-[18px] py-3 border-t border-zinc-700 light:border-slate-400",children:l})]})}function he({content:e}){const[s,l]=o.useState(!1),n=async()=>{await ie(e),l(!0),setTimeout(()=>l(!1),2e3)};return t.jsx("button",{type:"button",onClick:n,disabled:s,className:"h-12 px-4 flex items-center hover:bg-white/5 light:hover:bg-slate-100 transition-colors",children:s?t.jsx(X,{size:20,className:"text-green-500"}):t.jsx(ue,{size:20,className:"text-zinc-50 light:text-slate-950"})})}const F=5e3;function H(e){return e?"github":"github-dark"}function O(e){const s=typeof e=="string"?q(e,e):e;if(typeof s!="object"||s===null)return null;const l=JSON.stringify(s,null,2),n=L(l,F),a=xe.highlight(n,{language:"json"}).value;return{__html:S.sanitize(a)}}function me({toolCall:e}){const[s,l]=o.useState(!1);return t.jsxs("div",{className:"border border-white/5 rounded-lg p-3 bg-theme-bg-primary/30",children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(C,{className:"h-3.5 w-3.5 text-blue-400"}),t.jsx("span",{className:"text-sm font-medium text-theme-text-primary",children:e.toolName})]}),t.jsx(ge,{toolCall:e})]}),t.jsx(pe,{toolCall:e}),t.jsx(be,{toolCall:e,showResult:s,setShowResult:l})]})}function ge({toolCall:e}){return e.timestamp?t.jsx("span",{className:"text-xs text-theme-text-secondary",children:E(e.timestamp).format("LTS")}):null}function pe({toolCall:e}){const{t:s}=y(),{isLight:l}=I();if(!e.arguments)return null;const n=O(e.arguments);return t.jsxs("div",{className:"mb-2",children:[t.jsx("span",{className:"text-xs text-theme-text-secondary",children:s("scheduledJobs.toolCall.arguments")}),n?t.jsx("pre",{className:`text-xs rounded-lg p-2 mt-1 overflow-x-auto white-scrollbar tool-call-scrollbar hljs ${H(l)}`,dangerouslySetInnerHTML:n}):t.jsx("pre",{className:"text-xs text-theme-text-primary bg-theme-bg-primary/50 rounded p-2 mt-1 overflow-x-auto white-scrollbar tool-call-scrollbar",children:typeof e.arguments=="string"?e.arguments:JSON.stringify(e.arguments,null,2)})]})}function be({toolCall:e,showResult:s,setShowResult:l}){const{t:n}=y(),{isLight:a}=I();if(!e.result)return null;const i=typeof e.result=="string"?e.result:JSON.stringify(e.result,null,2),r=L(i,F),d=O(i);return i?t.jsxs("div",{children:[t.jsx("button",{type:"button",onClick:()=>l(!s),className:"border-none text-xs text-blue-400 hover:text-blue-300 transition-colors",children:n(s?"scheduledJobs.toolCall.hideResult":"scheduledJobs.toolCall.showResult")}),s&&(d?t.jsx("pre",{className:`text-xs rounded-lg p-2 mt-1 overflow-x-auto max-h-64 overflow-y-auto whitespace-pre-wrap white-scrollbar tool-call-scrollbar hljs ${H(a)}`,dangerouslySetInnerHTML:d}):t.jsx("pre",{className:"text-xs text-theme-text-primary bg-theme-bg-primary/50 rounded p-2 mt-1 overflow-x-auto max-h-64 overflow-y-auto whitespace-pre-wrap white-scrollbar tool-call-scrollbar",children:r}))]}):null}const R={pptx:{badge:"PPT",bg:"bg-orange-100",text:"text-orange-800",label:e=>e("scheduledJobs.file.types.powerpoint")},ppt:{badge:"PPT",bg:"bg-orange-100",text:"text-orange-800",label:e=>e("scheduledJobs.file.types.powerpoint")},pdf:{badge:"PDF",bg:"bg-red-100",text:"text-red-800",label:e=>e("scheduledJobs.file.types.pdf")},doc:{badge:"DOC",bg:"bg-blue-100",text:"text-blue-800",label:e=>e("scheduledJobs.file.types.word")},docx:{badge:"DOC",bg:"bg-blue-100",text:"text-blue-800",label:e=>e("scheduledJobs.file.types.word")},xls:{badge:"XLS",bg:"bg-green-100",text:"text-green-800",label:e=>e("scheduledJobs.file.types.spreadsheet")},xlsx:{badge:"XLS",bg:"bg-green-100",text:"text-green-800",label:e=>e("scheduledJobs.file.types.spreadsheet")},csv:{badge:"CSV",bg:"bg-green-100",text:"text-green-800",label:e=>e("scheduledJobs.file.types.spreadsheet")},default:{badge:"FILE",bg:"bg-zinc-200",text:"text-zinc-800",label:e=>e("scheduledJobs.file.types.generic")}};function fe(e,s){var a,i;const l=((i=(a=e==null?void 0:e.split("."))==null?void 0:a.pop())==null?void 0:i.toLowerCase())??"txt",n=R[l]||R.default;return{...n,type:n.label(s)}}function je({file:e}){const{t:s}=y(),[l,n]=o.useState(!1),{badge:a,bg:i,text:r,type:d}=fe(e.filename,s),u=async()=>{if(!(l||!e.storageFilename)){n(!0);try{const h=await oe.download(e.storageFilename);if(!h)throw new Error("Failed to download file");const{saveAs:m}=await B(()=>import("../index.js").then(g=>g.F),["index.js","index.css"]);m(h,e.filename||e.storageFilename)}catch{j(s("scheduledJobs.file.downloadFailed"),"error")}finally{n(!1)}}};return t.jsxs("div",{className:"flex items-center justify-between bg-zinc-800 light:bg-slate-100 rounded-lg p-3",children:[t.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[t.jsx("div",{className:`${i} ${r} rounded-lg flex items-center justify-center shrink-0 h-10 w-10 text-xs font-semibold`,children:a}),t.jsxs("div",{className:"flex flex-col min-w-0",children:[t.jsx("p",{className:"text-sm text-white light:text-slate-950 truncate",children:e.filename||s("scheduledJobs.file.unknown")}),t.jsxs("p",{className:"text-sm text-zinc-400 light:text-slate-600",children:[K(e.fileSize,!0,1),e.fileSize&&d?" · ":"",d]})]})]}),t.jsx("button",{type:"button",onClick:u,disabled:l,title:s("scheduledJobs.file.download"),"aria-label":s("scheduledJobs.file.download"),className:"border-none text-zinc-400 light:text-slate-600 hover:text-zinc-50 light:hover:text-slate-950 transition-colors shrink-0 ml-4 disabled:opacity-50",children:l?t.jsx(U,{size:16,weight:"bold",className:"animate-spin"}):t.jsx(V,{size:16,weight:"bold"})})]})}function Me(){const{t:e}=y(),{id:s,runId:l}=Y(),n=W(),[a,i]=o.useState(!0),[r,d]=o.useState(null),[u,h]=o.useState(null),[m,g]=o.useState(!1),[N,p]=o.useState(!1);o.useEffect(()=>{v()},[l]);const v=async()=>{const c=await f.getRun(l);d(c.run),h(c.job),i(!1),c.run&&!c.run.readAt&&f.markRunRead(l)},P=(r==null?void 0:r.status)==="running"||(r==null?void 0:r.status)==="queued";re(v,3e3,P);const M=async()=>{g(!0);const{workspaceSlug:c,threadSlug:b,error:k}=await f.continueInThread(l);if(k||!c||!b){j(k||e("scheduledJobs.runDetail.threadFailed"),"error"),g(!1);return}n(T.workspace.thread(c,b))},A=async()=>{p(!0);const{success:c,error:b}=await f.killRun(l);if(p(!1),!c){j(b||e("scheduledJobs.toast.killFailed"),"error");return}j(e("scheduledJobs.toast.killed"),"success"),v()};if(a)return t.jsx(z,{children:t.jsx("p",{className:"text-zinc-400 light:text-slate-600 text-sm",children:e("scheduledJobs.runDetail.loading")})});if(!r)return t.jsx(z,{children:t.jsx("p",{className:"text-zinc-400 light:text-slate-600 text-sm",children:e("scheduledJobs.runDetail.notFound")})});const x=r.result||{};return t.jsxs(z,{children:[t.jsx(ye,{t:e,job:u,run:r,result:x,continuing:m,killing:N,onBack:()=>n(T.settings.scheduledJobRuns(s)),onContinueInThread:M,onKillRun:A}),t.jsxs("div",{className:"mt-6 space-y-4",children:[t.jsx(we,{t:e,prompt:u==null?void 0:u.prompt}),t.jsx(Ne,{t:e,error:r==null?void 0:r.error}),t.jsx(ve,{t:e,result:x}),t.jsx(Je,{t:e,result:x}),t.jsx(ze,{t:e,result:x}),t.jsx(Se,{t:e,result:x}),t.jsx(ke,{t:e,metrics:x==null?void 0:x.metrics})]})]})}function z({children:e}){return t.jsxs("div",{className:"w-screen h-screen overflow-hidden bg-theme-bg-container flex",children:[t.jsx(Q,{}),t.jsx("div",{style:{height:Z?"100%":"calc(100% - 32px)"},className:"relative md:ml-[2px] md:mr-[16px] md:my-[16px] md:rounded-[16px] bg-theme-bg-secondary w-full h-full overflow-y-scroll p-4 md:p-0",children:t.jsx("div",{className:"flex flex-col w-full px-1 md:pl-6 md:pr-[50px] md:py-6 py-16",children:e})})]})}function ye({t:e,job:s,run:l,result:n,continuing:a,killing:i,onBack:r,onContinueInThread:d,onKillRun:u}){function h(){return{completed:{text:e("scheduledJobs.status.completed"),style:"text-green-400 light:text-green-600"},failed:{text:e("scheduledJobs.status.failed"),style:"text-red-400 light:text-red-600"},timed_out:{text:e("scheduledJobs.status.timed_out"),style:"text-orange-400 light:text-orange-600"},running:{text:e("scheduledJobs.status.running"),style:"text-yellow-400 light:text-yellow-600"},queued:{text:e("scheduledJobs.status.queued"),style:"text-blue-400 light:text-blue-600"},default:{text:"—",style:"text-zinc-400 light:text-slate-600"}}}const m=h(),{text:g,style:N}=m[l.status]||m.default,p=["running","queued"].includes(l.status);return t.jsxs("div",{className:"w-full flex items-end justify-between gap-x-4 pb-6 border-white/10 light:border-zinc-300 border-b-2",children:[t.jsxs("div",{className:"flex flex-col gap-y-2",children:[t.jsxs("button",{type:"button",onClick:r,className:"border-none flex items-center gap-2 text-zinc-400 light:text-slate-600 hover:text-zinc-50 light:hover:text-slate-950 text-sm transition-colors w-fit",children:[t.jsx(ee,{className:"h-4 w-4"}),e("scheduledJobs.runDetail.back")]}),t.jsx("p",{className:"text-lg leading-7 font-semibold text-zinc-50 light:text-slate-950",children:e("scheduledJobs.runDetail.runHeading",{name:(s==null?void 0:s.name)||e("scheduledJobs.runDetail.unknownJob"),id:l.id})}),t.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[t.jsx("span",{className:N,children:g}),t.jsx("span",{className:"text-zinc-400 light:text-slate-600",children:E(l.startedAt).format("LTS")}),n.duration&&t.jsx("span",{className:"text-zinc-400 light:text-slate-600",children:e("scheduledJobs.runDetail.duration",{value:te(n.duration/1e3)})})]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[p&&t.jsxs("button",{type:"button",onClick:u,disabled:i,title:e("scheduledJobs.runDetail.stopJob"),className:"border-none h-9 px-5 rounded-lg bg-red-500/20 text-red-400 light:bg-red-100 light:text-red-600 text-sm font-medium hover:bg-red-500/30 light:hover:bg-red-200 transition-colors disabled:opacity-50 shrink-0 flex items-center gap-2",children:[t.jsx(ae,{className:"h-4 w-4",weight:"bold"}),e(i?"scheduledJobs.runDetail.killing":"scheduledJobs.runDetail.stopJob")]}),l.status==="completed"&&t.jsx("button",{type:"button",onClick:d,disabled:a,className:"border-none h-9 px-5 rounded-lg bg-zinc-50 text-zinc-950 light:bg-slate-900 light:text-white text-sm font-medium hover:bg-zinc-200 light:hover:bg-slate-800 transition-colors disabled:opacity-50 shrink-0",children:e(a?"scheduledJobs.runDetail.creating":"scheduledJobs.runDetail.continueInThread")})]})]})}function we({t:e,prompt:s}){return t.jsxs("div",{className:"border border-zinc-700 light:border-slate-400 rounded-lg p-[18px]",children:[t.jsx("p",{className:"text-sm font-medium text-white light:text-slate-950 uppercase tracking-[1.4px] mb-1",children:e("scheduledJobs.runDetail.sections.prompt")}),t.jsx("p",{className:"text-sm text-zinc-400 light:text-slate-600 whitespace-pre-wrap",children:s||"—"})]})}function Ne({t:e,error:s}){return s?t.jsxs("div",{className:"border border-red-500/20 light:border-red-300 rounded-lg p-[18px] bg-red-500/5 light:bg-red-50",children:[t.jsx("p",{className:"text-sm font-medium text-red-400 light:text-red-600 uppercase tracking-[1.4px] mb-1",children:e("scheduledJobs.runDetail.sections.error")}),t.jsx("p",{className:"text-sm text-red-300 light:text-red-700",children:s})]}):null}function ve({t:e,result:s}){return!s.thoughts||s.thoughts.length===0?null:t.jsx(w,{title:e("scheduledJobs.runDetail.sections.thinking",{count:s.thoughts.length}),icon:se,children:t.jsx("div",{className:"space-y-2",children:s.thoughts.map((l,n)=>t.jsxs("div",{className:"flex items-start gap-2 text-sm text-theme-text-secondary",children:[t.jsxs("span",{className:"text-xs text-theme-text-secondary/50 mt-0.5 min-w-[20px]",children:[n+1,"."]}),t.jsx("span",{children:l})]},n))})})}function Je({t:e,result:s}){return!s.toolCalls||s.toolCalls.length===0?null:t.jsx(w,{title:e("scheduledJobs.runDetail.sections.toolCalls",{count:s.toolCalls.length}),icon:C,children:t.jsx("div",{className:"space-y-3",children:s.toolCalls.map((l,n)=>t.jsx(me,{toolCall:l},n))})})}function ze({t:e,result:s}){const l=s.outputs||[];return l.length===0?null:t.jsx(w,{title:e("scheduledJobs.runDetail.sections.files",{count:l.length}),icon:ne,defaultOpen:!0,children:t.jsx("div",{className:"space-y-2",children:l.map((n,a)=>t.jsx(je,{file:n.payload,type:n.type},a))})})}function Se({t:e,result:s}){var a;if(!s.text)return null;let l=null,n=s.text;return s.text.match(J)&&(l=(a=s.text.match(J))==null?void 0:a[0],l&&(l=l.replace(de,"").replace(ce,"").trim()),n=s.text.replace(J,"")),t.jsxs(w,{title:e("scheduledJobs.runDetail.sections.response"),icon:le,defaultOpen:!0,copyableContent:n,children:[l&&t.jsx("div",{className:"text-sm text-zinc-50/50 light:text-slate-950/50 markdown border-l-2 border-zinc-700 light:border-slate-400 pl-2 mb-4",children:t.jsx("span",{dangerouslySetInnerHTML:{__html:S.sanitize(_(l))}})}),t.jsx("div",{className:"text-sm text-zinc-50 light:text-slate-950 markdown",dangerouslySetInnerHTML:{__html:S.sanitize(_(n))}})]})}function ke({t:e,metrics:s}){if(!s||Object.keys(s).length===0||!s.prompt_tokens||!s.completion_tokens)return null;function l(n){return n.model?t.jsxs("span",{className:"font-mono text-xs font-normal text-zinc-50/50 light:text-slate-950/50",children:["(",n.model,")"]}):null}return t.jsxs("div",{className:"border border-zinc-700 light:border-slate-400 rounded-lg p-[18px]",children:[t.jsxs("p",{className:"text-sm font-semibold text-zinc-400 light:text-slate-600 uppercase tracking-[1.4px] mb-1",children:[e("scheduledJobs.runDetail.sections.metrics")," ",l(s)]}),t.jsxs("div",{className:"flex gap-6 text-sm text-zinc-400 light:text-slate-600",children:[s.prompt_tokens!=null&&t.jsxs("span",{children:[e("scheduledJobs.runDetail.metrics.promptTokens")," ",t.jsx("span",{className:"text-zinc-50 light:text-slate-950",children:D(s.prompt_tokens)})]}),s.completion_tokens!=null&&t.jsxs("span",{children:[e("scheduledJobs.runDetail.metrics.completionTokens")," ",t.jsx("span",{className:"text-zinc-50 light:text-slate-950",children:D(s.completion_tokens)})]})]})]})}export{Me as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{u as h,j as t,b as j,r as d,p as N,c9 as z,bH as H,Y as x,c,l as R,a2 as S,i as k,a$ as A}from"../index.js";import{u as q}from"./usePolling-3b229af5.js";import{R as C}from"./Stop-4b47ae05.js";import{h as y}from"./moment-49fc1b76.js";import{h as T}from"./cron-db080d69.js";function D(e){return{completed:{text:e("scheduledJobs.status.completed"),style:"font-medium text-white light:text-slate-950"},failed:{text:e("scheduledJobs.status.failed"),style:"text-red-400 light:text-red-600"},timed_out:{text:e("scheduledJobs.status.timed_out"),style:"text-red-400 light:text-red-600"},running:{text:e("scheduledJobs.status.running"),style:"italic text-zinc-400 light:text-slate-600"},queued:{text:e("scheduledJobs.status.queued"),style:"italic text-zinc-400 light:text-slate-600"},default:{text:"—",style:"text-zinc-400 light:text-slate-600"}}}function I({status:e}){const{t:l}=h(),s=D(l),{text:a,style:n}=s[e]||s.default;return t.jsx("span",{className:`text-sm ${n}`,children:a})}function P(e){if(!e.completedAt||!e.startedAt)return"—";const l=y.duration(y(e.completedAt).diff(y(e.startedAt)));return H(l.asSeconds())}function $({run:e,jobId:l,onKilled:s}){const{t:a}=h(),n=j(),[m,o]=d.useState(!1),g=!e.readAt&&!["running","queued"].includes(e.status),p=["running","queued"].includes(e.status),u=async f=>{f.stopPropagation(),o(!0);const{success:r,error:b}=await x.killRun(e.id);if(o(!1),!r){c(b||a("scheduledJobs.toast.killFailed"),"error");return}c(a("scheduledJobs.toast.killed"),"success"),s==null||s()};return t.jsxs("button",{type:"button",onClick:()=>n(N.settings.scheduledJobRunDetail(l,e.id)),className:"border-none flex items-center px-4 h-14 hover:bg-white/5 light:hover:bg-slate-200 transition-colors text-left w-full",children:[t.jsxs("div",{className:"w-[200px] flex items-center gap-2 relative",children:[g&&t.jsx(z,{weight:"fill",className:"h-2 w-2 text-blue-400 light:text-blue-600 absolute -left-4"}),p&&t.jsx("button",{type:"button",onClick:u,disabled:m,title:a("scheduledJobs.runHistory.stopJob"),className:"border-none ml-2 p-1.5 rounded bg-red-500/20 text-red-400 light:bg-red-100 light:text-red-600 hover:bg-red-500/30 light:hover:bg-red-200 transition-colors disabled:opacity-50",children:t.jsx(C,{className:"h-3.5 w-3.5",weight:"bold"})}),t.jsx(I,{status:e.status})]}),t.jsx("span",{className:"w-[260px] text-sm font-medium text-white light:text-slate-950 truncate",children:new Date(e.startedAt).toLocaleString()}),t.jsx("span",{className:"w-[160px] text-sm font-medium text-white light:text-slate-950 truncate",children:P(e)}),t.jsx("span",{className:`flex-1 text-sm truncate pr-4 ${e.error?"text-red-400 light:text-red-600 italic":"font-medium text-white light:text-slate-950"}`,children:e.error||"—"})]})}function B(){const{t:e}=h(),{id:l}=R(),[s,a]=d.useState(null),[n,m]=d.useState([]),[o,g]=d.useState(!0),[p,u]=d.useState(!1),f=n.some(i=>i.status==="queued"||i.status==="running"),r=async()=>{const{runs:i}=await x.runs(l);m(i||[]),g(!1)};d.useEffect(()=>{x.get(l).then(({job:i})=>a(i)),r()},[l]),q(r,5e3);const b=async()=>{u(!0);const{success:i,skipped:v,error:J}=await x.trigger(l);if(u(!1),!i){c(J||e("scheduledJobs.toast.triggerFailed"),"error");return}v?c(e("scheduledJobs.toast.triggerSkipped","A run is already in progress for this job"),"info"):c(e("scheduledJobs.toast.triggered"),"success"),r()};return o?t.jsx(w,{job:s,children:t.jsx("div",{className:"flex flex-col items-center justify-center gap-8 py-24 text-center",children:t.jsx("p",{className:"text-zinc-400 light:text-slate-600 text-sm",children:e("scheduledJobs.loading")})})}):t.jsx(w,{job:s,children:t.jsxs("div",{className:"pt-8",children:[t.jsxs("div",{className:"flex items-center px-4 pb-[18px] text-xs font-semibold uppercase tracking-[1.4px] text-zinc-400 light:text-slate-600",children:[t.jsx("span",{className:"w-[200px]",children:e("scheduledJobs.runHistory.table.status")}),t.jsx("span",{className:"w-[260px]",children:e("scheduledJobs.runHistory.table.started")}),t.jsx("span",{className:"w-[160px]",children:e("scheduledJobs.runHistory.table.duration")}),t.jsx("span",{className:"flex-1",children:e("scheduledJobs.runHistory.table.error")})]}),t.jsx("div",{className:"h-px w-full bg-white/10 light:bg-slate-300"}),n.length===0?t.jsxs("div",{className:"flex flex-col items-center justify-center gap-8 py-24 text-center",children:[t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx("p",{className:"text-base font-semibold text-zinc-50 light:text-slate-950",children:e("scheduledJobs.runHistory.emptyTitle")}),t.jsx("p",{className:"text-sm font-medium text-zinc-400 light:text-slate-600",children:e("scheduledJobs.runHistory.emptySubtitle")})]}),t.jsx("button",{type:"button",onClick:b,disabled:p||f,className:"border-none h-9 px-5 rounded-lg bg-zinc-50 text-zinc-950 light:bg-slate-900 light:text-white text-sm font-medium hover:bg-zinc-200 light:hover:bg-slate-800 transition-colors disabled:opacity-50",children:e("scheduledJobs.runHistory.runNow")})]}):t.jsx("div",{className:"flex flex-col divide-y divide-white/5 light:divide-slate-200",children:n.map(i=>t.jsx($,{run:i,jobId:s==null?void 0:s.id,onKilled:r},i.id))})]})})}function w({job:e,children:l}){const{t:s,i18n:a}=h(),n=j();return t.jsxs("div",{className:"w-screen h-screen overflow-hidden bg-theme-bg-container flex",children:[t.jsx(S,{}),t.jsx("div",{style:{height:k?"100%":"calc(100% - 32px)"},className:"relative md:ml-[2px] md:mr-[16px] md:my-[16px] md:rounded-[16px] bg-theme-bg-secondary w-full h-full overflow-y-scroll p-4 md:p-0",children:t.jsxs("div",{className:"flex flex-col w-full px-1 md:pl-6 md:pr-[50px] md:py-6 py-16",children:[t.jsxs("div",{className:"w-full flex flex-col gap-y-2 pb-6 border-white/10 light:border-slate-300 border-b-2",children:[t.jsxs("button",{type:"button",onClick:()=>n(N.settings.scheduledJobs()),className:"border-none flex items-center gap-2 text-zinc-400 light:text-slate-600 hover:text-zinc-50 light:hover:text-slate-950 text-sm transition-colors w-fit",children:[t.jsx(A,{className:"h-4 w-4"}),s("scheduledJobs.runHistory.back")]}),t.jsx("p",{className:"text-lg leading-7 font-semibold text-zinc-50 light:text-slate-950",children:s("scheduledJobs.runHistory.title",{name:(e==null?void 0:e.name)||"..."})}),t.jsxs("p",{className:"text-xs text-zinc-400 light:text-slate-600",children:[s("scheduledJobs.runHistory.schedule")," ",t.jsx("code",{children:T(e==null?void 0:e.schedule,a.language)||"—"})]})]}),l]})})]})}export{B as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{aU as M,bz as U,bA as J,r as x,bB as D,bC as B,bD as V,bE as L,bF as X}from"../index.js";var Y={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0};const Z=M(Y);var q=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function S(e){var t={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},n=e.match(/<\/?([^\s]+?)[/\s>]/);if(n&&(t.name=n[1],(Z[n[1]]||e.charAt(e.length-2)==="/")&&(t.voidElement=!0),t.name.startsWith("!--"))){var i=e.indexOf("-->");return{type:"comment",comment:i!==-1?e.slice(4,i):""}}for(var f=new RegExp(q),r=null;(r=f.exec(e))!==null;)if(r[0].trim())if(r[1]){var c=r[1].trim(),l=[c,""];c.indexOf("=")>-1&&(l=c.split("=")),t.attrs[l[0]]=l[1],f.lastIndex--}else r[2]&&(t.attrs[r[2]]=r[3].trim().substring(1,r[3].length-1));return t}var G=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,Q=/^\s*$/,_=Object.create(null);function W(e,t){switch(t.type){case"text":return e+t.content;case"tag":return e+="<"+t.name+(t.attrs?function(n){var i=[];for(var f in n)i.push(f+'="'+n[f]+'"');return i.length?" "+i.join(" "):""}(t.attrs):"")+(t.voidElement?"/>":">"),t.voidElement?e:e+t.children.reduce(W,"")+"</"+t.name+">";case"comment":return e+"<!--"+t.comment+"-->"}}var R={parse:function(e,t){t||(t={}),t.components||(t.components=_);var n,i=[],f=[],r=-1,c=!1;if(e.indexOf("<")!==0){var l=e.indexOf("<");i.push({type:"text",content:l===-1?e:e.substring(0,l)})}return e.replace(G,function(u,m){if(c){if(u!=="</"+n.name+">")return;c=!1}var v,b=u.charAt(1)!=="/",A=u.startsWith("<!--"),E=m+u.length,$=e.charAt(E);if(A){var h=S(u);return r<0?(i.push(h),i):((v=f[r]).children.push(h),i)}if(b&&(r++,(n=S(u)).type==="tag"&&t.components[n.name]&&(n.type="component",c=!0),n.voidElement||c||!$||$==="<"||n.children.push({type:"text",content:e.slice(E,e.indexOf("<",E))}),r===0&&i.push(n),(v=f[r-1])&&v.children.push(n),f[r]=n),(!b||n.voidElement)&&(r>-1&&(n.voidElement||n.name===u.slice(2,-1))&&(r--,n=r===-1?i:f[r]),!c&&$!=="<"&&$)){v=r===-1?i:f[r].children;var p=e.indexOf("<",E),o=e.slice(E,p===-1?void 0:p);Q.test(o)&&(o=" "),(p>-1&&r+v.length>=0||o!==" ")&&v.push({type:"text",content:o})}}),i},stringify:function(e){return e.reduce(function(t,n){return t+W("",n)},"")}};const H=(e,t)=>{if(!e)return!1;const n=e.props?e.props.children:e.children;return t?n.length>0:!!n},I=e=>{if(!e)return[];const t=e.props?e.props.children:e.children;return e.props&&e.props.i18nIsDynamicList?P(t):t},ee=e=>Array.isArray(e)&&e.every(x.isValidElement),P=e=>Array.isArray(e)?e:[e],te=(e,t)=>{const n={...t};return n.props=Object.assign(e.props,t.props),n},z=(e,t)=>{if(!e)return"";let n="";const i=P(e),f=t.transSupportBasicHtmlNodes&&t.transKeepBasicHtmlNodesFor?t.transKeepBasicHtmlNodesFor:[];return i.forEach((r,c)=>{if(D(r))n+=`${r}`;else if(x.isValidElement(r)){const{props:l,type:u}=r,m=Object.keys(l).length,v=f.indexOf(u)>-1,b=l.children;if(!b&&v&&!m)n+=`<${u}/>`;else if(!b&&(!v||m)||l.i18nIsDynamicList)n+=`<${c}></${c}>`;else if(v&&m===1&&D(b))n+=`<${u}>${b}</${u}>`;else{const A=z(b,t);n+=`<${c}>${A}</${c}>`}}else if(r===null)B("Trans: the passed in value is invalid - seems you passed in a null child.");else if(V(r)){const{format:l,...u}=r,m=Object.keys(u);if(m.length===1){const v=l?`${m[0]}, ${l}`:m[0];n+=`{{${v}}}`}else B("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",r)}else B("Trans: the passed in value is invalid - seems you passed in a variable like {number} - please pass in variables for interpolation as full objects like {{number}}.",r)}),n},ne=(e,t,n,i,f,r)=>{if(t==="")return[];const c=i.transKeepBasicHtmlNodesFor||[],l=t&&new RegExp(c.map(p=>`<${p}`).join("|")).test(t);if(!e&&!l&&!r)return[t];const u={},m=p=>{P(p).forEach(a=>{D(a)||(H(a)?m(I(a)):V(a)&&!x.isValidElement(a)&&Object.assign(u,a))})};m(e);const v=R.parse(`<0>${t}</0>`),b={...u,...f},A=(p,o,a)=>{const g=I(p),C=$(g,o.children,a);return ee(g)&&C.length===0||p.props&&p.props.i18nIsDynamicList?g:C},E=(p,o,a,g,C)=>{p.dummy?(p.children=o,a.push(x.cloneElement(p,{key:g},C?void 0:o))):a.push(...x.Children.map([p],d=>{const s={...d.props};return delete s.i18nIsDynamicList,x.createElement(d.type,{...s,key:g,ref:d.ref},C?null:o)}))},$=(p,o,a)=>{const g=P(p);return P(o).reduce((d,s,T)=>{const N=s.children&&s.children[0]&&s.children[0].content&&n.services.interpolator.interpolate(s.children[0].content,b,n.language);if(s.type==="tag"){let k=g[parseInt(s.name,10)];a.length===1&&!k&&(k=a[0][s.name]),k||(k={});const y=Object.keys(s.attrs).length!==0?te({props:s.attrs},k):k,F=x.isValidElement(y),j=F&&H(s,!0)&&!s.voidElement,w=l&&V(y)&&y.dummy&&!F,K=V(e)&&Object.hasOwnProperty.call(e,s.name);if(D(y)){const O=n.services.interpolator.interpolate(y,b,n.language);d.push(O)}else if(H(y)||j){const O=A(y,s,a);E(y,O,d,T)}else if(w){const O=$(g,s.children,a);E(y,O,d,T)}else if(Number.isNaN(parseFloat(s.name)))if(K){const O=A(y,s,a);E(y,O,d,T,s.voidElement)}else if(i.transSupportBasicHtmlNodes&&c.indexOf(s.name)>-1)if(s.voidElement)d.push(x.createElement(s.name,{key:`${s.name}-${T}`}));else{const O=$(g,s.children,a);d.push(x.createElement(s.name,{key:`${s.name}-${T}`},O))}else if(s.voidElement)d.push(`<${s.name} />`);else{const O=$(g,s.children,a);d.push(`<${s.name}>${O}</${s.name}>`)}else if(V(y)&&!F){const O=s.children[0]?N:null;O&&d.push(O)}else E(y,N,d,T,s.children.length!==1||!N)}else if(s.type==="text"){const k=i.transWrapTextNodes,y=r?i.unescape(n.services.interpolator.interpolate(s.content,b,n.language)):n.services.interpolator.interpolate(s.content,b,n.language);k?d.push(x.createElement(k,{key:`${s.name}-${T}`},y)):d.push(y)}return d},[])},h=$([{dummy:!0,children:e||[]}],v,P(e||[]));return I(h[0])};function se(e){let{children:t,count:n,parent:i,i18nKey:f,context:r,tOptions:c={},values:l,defaults:u,components:m,ns:v,i18n:b,t:A,shouldUnescape:E,...$}=e;const h=b||L();if(!h)return U("You will need to pass in an i18next instance by using i18nextReactModule"),t;const p=A||h.t.bind(h)||(j=>j),o={...J(),...h.options&&h.options.react};let a=v||p.ns||h.options&&h.options.defaultNS;a=D(a)?[a]:a||["translation"];const g=z(t,o),C=u||g||o.transEmptyNodeValue||f,{hashTransKey:d}=o,s=f||(d?d(g||C):g||C);h.options&&h.options.interpolation&&h.options.interpolation.defaultVariables&&(l=l&&Object.keys(l).length>0?{...l,...h.options.interpolation.defaultVariables}:{...h.options.interpolation.defaultVariables});const T=l||n!==void 0||!t?c.interpolation:{interpolation:{...c.interpolation,prefix:"#$?",suffix:"?$#"}},N={...c,context:r||c.context,count:n,...l,...T,defaultValue:C,ns:a},k=s?p(s,N):C;m&&Object.keys(m).forEach(j=>{const w=m[j];if(typeof w.type=="function"||!w.props||!w.props.children||k.indexOf(`${j}/>`)<0&&k.indexOf(`${j} />`)<0)return;function K(){return x.createElement(x.Fragment,null,w)}m[j]=x.createElement(K)});const y=ne(m||t,k,h,o,N,E),F=i!==void 0?i:o.defaultTransParent;return F?x.createElement(F,$,y):y}function ae(e){let{children:t,count:n,parent:i,i18nKey:f,context:r,tOptions:c={},values:l,defaults:u,components:m,ns:v,i18n:b,t:A,shouldUnescape:E,...$}=e;const{i18n:h,defaultNS:p}=x.useContext(X)||{},o=b||h||L(),a=A||o&&o.t.bind(o);return se({children:t,count:n,parent:i,i18nKey:f,context:r,tOptions:c,values:l,defaults:u,components:m,ns:v||a&&a.ns||p||o&&o.options&&o.options.defaultNS,i18n:o,t:A,shouldUnescape:E,...$})}export{ae as T};
|