@speakableio/core 1.0.13 → 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 +13 -5
- package/dist/index.native.d.ts +13 -5
- package/dist/index.native.js +47 -16
- package/dist/index.native.js.map +1 -1
- package/dist/index.native.mjs +47 -16
- package/dist/index.native.mjs.map +1 -1
- package/dist/index.web.d.mts +13 -5
- package/dist/index.web.js +47 -16
- package/dist/index.web.js.map +1 -1
- package/package.json +1 -1
package/dist/index.web.d.mts
CHANGED
|
@@ -772,6 +772,11 @@ interface PageScore {
|
|
|
772
772
|
hint?: string[];
|
|
773
773
|
reviewed?: boolean;
|
|
774
774
|
error?: ('feedback_error' | 'transcript_error' | 'summary_error' | 'audio_upload_error' | 'unknown' | null)[];
|
|
775
|
+
stagedResponse?: {
|
|
776
|
+
audio?: string | null;
|
|
777
|
+
fileName?: string | null;
|
|
778
|
+
transcript?: string | null;
|
|
779
|
+
} | null;
|
|
775
780
|
}
|
|
776
781
|
|
|
777
782
|
declare enum AssignmentAnalyticsType {
|
|
@@ -993,7 +998,9 @@ declare function useUpdateCardScore({ isAssignment, activityId, userId, cardIds,
|
|
|
993
998
|
}, Error, {
|
|
994
999
|
cardId: string;
|
|
995
1000
|
cardScore: PageScore;
|
|
996
|
-
},
|
|
1001
|
+
}, {
|
|
1002
|
+
previousData: Score | undefined;
|
|
1003
|
+
}>;
|
|
997
1004
|
};
|
|
998
1005
|
declare function useClearScore(): {
|
|
999
1006
|
mutationClearScore: _tanstack_react_query.UseMutationResult<{
|
|
@@ -2772,7 +2779,7 @@ declare const useBaseOpenAI: ({ onTranscriptSuccess, onTranscriptError, onComple
|
|
|
2772
2779
|
url: string;
|
|
2773
2780
|
fileName: string;
|
|
2774
2781
|
}>;
|
|
2775
|
-
uploadAudioAndGetTranscript: (audio: string, language: string) => Promise<{
|
|
2782
|
+
uploadAudioAndGetTranscript: (audio: string, language: string, pagePrompt: string | null) => Promise<{
|
|
2776
2783
|
transcript: string;
|
|
2777
2784
|
audioUrl: string;
|
|
2778
2785
|
}>;
|
|
@@ -2785,19 +2792,20 @@ declare const useBaseOpenAI: ({ onTranscriptSuccess, onTranscriptError, onComple
|
|
|
2785
2792
|
url: string;
|
|
2786
2793
|
fileName: string;
|
|
2787
2794
|
}>;
|
|
2788
|
-
uploadAudioAndGetTranscript: (audio: string, language: string) => Promise<{
|
|
2795
|
+
uploadAudioAndGetTranscript: (audio: string, language: string, pagePrompt: string | null) => Promise<{
|
|
2789
2796
|
transcript: string;
|
|
2790
2797
|
audioUrl: string;
|
|
2791
2798
|
}>;
|
|
2792
|
-
getTranscript: (audioUrl: string, language: string) => Promise<
|
|
2799
|
+
getTranscript: (audioUrl: string, language: string, prompt?: string) => Promise<any>;
|
|
2793
2800
|
getFreeResponseCompletion: (messages: string[], isFreeResponse: boolean, feedbackLanguage: string, gradingStandard?: string) => Promise<any>;
|
|
2794
|
-
getFeedback: ({ cardId, language, writtenResponse, audio, autoGrade, file, }: {
|
|
2801
|
+
getFeedback: ({ cardId, language, writtenResponse, audio, autoGrade, file, pagePrompt, }: {
|
|
2795
2802
|
cardId: string;
|
|
2796
2803
|
language: string;
|
|
2797
2804
|
writtenResponse: string | null;
|
|
2798
2805
|
audio: string | null;
|
|
2799
2806
|
autoGrade: boolean;
|
|
2800
2807
|
file: string | null;
|
|
2808
|
+
pagePrompt: string | null;
|
|
2801
2809
|
}) => Promise<{
|
|
2802
2810
|
noFeedbackAvailable: boolean;
|
|
2803
2811
|
success: boolean;
|
package/dist/index.web.js
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(
|
|
@@ -1288,7 +1290,7 @@ function useScore({
|
|
|
1288
1290
|
enabled
|
|
1289
1291
|
});
|
|
1290
1292
|
}
|
|
1291
|
-
var debounceUpdateScore = debounce(updateScore,
|
|
1293
|
+
var debounceUpdateScore = debounce(updateScore, 500);
|
|
1292
1294
|
function useUpdateScore() {
|
|
1293
1295
|
const { queryClient } = useSpeakableApi();
|
|
1294
1296
|
const mutation = useMutation({
|
|
@@ -1347,6 +1349,7 @@ function useUpdateCardScore({
|
|
|
1347
1349
|
return { cardId, scoresUpdated: newScoreUpdated };
|
|
1348
1350
|
},
|
|
1349
1351
|
onMutate: ({ cardId, cardScore }) => {
|
|
1352
|
+
const previousData = queryClient.getQueryData(queryKey);
|
|
1350
1353
|
queryClient.setQueryData(queryKey, (previousScore) => {
|
|
1351
1354
|
const updates = handleOptimisticScore({
|
|
1352
1355
|
score: previousScore,
|
|
@@ -1360,14 +1363,18 @@ function useUpdateCardScore({
|
|
|
1360
1363
|
...updates
|
|
1361
1364
|
};
|
|
1362
1365
|
});
|
|
1366
|
+
return { previousData };
|
|
1363
1367
|
},
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
if (previousData) {
|
|
1369
|
-
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);
|
|
1370
1372
|
}
|
|
1373
|
+
},
|
|
1374
|
+
onSettled: () => {
|
|
1375
|
+
queryClient.invalidateQueries({
|
|
1376
|
+
queryKey
|
|
1377
|
+
});
|
|
1371
1378
|
}
|
|
1372
1379
|
});
|
|
1373
1380
|
return {
|
|
@@ -1433,6 +1440,9 @@ function useClearScore() {
|
|
|
1433
1440
|
const { queryClient } = useSpeakableApi();
|
|
1434
1441
|
const mutation = useMutation({
|
|
1435
1442
|
mutationFn: clearScore,
|
|
1443
|
+
onError: (error) => {
|
|
1444
|
+
console.log("Error clearing score:", error.message);
|
|
1445
|
+
},
|
|
1436
1446
|
onSettled: (result) => {
|
|
1437
1447
|
var _a;
|
|
1438
1448
|
queryClient.invalidateQueries({
|
|
@@ -1448,6 +1458,9 @@ function useClearScoreV2() {
|
|
|
1448
1458
|
const { queryClient } = useSpeakableApi();
|
|
1449
1459
|
const mutation = useMutation({
|
|
1450
1460
|
mutationFn: clearScoreV2,
|
|
1461
|
+
onError: (error) => {
|
|
1462
|
+
console.log("Error clearing score V2:", error.message);
|
|
1463
|
+
},
|
|
1451
1464
|
onSettled: (result) => {
|
|
1452
1465
|
var _a;
|
|
1453
1466
|
queryClient.invalidateQueries({
|
|
@@ -3040,21 +3053,38 @@ var useBaseOpenAI = ({
|
|
|
3040
3053
|
const { data: feedbackAccess } = useActivityFeedbackAccess({
|
|
3041
3054
|
aiEnabled
|
|
3042
3055
|
});
|
|
3043
|
-
const getTranscript = async (audioUrl, language) => {
|
|
3044
|
-
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
|
+
}
|
|
3045
3073
|
try {
|
|
3046
|
-
const getAssemblyAITranscript = (_b = (_a = api).httpsCallable) == null ? void 0 : _b.call(_a, "transcribeAssemblyAIAudio");
|
|
3047
3074
|
const response = await (getAssemblyAITranscript == null ? void 0 : getAssemblyAITranscript({
|
|
3048
3075
|
audioUrl,
|
|
3049
3076
|
language
|
|
3050
3077
|
}));
|
|
3051
3078
|
const transcript = response == null ? void 0 : response.data;
|
|
3052
|
-
|
|
3079
|
+
if (transcript) {
|
|
3080
|
+
return transcript;
|
|
3081
|
+
}
|
|
3082
|
+
throw new Error("Both transcript services failed");
|
|
3053
3083
|
} catch (error) {
|
|
3054
|
-
console.log("
|
|
3084
|
+
console.log("AssemblyAI transcript also failed:", error);
|
|
3055
3085
|
onTranscriptError({
|
|
3056
3086
|
type: "TRANSCRIPT",
|
|
3057
|
-
message: (error == null ? void 0 : error.message) || "Error getting transcript"
|
|
3087
|
+
message: (error == null ? void 0 : error.message) || "Error getting transcript from both services"
|
|
3058
3088
|
});
|
|
3059
3089
|
throw new Error(error);
|
|
3060
3090
|
}
|
|
@@ -3109,7 +3139,8 @@ var useBaseOpenAI = ({
|
|
|
3109
3139
|
// if the type = RESPOND_WRITE
|
|
3110
3140
|
audio = null,
|
|
3111
3141
|
autoGrade = true,
|
|
3112
|
-
file = null
|
|
3142
|
+
file = null,
|
|
3143
|
+
pagePrompt = null
|
|
3113
3144
|
}) => {
|
|
3114
3145
|
try {
|
|
3115
3146
|
if (!(feedbackAccess == null ? void 0 : feedbackAccess.canAccessFeedback)) {
|
|
@@ -3129,7 +3160,7 @@ var useBaseOpenAI = ({
|
|
|
3129
3160
|
onTranscriptSuccess(writtenResponse);
|
|
3130
3161
|
} else if (typeof audio === "string" && file) {
|
|
3131
3162
|
if (feedbackAccess == null ? void 0 : feedbackAccess.canAccessFeedback) {
|
|
3132
|
-
transcript = await getTranscript(audio, language);
|
|
3163
|
+
transcript = await getTranscript(audio, language, pagePrompt != null ? pagePrompt : "");
|
|
3133
3164
|
audioUrl = audio;
|
|
3134
3165
|
onTranscriptSuccess(transcript);
|
|
3135
3166
|
} else {
|
|
@@ -3138,7 +3169,7 @@ var useBaseOpenAI = ({
|
|
|
3138
3169
|
);
|
|
3139
3170
|
}
|
|
3140
3171
|
} else {
|
|
3141
|
-
const response = await uploadAudioAndGetTranscript(audio || "", language);
|
|
3172
|
+
const response = await uploadAudioAndGetTranscript(audio || "", language, pagePrompt != null ? pagePrompt : "");
|
|
3142
3173
|
transcript = response.transcript;
|
|
3143
3174
|
audioUrl = response.audioUrl;
|
|
3144
3175
|
}
|