@speakableio/core 1.0.12 → 1.0.14
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/index.native.d.mts +26 -6
- package/dist/index.native.d.ts +26 -6
- package/dist/index.native.js +96 -16
- package/dist/index.native.js.map +1 -1
- package/dist/index.native.mjs +96 -16
- package/dist/index.native.mjs.map +1 -1
- package/dist/index.web.d.mts +26 -6
- package/dist/index.web.js +96 -16
- package/dist/index.web.js.map +1 -1
- package/package.json +1 -1
package/dist/index.native.mjs
CHANGED
|
@@ -47,6 +47,8 @@ function withErrorHandler(fn, serviceName) {
|
|
|
47
47
|
try {
|
|
48
48
|
return await fn(...args);
|
|
49
49
|
} catch (error) {
|
|
50
|
+
console.error(`Service ${serviceName} failed with args:`, args);
|
|
51
|
+
console.error("Error details:", error);
|
|
50
52
|
if (error instanceof Error && "code" in error) {
|
|
51
53
|
const firebaseError = error;
|
|
52
54
|
throw new ServiceError(
|
|
@@ -1143,6 +1145,39 @@ async function clearScore(params) {
|
|
|
1143
1145
|
activityId: params.activityId
|
|
1144
1146
|
};
|
|
1145
1147
|
}
|
|
1148
|
+
async function clearScoreV2(params) {
|
|
1149
|
+
var _a, _b, _c, _d, _e;
|
|
1150
|
+
const update = {
|
|
1151
|
+
[`cards.${params.cardId}`]: {
|
|
1152
|
+
...params.cardScores,
|
|
1153
|
+
attempts: ((_a = params.cardScores.attempts) != null ? _a : 1) + 1,
|
|
1154
|
+
correct: (_b = params.cardScores.correct) != null ? _b : 0,
|
|
1155
|
+
history: [
|
|
1156
|
+
{
|
|
1157
|
+
...params.cardScores,
|
|
1158
|
+
attempts: (_c = params.cardScores.attempts) != null ? _c : 1,
|
|
1159
|
+
correct: (_d = params.cardScores.correct) != null ? _d : 0,
|
|
1160
|
+
retryTime: dayjs3().format("YYYY-MM-DD HH:mm:ss"),
|
|
1161
|
+
history: null
|
|
1162
|
+
},
|
|
1163
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
1164
|
+
...(_e = params.cardScores.history) != null ? _e : []
|
|
1165
|
+
]
|
|
1166
|
+
}
|
|
1167
|
+
};
|
|
1168
|
+
const path = params.isAssignment ? refsAssignmentFiresotre.assignmentScores({
|
|
1169
|
+
id: params.activityId,
|
|
1170
|
+
userId: params.userId
|
|
1171
|
+
}) : refsScoresPractice.practiceScores({
|
|
1172
|
+
setId: params.activityId,
|
|
1173
|
+
userId: params.userId
|
|
1174
|
+
});
|
|
1175
|
+
await api.updateDoc(path, update);
|
|
1176
|
+
return {
|
|
1177
|
+
update,
|
|
1178
|
+
activityId: params.activityId
|
|
1179
|
+
};
|
|
1180
|
+
}
|
|
1146
1181
|
|
|
1147
1182
|
// src/domains/assignment/services/submit-assignment-score.service.ts
|
|
1148
1183
|
import dayjs4 from "dayjs";
|
|
@@ -1255,7 +1290,7 @@ function useScore({
|
|
|
1255
1290
|
enabled
|
|
1256
1291
|
});
|
|
1257
1292
|
}
|
|
1258
|
-
var debounceUpdateScore = debounce(updateScore,
|
|
1293
|
+
var debounceUpdateScore = debounce(updateScore, 500);
|
|
1259
1294
|
function useUpdateScore() {
|
|
1260
1295
|
const { queryClient } = useSpeakableApi();
|
|
1261
1296
|
const mutation = useMutation({
|
|
@@ -1314,6 +1349,7 @@ function useUpdateCardScore({
|
|
|
1314
1349
|
return { cardId, scoresUpdated: newScoreUpdated };
|
|
1315
1350
|
},
|
|
1316
1351
|
onMutate: ({ cardId, cardScore }) => {
|
|
1352
|
+
const previousData = queryClient.getQueryData(queryKey);
|
|
1317
1353
|
queryClient.setQueryData(queryKey, (previousScore) => {
|
|
1318
1354
|
const updates = handleOptimisticScore({
|
|
1319
1355
|
score: previousScore,
|
|
@@ -1327,14 +1363,18 @@ function useUpdateCardScore({
|
|
|
1327
1363
|
...updates
|
|
1328
1364
|
};
|
|
1329
1365
|
});
|
|
1366
|
+
return { previousData };
|
|
1330
1367
|
},
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
if (previousData) {
|
|
1336
|
-
queryClient.setQueryData(queryKey, previousData);
|
|
1368
|
+
onError: (error, variables, context) => {
|
|
1369
|
+
console.log("Error updating card score:", error.message);
|
|
1370
|
+
if (context == null ? void 0 : context.previousData) {
|
|
1371
|
+
queryClient.setQueryData(queryKey, context.previousData);
|
|
1337
1372
|
}
|
|
1373
|
+
},
|
|
1374
|
+
onSettled: () => {
|
|
1375
|
+
queryClient.invalidateQueries({
|
|
1376
|
+
queryKey
|
|
1377
|
+
});
|
|
1338
1378
|
}
|
|
1339
1379
|
});
|
|
1340
1380
|
return {
|
|
@@ -1400,6 +1440,27 @@ function useClearScore() {
|
|
|
1400
1440
|
const { queryClient } = useSpeakableApi();
|
|
1401
1441
|
const mutation = useMutation({
|
|
1402
1442
|
mutationFn: clearScore,
|
|
1443
|
+
onError: (error) => {
|
|
1444
|
+
console.log("Error clearing score:", error.message);
|
|
1445
|
+
},
|
|
1446
|
+
onSettled: (result) => {
|
|
1447
|
+
var _a;
|
|
1448
|
+
queryClient.invalidateQueries({
|
|
1449
|
+
queryKey: scoreQueryKeys.byId((_a = result == null ? void 0 : result.activityId) != null ? _a : "")
|
|
1450
|
+
});
|
|
1451
|
+
}
|
|
1452
|
+
});
|
|
1453
|
+
return {
|
|
1454
|
+
mutationClearScore: mutation
|
|
1455
|
+
};
|
|
1456
|
+
}
|
|
1457
|
+
function useClearScoreV2() {
|
|
1458
|
+
const { queryClient } = useSpeakableApi();
|
|
1459
|
+
const mutation = useMutation({
|
|
1460
|
+
mutationFn: clearScoreV2,
|
|
1461
|
+
onError: (error) => {
|
|
1462
|
+
console.log("Error clearing score V2:", error.message);
|
|
1463
|
+
},
|
|
1403
1464
|
onSettled: (result) => {
|
|
1404
1465
|
var _a;
|
|
1405
1466
|
queryClient.invalidateQueries({
|
|
@@ -2992,21 +3053,38 @@ var useBaseOpenAI = ({
|
|
|
2992
3053
|
const { data: feedbackAccess } = useActivityFeedbackAccess({
|
|
2993
3054
|
aiEnabled
|
|
2994
3055
|
});
|
|
2995
|
-
const getTranscript = async (audioUrl, language) => {
|
|
2996
|
-
var _a, _b;
|
|
3056
|
+
const getTranscript = async (audioUrl, language, prompt) => {
|
|
3057
|
+
var _a, _b, _c, _d;
|
|
3058
|
+
const getGeminiTranscript = (_b = (_a = api).httpsCallable) == null ? void 0 : _b.call(_a, "getGeminiTranscript");
|
|
3059
|
+
const getAssemblyAITranscript = (_d = (_c = api).httpsCallable) == null ? void 0 : _d.call(_c, "transcribeAssemblyAIAudio");
|
|
3060
|
+
try {
|
|
3061
|
+
const { data } = await (getGeminiTranscript == null ? void 0 : getGeminiTranscript({
|
|
3062
|
+
audioUrl,
|
|
3063
|
+
targetLanguage: language,
|
|
3064
|
+
prompt: prompt || ""
|
|
3065
|
+
}));
|
|
3066
|
+
const transcript = data.transcript;
|
|
3067
|
+
if (transcript) {
|
|
3068
|
+
return transcript;
|
|
3069
|
+
}
|
|
3070
|
+
} catch (error) {
|
|
3071
|
+
console.log("Gemini transcript failed, trying AssemblyAI fallback:", error);
|
|
3072
|
+
}
|
|
2997
3073
|
try {
|
|
2998
|
-
const getAssemblyAITranscript = (_b = (_a = api).httpsCallable) == null ? void 0 : _b.call(_a, "transcribeAssemblyAIAudio");
|
|
2999
3074
|
const response = await (getAssemblyAITranscript == null ? void 0 : getAssemblyAITranscript({
|
|
3000
3075
|
audioUrl,
|
|
3001
3076
|
language
|
|
3002
3077
|
}));
|
|
3003
3078
|
const transcript = response == null ? void 0 : response.data;
|
|
3004
|
-
|
|
3079
|
+
if (transcript) {
|
|
3080
|
+
return transcript;
|
|
3081
|
+
}
|
|
3082
|
+
throw new Error("Both transcript services failed");
|
|
3005
3083
|
} catch (error) {
|
|
3006
|
-
console.log("
|
|
3084
|
+
console.log("AssemblyAI transcript also failed:", error);
|
|
3007
3085
|
onTranscriptError({
|
|
3008
3086
|
type: "TRANSCRIPT",
|
|
3009
|
-
message: (error == null ? void 0 : error.message) || "Error getting transcript"
|
|
3087
|
+
message: (error == null ? void 0 : error.message) || "Error getting transcript from both services"
|
|
3010
3088
|
});
|
|
3011
3089
|
throw new Error(error);
|
|
3012
3090
|
}
|
|
@@ -3061,7 +3139,8 @@ var useBaseOpenAI = ({
|
|
|
3061
3139
|
// if the type = RESPOND_WRITE
|
|
3062
3140
|
audio = null,
|
|
3063
3141
|
autoGrade = true,
|
|
3064
|
-
file = null
|
|
3142
|
+
file = null,
|
|
3143
|
+
pagePrompt = null
|
|
3065
3144
|
}) => {
|
|
3066
3145
|
try {
|
|
3067
3146
|
if (!(feedbackAccess == null ? void 0 : feedbackAccess.canAccessFeedback)) {
|
|
@@ -3081,7 +3160,7 @@ var useBaseOpenAI = ({
|
|
|
3081
3160
|
onTranscriptSuccess(writtenResponse);
|
|
3082
3161
|
} else if (typeof audio === "string" && file) {
|
|
3083
3162
|
if (feedbackAccess == null ? void 0 : feedbackAccess.canAccessFeedback) {
|
|
3084
|
-
transcript = await getTranscript(audio, language);
|
|
3163
|
+
transcript = await getTranscript(audio, language, pagePrompt != null ? pagePrompt : "");
|
|
3085
3164
|
audioUrl = audio;
|
|
3086
3165
|
onTranscriptSuccess(transcript);
|
|
3087
3166
|
} else {
|
|
@@ -3090,7 +3169,7 @@ var useBaseOpenAI = ({
|
|
|
3090
3169
|
);
|
|
3091
3170
|
}
|
|
3092
3171
|
} else {
|
|
3093
|
-
const response = await uploadAudioAndGetTranscript(audio || "", language);
|
|
3172
|
+
const response = await uploadAudioAndGetTranscript(audio || "", language, pagePrompt != null ? pagePrompt : "");
|
|
3094
3173
|
transcript = response.transcript;
|
|
3095
3174
|
audioUrl = response.audioUrl;
|
|
3096
3175
|
}
|
|
@@ -3320,6 +3399,7 @@ export {
|
|
|
3320
3399
|
useBaseOpenAI,
|
|
3321
3400
|
useCards,
|
|
3322
3401
|
useClearScore,
|
|
3402
|
+
useClearScoreV2,
|
|
3323
3403
|
useCreateCard,
|
|
3324
3404
|
useCreateCards,
|
|
3325
3405
|
useCreateNotification,
|