@egdesk/next-api-plugin 1.5.100 → 1.5.108
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generate-chunked-upload-routes.d.ts +4 -1
- package/dist/generate-chunked-upload-routes.js +31 -13
- package/dist/generate-helpers.js +321 -0
- package/dist/generate-middleware.js +15 -2
- package/dist/generate-proxy.js +16 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -3
- package/package.json +1 -1
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generate Next.js App Router handlers that proxy chunked uploads to EGDesk MCP.
|
|
3
|
-
* Browser → these routes (tunnel-safe small chunks) → localhost MCP
|
|
3
|
+
* Browser → these routes (tunnel-safe small chunks) → localhost MCP upload endpoints.
|
|
4
4
|
*/
|
|
5
|
+
/** My DB row attachments → MCP /user-data/uploads */
|
|
5
6
|
export declare function generateChunkedUploadRoutes(projectPath: string): void;
|
|
7
|
+
/** Voice Transcript audio → MCP /voice-transcript/uploads (allowlisted for transcribe) */
|
|
8
|
+
export declare function generateVoiceTranscriptChunkedUploadRoutes(projectPath: string): void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* Generate Next.js App Router handlers that proxy chunked uploads to EGDesk MCP.
|
|
4
|
-
* Browser → these routes (tunnel-safe small chunks) → localhost MCP
|
|
4
|
+
* Browser → these routes (tunnel-safe small chunks) → localhost MCP upload endpoints.
|
|
5
5
|
*/
|
|
6
6
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
7
|
if (k2 === undefined) k2 = k;
|
|
@@ -38,6 +38,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
38
38
|
})();
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
40
|
exports.generateChunkedUploadRoutes = generateChunkedUploadRoutes;
|
|
41
|
+
exports.generateVoiceTranscriptChunkedUploadRoutes = generateVoiceTranscriptChunkedUploadRoutes;
|
|
41
42
|
const fs = __importStar(require("fs"));
|
|
42
43
|
const path = __importStar(require("path"));
|
|
43
44
|
const os = __importStar(require("os"));
|
|
@@ -117,18 +118,19 @@ export async function proxyRaw(
|
|
|
117
118
|
return NextResponse.json(parsed, { status: response.status });
|
|
118
119
|
}
|
|
119
120
|
`;
|
|
120
|
-
function
|
|
121
|
+
function generateChunkedUploadRouteTree(projectPath, spec) {
|
|
121
122
|
const hasSrc = usesSrcDirectory(projectPath);
|
|
122
123
|
const appRoot = hasSrc ? path.join(projectPath, 'src', 'app') : path.join(projectPath, 'app');
|
|
123
|
-
const base = path.join(appRoot,
|
|
124
|
+
const base = path.join(appRoot, ...spec.appApiSegments);
|
|
125
|
+
const mcp = spec.mcpUploadsPath.replace(/\/$/, '');
|
|
124
126
|
writeFile(path.join(base, '_proxy.ts'), SHARED_HELPER);
|
|
125
127
|
writeFile(path.join(base, 'route.ts'), `import { NextRequest } from 'next/server';
|
|
126
128
|
import { proxyJson } from './_proxy';
|
|
127
129
|
|
|
128
|
-
/**
|
|
130
|
+
/** ${spec.initPostComment} */
|
|
129
131
|
export async function POST(request: NextRequest) {
|
|
130
132
|
const body = await request.text();
|
|
131
|
-
return proxyJson('
|
|
133
|
+
return proxyJson('${mcp}', {
|
|
132
134
|
method: 'POST',
|
|
133
135
|
headers: { 'Content-Type': 'application/json' },
|
|
134
136
|
body,
|
|
@@ -138,28 +140,28 @@ export async function POST(request: NextRequest) {
|
|
|
138
140
|
writeFile(path.join(base, '[id]', 'route.ts'), `import { NextRequest } from 'next/server';
|
|
139
141
|
import { proxyJson } from '../_proxy';
|
|
140
142
|
|
|
141
|
-
/** GET
|
|
143
|
+
/** GET — upload status */
|
|
142
144
|
export async function GET(
|
|
143
145
|
_request: NextRequest,
|
|
144
146
|
ctx: { params: Promise<{ id: string }> | { id: string } },
|
|
145
147
|
) {
|
|
146
148
|
const params = await Promise.resolve(ctx.params);
|
|
147
|
-
return proxyJson(
|
|
149
|
+
return proxyJson(\`${mcp}/\${params.id}\`, { method: 'GET' });
|
|
148
150
|
}
|
|
149
151
|
|
|
150
|
-
/** DELETE
|
|
152
|
+
/** DELETE — abort upload */
|
|
151
153
|
export async function DELETE(
|
|
152
154
|
_request: NextRequest,
|
|
153
155
|
ctx: { params: Promise<{ id: string }> | { id: string } },
|
|
154
156
|
) {
|
|
155
157
|
const params = await Promise.resolve(ctx.params);
|
|
156
|
-
return proxyJson(
|
|
158
|
+
return proxyJson(\`${mcp}/\${params.id}\`, { method: 'DELETE' });
|
|
157
159
|
}
|
|
158
160
|
`);
|
|
159
161
|
writeFile(path.join(base, '[id]', 'chunks', '[index]', 'route.ts'), `import { NextRequest } from 'next/server';
|
|
160
162
|
import { proxyRaw } from '../../../_proxy';
|
|
161
163
|
|
|
162
|
-
/** PUT
|
|
164
|
+
/** PUT — raw octet-stream chunk */
|
|
163
165
|
export async function PUT(
|
|
164
166
|
request: NextRequest,
|
|
165
167
|
ctx: { params: Promise<{ id: string; index: string }> | { id: string; index: string } },
|
|
@@ -168,7 +170,7 @@ export async function PUT(
|
|
|
168
170
|
const buf = await request.arrayBuffer();
|
|
169
171
|
const sha = request.headers.get('x-chunk-sha256');
|
|
170
172
|
return proxyRaw(
|
|
171
|
-
|
|
173
|
+
\`${mcp}/\${params.id}/chunks/\${params.index}\`,
|
|
172
174
|
'PUT',
|
|
173
175
|
buf,
|
|
174
176
|
{
|
|
@@ -181,13 +183,13 @@ export async function PUT(
|
|
|
181
183
|
writeFile(path.join(base, '[id]', 'complete', 'route.ts'), `import { NextRequest } from 'next/server';
|
|
182
184
|
import { proxyJson } from '../../_proxy';
|
|
183
185
|
|
|
184
|
-
/** POST
|
|
186
|
+
/** POST — finalize upload */
|
|
185
187
|
export async function POST(
|
|
186
188
|
_request: NextRequest,
|
|
187
189
|
ctx: { params: Promise<{ id: string }> | { id: string } },
|
|
188
190
|
) {
|
|
189
191
|
const params = await Promise.resolve(ctx.params);
|
|
190
|
-
return proxyJson(
|
|
192
|
+
return proxyJson(\`${mcp}/\${params.id}/complete\`, {
|
|
191
193
|
method: 'POST',
|
|
192
194
|
headers: { 'Content-Type': 'application/json' },
|
|
193
195
|
body: '{}',
|
|
@@ -195,3 +197,19 @@ export async function POST(
|
|
|
195
197
|
}
|
|
196
198
|
`);
|
|
197
199
|
}
|
|
200
|
+
/** My DB row attachments → MCP /user-data/uploads */
|
|
201
|
+
function generateChunkedUploadRoutes(projectPath) {
|
|
202
|
+
generateChunkedUploadRouteTree(projectPath, {
|
|
203
|
+
appApiSegments: ['api', 'user', 'files', 'uploads'],
|
|
204
|
+
mcpUploadsPath: '/user-data/uploads',
|
|
205
|
+
initPostComment: 'POST /api/user/files/uploads — init chunked upload',
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
/** Voice Transcript audio → MCP /voice-transcript/uploads (allowlisted for transcribe) */
|
|
209
|
+
function generateVoiceTranscriptChunkedUploadRoutes(projectPath) {
|
|
210
|
+
generateChunkedUploadRouteTree(projectPath, {
|
|
211
|
+
appApiSegments: ['api', 'voice-transcript', 'uploads'],
|
|
212
|
+
mcpUploadsPath: '/voice-transcript/uploads',
|
|
213
|
+
initPostComment: 'POST /api/voice-transcript/uploads — init chunked audio upload',
|
|
214
|
+
});
|
|
215
|
+
}
|
package/dist/generate-helpers.js
CHANGED
|
@@ -1000,6 +1000,290 @@ export async function uploadFileChunked(
|
|
|
1000
1000
|
};
|
|
1001
1001
|
}
|
|
1002
1002
|
|
|
1003
|
+
// ==========================================
|
|
1004
|
+
// VOICE TRANSCRIPT CHUNKED AUDIO UPLOAD
|
|
1005
|
+
// ==========================================
|
|
1006
|
+
|
|
1007
|
+
/** EGDesk Voice Transcript MCP allowlist max (must match desktop audio-path.ts). */
|
|
1008
|
+
const VOICE_TRANSCRIPT_MAX_AUDIO_BYTES = 80 * 1024 * 1024;
|
|
1009
|
+
|
|
1010
|
+
const VOICE_TRANSCRIPT_AUDIO_EXTENSIONS = [
|
|
1011
|
+
'.wav',
|
|
1012
|
+
'.mp3',
|
|
1013
|
+
'.m4a',
|
|
1014
|
+
'.aac',
|
|
1015
|
+
'.ogg',
|
|
1016
|
+
'.webm',
|
|
1017
|
+
'.flac',
|
|
1018
|
+
];
|
|
1019
|
+
|
|
1020
|
+
export type UploadVoiceTranscriptAudioOptions = {
|
|
1021
|
+
mimeType?: string;
|
|
1022
|
+
onProgress?: (p: { sentBytes: number; totalBytes: number; sentChunks: number; totalChunks: number }) => void;
|
|
1023
|
+
signal?: AbortSignal;
|
|
1024
|
+
parallelism?: number;
|
|
1025
|
+
};
|
|
1026
|
+
|
|
1027
|
+
export type VoiceTranscriptAudioUploadResult = {
|
|
1028
|
+
success: true;
|
|
1029
|
+
uploadId: string;
|
|
1030
|
+
filePath: string;
|
|
1031
|
+
state: string;
|
|
1032
|
+
sha256?: string;
|
|
1033
|
+
filename: string;
|
|
1034
|
+
resumed?: boolean;
|
|
1035
|
+
};
|
|
1036
|
+
|
|
1037
|
+
function assertVoiceTranscriptFilename(filename: string): void {
|
|
1038
|
+
const lower = filename.toLowerCase();
|
|
1039
|
+
const ok = VOICE_TRANSCRIPT_AUDIO_EXTENSIONS.some((ext) => lower.endsWith(ext));
|
|
1040
|
+
if (!ok) {
|
|
1041
|
+
throw new Error(
|
|
1042
|
+
\`Unsupported audio extension for "\${filename}". Allowed: \${VOICE_TRANSCRIPT_AUDIO_EXTENSIONS.join(', ')}\`,
|
|
1043
|
+
);
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
/**
|
|
1048
|
+
* Chunked upload for call/meeting audio (tunnel-safe). Proxies to /api/voice-transcript/uploads/*
|
|
1049
|
+
* and returns an absolute file_path on the EGDesk machine for voice_transcript_transcribe.
|
|
1050
|
+
*/
|
|
1051
|
+
export async function uploadVoiceTranscriptAudioChunked(
|
|
1052
|
+
file: Blob | File,
|
|
1053
|
+
options: UploadVoiceTranscriptAudioOptions = {},
|
|
1054
|
+
): Promise<VoiceTranscriptAudioUploadResult> {
|
|
1055
|
+
if (typeof window === 'undefined') {
|
|
1056
|
+
throw new Error(
|
|
1057
|
+
'uploadVoiceTranscriptAudioChunked() is browser-only. On the server, POST to MCP /voice-transcript/uploads directly.',
|
|
1058
|
+
);
|
|
1059
|
+
}
|
|
1060
|
+
const filename = (file as File).name || \`recording-\${Date.now()}.m4a\`;
|
|
1061
|
+
assertVoiceTranscriptFilename(filename);
|
|
1062
|
+
const mimeType = options.mimeType || file.type || 'application/octet-stream';
|
|
1063
|
+
const totalBytes = file.size;
|
|
1064
|
+
if (totalBytes <= 0) throw new Error('Audio file is empty.');
|
|
1065
|
+
if (totalBytes > VOICE_TRANSCRIPT_MAX_AUDIO_BYTES) {
|
|
1066
|
+
throw new Error(
|
|
1067
|
+
\`Audio is too large (\${totalBytes} bytes). Max \${VOICE_TRANSCRIPT_MAX_AUDIO_BYTES} bytes (80 MB).\`,
|
|
1068
|
+
);
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
const lastModified = Number((file as File).lastModified) || 0;
|
|
1072
|
+
const resumeKey = \`egdesk_voice_chunked_upload:\${filename}|\${totalBytes}|\${lastModified}\`;
|
|
1073
|
+
const readResume = (): string => {
|
|
1074
|
+
try {
|
|
1075
|
+
return localStorage.getItem(resumeKey) || '';
|
|
1076
|
+
} catch {
|
|
1077
|
+
return '';
|
|
1078
|
+
}
|
|
1079
|
+
};
|
|
1080
|
+
const writeResume = (id: string) => {
|
|
1081
|
+
try {
|
|
1082
|
+
localStorage.setItem(resumeKey, id);
|
|
1083
|
+
} catch {
|
|
1084
|
+
// ignore
|
|
1085
|
+
}
|
|
1086
|
+
};
|
|
1087
|
+
const clearResume = () => {
|
|
1088
|
+
try {
|
|
1089
|
+
localStorage.removeItem(resumeKey);
|
|
1090
|
+
} catch {
|
|
1091
|
+
// ignore
|
|
1092
|
+
}
|
|
1093
|
+
};
|
|
1094
|
+
|
|
1095
|
+
const apiBase = '/api/voice-transcript/uploads';
|
|
1096
|
+
|
|
1097
|
+
let uploadId = readResume();
|
|
1098
|
+
let chunkSize = 0;
|
|
1099
|
+
let totalChunks = 0;
|
|
1100
|
+
|
|
1101
|
+
if (uploadId) {
|
|
1102
|
+
const statusRes = await apiFetch(\`\${apiBase}/\${uploadId}\`, { signal: options.signal });
|
|
1103
|
+
const statusJson = await statusRes.json().catch(() => ({}));
|
|
1104
|
+
if (
|
|
1105
|
+
statusRes.ok &&
|
|
1106
|
+
statusJson.success !== false &&
|
|
1107
|
+
(statusJson.state === 'receiving' || statusJson.state === 'finalizing') &&
|
|
1108
|
+
Number(statusJson.size) === totalBytes
|
|
1109
|
+
) {
|
|
1110
|
+
chunkSize = Number(statusJson.chunkSize);
|
|
1111
|
+
totalChunks = Number(statusJson.totalChunks || Math.ceil(totalBytes / chunkSize));
|
|
1112
|
+
} else if (statusRes.ok && statusJson.state === 'done' && (statusJson.filePath || statusJson.file?.filePath)) {
|
|
1113
|
+
clearResume();
|
|
1114
|
+
const filePath = String(statusJson.filePath || statusJson.file?.filePath);
|
|
1115
|
+
return {
|
|
1116
|
+
success: true,
|
|
1117
|
+
uploadId,
|
|
1118
|
+
filePath,
|
|
1119
|
+
state: 'done',
|
|
1120
|
+
sha256: statusJson.sha256,
|
|
1121
|
+
filename,
|
|
1122
|
+
resumed: true,
|
|
1123
|
+
};
|
|
1124
|
+
} else {
|
|
1125
|
+
clearResume();
|
|
1126
|
+
uploadId = '';
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
if (!uploadId) {
|
|
1131
|
+
const initRes = await apiFetch(apiBase, {
|
|
1132
|
+
method: 'POST',
|
|
1133
|
+
headers: { 'Content-Type': 'application/json' },
|
|
1134
|
+
body: JSON.stringify({ filename, size: totalBytes, mimeType }),
|
|
1135
|
+
signal: options.signal,
|
|
1136
|
+
});
|
|
1137
|
+
const initJson = await initRes.json();
|
|
1138
|
+
if (!initRes.ok || initJson.success === false) {
|
|
1139
|
+
throw new Error(initJson.error || initJson.message || \`Init upload failed (HTTP \${initRes.status})\`);
|
|
1140
|
+
}
|
|
1141
|
+
uploadId = String(initJson.uploadId);
|
|
1142
|
+
chunkSize = Number(initJson.chunkSize);
|
|
1143
|
+
totalChunks = Number(initJson.totalChunks || Math.ceil(totalBytes / chunkSize));
|
|
1144
|
+
writeResume(uploadId);
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
const parallelism = Math.max(1, Math.min(options.parallelism ?? 3, 3));
|
|
1148
|
+
const statusRes = await apiFetch(\`\${apiBase}/\${uploadId}\`, { signal: options.signal });
|
|
1149
|
+
const statusJson = await statusRes.json().catch(() => ({}));
|
|
1150
|
+
const already = new Set<number>(Array.isArray(statusJson.received) ? statusJson.received : []);
|
|
1151
|
+
|
|
1152
|
+
let sentBytes = Math.min(totalBytes, already.size * chunkSize);
|
|
1153
|
+
let sentChunks = already.size;
|
|
1154
|
+
options.onProgress?.({ sentBytes, totalBytes, sentChunks, totalChunks });
|
|
1155
|
+
|
|
1156
|
+
const pending: number[] = [];
|
|
1157
|
+
for (let i = 0; i < totalChunks; i++) {
|
|
1158
|
+
if (!already.has(i)) pending.push(i);
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
1162
|
+
const backoffs = [500, 1500, 4000];
|
|
1163
|
+
|
|
1164
|
+
async function putOne(index: number): Promise<void> {
|
|
1165
|
+
const start = index * chunkSize;
|
|
1166
|
+
const end = Math.min(start + chunkSize, totalBytes);
|
|
1167
|
+
const slice = file.slice(start, end);
|
|
1168
|
+
const buf = await slice.arrayBuffer();
|
|
1169
|
+
const sha = await sha256Hex(buf);
|
|
1170
|
+
let lastErr: Error | null = null;
|
|
1171
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
1172
|
+
if (options.signal?.aborted) throw new Error('Upload aborted');
|
|
1173
|
+
try {
|
|
1174
|
+
const res = await apiFetch(\`\${apiBase}/\${uploadId}/chunks/\${index}\`, {
|
|
1175
|
+
method: 'PUT',
|
|
1176
|
+
headers: {
|
|
1177
|
+
'Content-Type': 'application/octet-stream',
|
|
1178
|
+
'x-chunk-sha256': sha,
|
|
1179
|
+
},
|
|
1180
|
+
body: buf,
|
|
1181
|
+
signal: options.signal,
|
|
1182
|
+
});
|
|
1183
|
+
const json = await res.json().catch(() => ({}));
|
|
1184
|
+
if (res.status === 401 && attempt < 2) {
|
|
1185
|
+
await sleep(backoffs[attempt]);
|
|
1186
|
+
continue;
|
|
1187
|
+
}
|
|
1188
|
+
if (!res.ok || json.success === false) {
|
|
1189
|
+
throw new Error(json.error || json.message || \`Chunk \${index} failed (HTTP \${res.status})\`);
|
|
1190
|
+
}
|
|
1191
|
+
sentChunks += 1;
|
|
1192
|
+
sentBytes = Math.min(totalBytes, sentBytes + (end - start));
|
|
1193
|
+
options.onProgress?.({ sentBytes, totalBytes, sentChunks, totalChunks });
|
|
1194
|
+
return;
|
|
1195
|
+
} catch (e: any) {
|
|
1196
|
+
lastErr = e instanceof Error ? e : new Error(String(e));
|
|
1197
|
+
if (attempt < 2) await sleep(backoffs[attempt]);
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
throw lastErr || new Error(\`Chunk \${index} failed\`);
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
let cursor = 0;
|
|
1204
|
+
async function worker() {
|
|
1205
|
+
while (cursor < pending.length) {
|
|
1206
|
+
const idx = pending[cursor++];
|
|
1207
|
+
await putOne(idx);
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
await Promise.all(Array.from({ length: Math.min(parallelism, pending.length || 1) }, () => worker()));
|
|
1211
|
+
|
|
1212
|
+
const completeRes = await apiFetch(\`\${apiBase}/\${uploadId}/complete\`, {
|
|
1213
|
+
method: 'POST',
|
|
1214
|
+
headers: { 'Content-Type': 'application/json' },
|
|
1215
|
+
body: '{}',
|
|
1216
|
+
signal: options.signal,
|
|
1217
|
+
});
|
|
1218
|
+
let completeJson = await completeRes.json();
|
|
1219
|
+
if (!completeRes.ok && completeRes.status !== 202) {
|
|
1220
|
+
throw new Error(completeJson.error || completeJson.message || \`Complete failed (HTTP \${completeRes.status})\`);
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
if (completeJson.state === 'finalizing' || completeRes.status === 202) {
|
|
1224
|
+
for (let i = 0; i < 600; i++) {
|
|
1225
|
+
if (options.signal?.aborted) throw new Error('Upload aborted');
|
|
1226
|
+
await sleep(500);
|
|
1227
|
+
const st = await apiFetch(\`\${apiBase}/\${uploadId}\`, { signal: options.signal });
|
|
1228
|
+
const sj = await st.json();
|
|
1229
|
+
if (sj.state === 'done') {
|
|
1230
|
+
completeJson = sj;
|
|
1231
|
+
break;
|
|
1232
|
+
}
|
|
1233
|
+
if (sj.state === 'failed') {
|
|
1234
|
+
throw new Error(sj.error || 'Upload finalization failed');
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
if (completeJson.state !== 'done') {
|
|
1238
|
+
throw new Error('Timed out waiting for voice upload finalization');
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
const filePath = String(
|
|
1243
|
+
completeJson.filePath || completeJson.file?.filePath || '',
|
|
1244
|
+
);
|
|
1245
|
+
if (!filePath) {
|
|
1246
|
+
throw new Error('Upload completed but filePath was missing from the response.');
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
clearResume();
|
|
1250
|
+
return {
|
|
1251
|
+
success: true,
|
|
1252
|
+
uploadId,
|
|
1253
|
+
filePath,
|
|
1254
|
+
state: completeJson.state || 'done',
|
|
1255
|
+
sha256: completeJson.sha256,
|
|
1256
|
+
filename,
|
|
1257
|
+
};
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
/**
|
|
1261
|
+
* Upload audio for Voice Transcript (browser). Uses chunked upload for tunnel safety.
|
|
1262
|
+
* Pass a File from a file picker (accept audio/*) or a Blob with a name.
|
|
1263
|
+
*/
|
|
1264
|
+
export async function uploadVoiceTranscriptAudio(
|
|
1265
|
+
file: Blob | File,
|
|
1266
|
+
options: UploadVoiceTranscriptAudioOptions = {},
|
|
1267
|
+
): Promise<VoiceTranscriptAudioUploadResult> {
|
|
1268
|
+
return uploadVoiceTranscriptAudioChunked(file, options);
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
/**
|
|
1272
|
+
* Upload audio from a Base64 or data-URL string (browser). Files larger than 4 MiB decoded
|
|
1273
|
+
* use the chunked path automatically.
|
|
1274
|
+
*/
|
|
1275
|
+
export async function uploadVoiceTranscriptAudioFromBase64(
|
|
1276
|
+
filename: string,
|
|
1277
|
+
data: string,
|
|
1278
|
+
options: UploadVoiceTranscriptAudioOptions = {},
|
|
1279
|
+
): Promise<VoiceTranscriptAudioUploadResult> {
|
|
1280
|
+
assertVoiceTranscriptFilename(filename);
|
|
1281
|
+
const bytes = base64ToUint8Array(data);
|
|
1282
|
+
const blob = new Blob([bytes], { type: options.mimeType || 'application/octet-stream' });
|
|
1283
|
+
const file = new File([blob], filename, { type: options.mimeType || blob.type });
|
|
1284
|
+
return uploadVoiceTranscriptAudioChunked(file, options);
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1003
1287
|
/**
|
|
1004
1288
|
* Upload a file attachment for a table row.
|
|
1005
1289
|
* Files are NOT table columns — they attach via a virtual columnName (e.g. "file").
|
|
@@ -3853,6 +4137,43 @@ export async function renameDriveFile(fileId: string, name: string, preferOAuth?
|
|
|
3853
4137
|
return callDriveTool('drive_rename', { fileId, name, preferOAuth });
|
|
3854
4138
|
}
|
|
3855
4139
|
|
|
4140
|
+
/** Invite a Google user to a Drive file or folder. Default preferOAuth: true. */
|
|
4141
|
+
export async function shareDriveFile(options: {
|
|
4142
|
+
fileId: string;
|
|
4143
|
+
shareType?: 'user' | 'anyone' | 'domain';
|
|
4144
|
+
email?: string;
|
|
4145
|
+
domain?: string;
|
|
4146
|
+
role?: 'reader' | 'writer' | 'commenter';
|
|
4147
|
+
allowFileDiscovery?: boolean;
|
|
4148
|
+
sendNotificationEmail?: boolean;
|
|
4149
|
+
preferOAuth?: boolean;
|
|
4150
|
+
}) {
|
|
4151
|
+
const preferOAuth = options.preferOAuth ?? true;
|
|
4152
|
+
return callDriveTool('drive_share_file', { ...options, preferOAuth }, { preferOAuth });
|
|
4153
|
+
}
|
|
4154
|
+
|
|
4155
|
+
/** List non-owner permissions on a Drive file or folder. Default preferOAuth: true. */
|
|
4156
|
+
export async function listDriveFilePermissions(
|
|
4157
|
+
fileId: string,
|
|
4158
|
+
options: WorkspaceVisitorCallOptions = {},
|
|
4159
|
+
) {
|
|
4160
|
+
const preferOAuth = options.preferOAuth ?? true;
|
|
4161
|
+
return callDriveTool('drive_list_file_permissions', { fileId, preferOAuth }, { ...options, preferOAuth });
|
|
4162
|
+
}
|
|
4163
|
+
|
|
4164
|
+
/** Remove a collaborator by permissionId or email. Default preferOAuth: true. */
|
|
4165
|
+
export async function revokeDriveFileAccess(options: {
|
|
4166
|
+
fileId: string;
|
|
4167
|
+
permissionId?: string;
|
|
4168
|
+
email?: string;
|
|
4169
|
+
shareType?: 'anyone' | 'domain';
|
|
4170
|
+
domain?: string;
|
|
4171
|
+
preferOAuth?: boolean;
|
|
4172
|
+
}) {
|
|
4173
|
+
const preferOAuth = options.preferOAuth ?? true;
|
|
4174
|
+
return callDriveTool('drive_revoke_file_access', { ...options, preferOAuth }, { preferOAuth });
|
|
4175
|
+
}
|
|
4176
|
+
|
|
3856
4177
|
/** Move a Drive file or folder to trash. Pass preferOAuth: true to act as the signed-in Google user. */
|
|
3857
4178
|
export async function trashDriveFile(fileId: string, preferOAuth?: boolean) {
|
|
3858
4179
|
return callDriveTool('drive_trash', { fileId, preferOAuth });
|
|
@@ -121,6 +121,19 @@ function resolveEgdeskMcpApiUrl(): string {
|
|
|
121
121
|
return (process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080').replace(/\\/$/, '');
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Visitor OAuth state is on the tunnel gateway (Supabase), not desktop in-memory pending.
|
|
126
|
+
*/
|
|
127
|
+
function resolveVisitorAuthMcpApiUrl(): string {
|
|
128
|
+
const tunnel = process.env.NEXT_PUBLIC_EGDESK_TUNNEL_URL;
|
|
129
|
+
if (tunnel && tunnel.trim()) return tunnel.replace(/\\/$/, '');
|
|
130
|
+
const publicUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL;
|
|
131
|
+
if (publicUrl && publicUrl.trim()) return publicUrl.replace(/\\/$/, '');
|
|
132
|
+
const internal = process.env.EGDESK_MCP_INTERNAL_URL;
|
|
133
|
+
if (internal && internal.trim()) return internal.replace(/\\/$/, '');
|
|
134
|
+
return 'http://localhost:8080';
|
|
135
|
+
}
|
|
136
|
+
|
|
124
137
|
export async function middleware(request: NextRequest) {
|
|
125
138
|
const { pathname } = request.nextUrl;
|
|
126
139
|
|
|
@@ -446,7 +459,7 @@ export async function middleware(request: NextRequest) {
|
|
|
446
459
|
if (pathname.includes('__visitor_auth_proxy')) {
|
|
447
460
|
try {
|
|
448
461
|
const body = await request.text();
|
|
449
|
-
const apiUrl =
|
|
462
|
+
const apiUrl = resolveVisitorAuthMcpApiUrl();
|
|
450
463
|
|
|
451
464
|
const response = await fetch(\`\${apiUrl}/visitor-auth/tools/call\`, {
|
|
452
465
|
method: 'POST',
|
|
@@ -466,7 +479,7 @@ export async function middleware(request: NextRequest) {
|
|
|
466
479
|
if (pathname.includes('__visitor_google_proxy')) {
|
|
467
480
|
try {
|
|
468
481
|
const body = await request.text();
|
|
469
|
-
const apiUrl =
|
|
482
|
+
const apiUrl = resolveVisitorAuthMcpApiUrl();
|
|
470
483
|
const headers = visitorUpstreamHeaders(request);
|
|
471
484
|
const authorization = request.headers.get('authorization');
|
|
472
485
|
if (authorization) headers['Authorization'] = authorization;
|
package/dist/generate-proxy.js
CHANGED
|
@@ -100,6 +100,20 @@ function resolveEgdeskMcpApiUrl(): string {
|
|
|
100
100
|
return (process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080').replace(/\\/$/, '');
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Visitor OAuth pending rows and sessions live on the tunnel gateway (Supabase).
|
|
105
|
+
* Do not use EGDESK_MCP_INTERNAL_URL here — desktop :8080 only keeps pending in memory.
|
|
106
|
+
*/
|
|
107
|
+
function resolveVisitorAuthMcpApiUrl(): string {
|
|
108
|
+
const tunnel = process.env.NEXT_PUBLIC_EGDESK_TUNNEL_URL;
|
|
109
|
+
if (tunnel && tunnel.trim()) return tunnel.replace(/\\/$/, '');
|
|
110
|
+
const publicUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL;
|
|
111
|
+
if (publicUrl && publicUrl.trim()) return publicUrl.replace(/\\/$/, '');
|
|
112
|
+
const internal = process.env.EGDESK_MCP_INTERNAL_URL;
|
|
113
|
+
if (internal && internal.trim()) return internal.replace(/\\/$/, '');
|
|
114
|
+
return 'http://localhost:8080';
|
|
115
|
+
}
|
|
116
|
+
|
|
103
117
|
/** Forward this site's origin so EGDesk can bind visitor sessions to this site only. */
|
|
104
118
|
function visitorForwardHeaders(request: NextRequest): Record<string, string> {
|
|
105
119
|
const headers = buildEgdeskHeaders();
|
|
@@ -800,7 +814,7 @@ export async function proxy(request: NextRequest) {
|
|
|
800
814
|
if (pathname.includes('__visitor_auth_proxy')) {
|
|
801
815
|
try {
|
|
802
816
|
const body = await request.text();
|
|
803
|
-
const apiUrl =
|
|
817
|
+
const apiUrl = resolveVisitorAuthMcpApiUrl();
|
|
804
818
|
|
|
805
819
|
const response = await fetch(\`\${apiUrl}/visitor-auth/tools/call\`, {
|
|
806
820
|
method: 'POST',
|
|
@@ -822,7 +836,7 @@ export async function proxy(request: NextRequest) {
|
|
|
822
836
|
if (pathname.includes('__visitor_google_proxy')) {
|
|
823
837
|
try {
|
|
824
838
|
const body = await request.text();
|
|
825
|
-
const apiUrl =
|
|
839
|
+
const apiUrl = resolveVisitorAuthMcpApiUrl();
|
|
826
840
|
const headers = visitorForwardHeaders(request);
|
|
827
841
|
const authorization = request.headers.get('authorization');
|
|
828
842
|
if (authorization) headers['Authorization'] = authorization;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* The minimum EGDesk app version this plugin version is compatible with.
|
|
9
9
|
* The app checks this at setup time and warns on mismatch.
|
|
10
10
|
*/
|
|
11
|
-
export declare const COMPATIBLE_APP_VERSION = "1.4.
|
|
11
|
+
export declare const COMPATIBLE_APP_VERSION = "1.4.113";
|
|
12
12
|
export interface SetupOptions {
|
|
13
13
|
egdeskUrl?: string;
|
|
14
14
|
/** Production EGDesk server URL — written to .env.production.local. Falls back to egdeskUrl. */
|
|
@@ -40,7 +40,7 @@ export type { UserDataTable, UserDataConfig } from './setup-userdata';
|
|
|
40
40
|
export { discoverTables, generateConfigFile, loadTablesFromSchemaFile, updateEnvFiles } from './setup-userdata';
|
|
41
41
|
export { generateMiddleware } from './generate-middleware';
|
|
42
42
|
export { generateProxy } from './generate-proxy';
|
|
43
|
-
export { generateChunkedUploadRoutes } from './generate-chunked-upload-routes';
|
|
43
|
+
export { generateChunkedUploadRoutes, generateVoiceTranscriptChunkedUploadRoutes, } from './generate-chunked-upload-routes';
|
|
44
44
|
export { generateHelpers, generateSchemaFile, ensureSchemaFile, formatEgdeskSchemaFileContent } from './generate-helpers';
|
|
45
45
|
export type { SchemaTableDefinition, EnsureSchemaFileResult, GenerateHelpersOptions } from './generate-helpers';
|
|
46
46
|
export { generateApiWrapper } from './generate-api-wrapper';
|
package/dist/index.js
CHANGED
|
@@ -39,14 +39,14 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
39
39
|
};
|
|
40
40
|
})();
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.ensureVisitorAuthConfig = exports.generateVisitorAuth = exports.generateApiWrapper = exports.formatEgdeskSchemaFileContent = exports.ensureSchemaFile = exports.generateSchemaFile = exports.generateHelpers = exports.generateChunkedUploadRoutes = exports.generateProxy = exports.generateMiddleware = exports.updateEnvFiles = exports.loadTablesFromSchemaFile = exports.generateConfigFile = exports.discoverTables = exports.COMPATIBLE_APP_VERSION = void 0;
|
|
42
|
+
exports.ensureVisitorAuthConfig = exports.generateVisitorAuth = exports.generateApiWrapper = exports.formatEgdeskSchemaFileContent = exports.ensureSchemaFile = exports.generateSchemaFile = exports.generateHelpers = exports.generateVoiceTranscriptChunkedUploadRoutes = exports.generateChunkedUploadRoutes = exports.generateProxy = exports.generateMiddleware = exports.updateEnvFiles = exports.loadTablesFromSchemaFile = exports.generateConfigFile = exports.discoverTables = exports.COMPATIBLE_APP_VERSION = void 0;
|
|
43
43
|
exports.detectNextUseProxy = detectNextUseProxy;
|
|
44
44
|
exports.setupNextApiPlugin = setupNextApiPlugin;
|
|
45
45
|
/**
|
|
46
46
|
* The minimum EGDesk app version this plugin version is compatible with.
|
|
47
47
|
* The app checks this at setup time and warns on mismatch.
|
|
48
48
|
*/
|
|
49
|
-
exports.COMPATIBLE_APP_VERSION = '1.4.
|
|
49
|
+
exports.COMPATIBLE_APP_VERSION = '1.4.113';
|
|
50
50
|
const fs = __importStar(require("fs"));
|
|
51
51
|
const path = __importStar(require("path"));
|
|
52
52
|
const setup_userdata_1 = require("./setup-userdata");
|
|
@@ -188,6 +188,7 @@ async function setupNextApiPlugin(projectPath, options = {}) {
|
|
|
188
188
|
})));
|
|
189
189
|
(0, generate_helpers_1.generateHelpers)(projectPath, { apiKeyNames });
|
|
190
190
|
(0, generate_chunked_upload_routes_1.generateChunkedUploadRoutes)(projectPath);
|
|
191
|
+
(0, generate_chunked_upload_routes_1.generateVoiceTranscriptChunkedUploadRoutes)(projectPath);
|
|
191
192
|
(0, generate_api_wrapper_1.generateApiWrapper)(projectPath);
|
|
192
193
|
(0, generate_visitor_auth_1.generateVisitorAuth)(projectPath);
|
|
193
194
|
(0, setup_userdata_1.updateEnvFiles)(projectPath, config, prodTables);
|
|
@@ -198,7 +199,8 @@ async function setupNextApiPlugin(projectPath, options = {}) {
|
|
|
198
199
|
console.log(' - egdesk.config.ts (type-safe config)');
|
|
199
200
|
console.log(' - egdesk.schema.ts (committed seed schema — add to git if newly created)');
|
|
200
201
|
console.log(' - egdesk-helpers.ts (helper functions)');
|
|
201
|
-
console.log(' - app/api/user/files/uploads/* (chunked
|
|
202
|
+
console.log(' - app/api/user/files/uploads/* (chunked My DB file uploads)');
|
|
203
|
+
console.log(' - app/api/voice-transcript/uploads/* (chunked Voice Transcript audio)');
|
|
202
204
|
console.log(' - egdesk-visitor-google.ts (generated visitor Google helper — do not edit)');
|
|
203
205
|
console.log(' - egdesk.visitor-auth.ts (site-owned login defaults; never overwritten)');
|
|
204
206
|
console.log(' - src/lib/api.ts (basePath-aware fetch wrapper)');
|
|
@@ -242,6 +244,7 @@ var generate_proxy_2 = require("./generate-proxy");
|
|
|
242
244
|
Object.defineProperty(exports, "generateProxy", { enumerable: true, get: function () { return generate_proxy_2.generateProxy; } });
|
|
243
245
|
var generate_chunked_upload_routes_2 = require("./generate-chunked-upload-routes");
|
|
244
246
|
Object.defineProperty(exports, "generateChunkedUploadRoutes", { enumerable: true, get: function () { return generate_chunked_upload_routes_2.generateChunkedUploadRoutes; } });
|
|
247
|
+
Object.defineProperty(exports, "generateVoiceTranscriptChunkedUploadRoutes", { enumerable: true, get: function () { return generate_chunked_upload_routes_2.generateVoiceTranscriptChunkedUploadRoutes; } });
|
|
245
248
|
var generate_helpers_2 = require("./generate-helpers");
|
|
246
249
|
Object.defineProperty(exports, "generateHelpers", { enumerable: true, get: function () { return generate_helpers_2.generateHelpers; } });
|
|
247
250
|
Object.defineProperty(exports, "generateSchemaFile", { enumerable: true, get: function () { return generate_helpers_2.generateSchemaFile; } });
|