@autoscriber/core 0.1.0 → 0.1.2
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/core/assistant-client.d.ts +11 -0
- package/dist/core/assistant-client.d.ts.map +1 -1
- package/dist/index.cjs +76 -2
- package/dist/index.js +76 -2
- package/package.json +1 -1
|
@@ -74,5 +74,16 @@ export declare class AssistantClient {
|
|
|
74
74
|
private handlePartialResult;
|
|
75
75
|
private handleVoiceTranscription;
|
|
76
76
|
private resetRecordingState;
|
|
77
|
+
/**
|
|
78
|
+
* Sanitizes FHIR resources by removing empty answer values that fail FHIR validation.
|
|
79
|
+
* Specifically handles QuestionnaireResponse resources by removing empty valueString entries
|
|
80
|
+
* and empty answer arrays to comply with FHIR validation patterns.
|
|
81
|
+
*/
|
|
82
|
+
private sanitizeFhirResource;
|
|
83
|
+
/**
|
|
84
|
+
* Recursively sanitizes a QuestionnaireResponse by removing empty answer values.
|
|
85
|
+
* Removes empty valueString entries and empty answer arrays to comply with FHIR validation.
|
|
86
|
+
*/
|
|
87
|
+
private sanitizeQuestionnaireResponse;
|
|
77
88
|
}
|
|
78
89
|
//# sourceMappingURL=assistant-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assistant-client.d.ts","sourceRoot":"","sources":["../../src/core/assistant-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAEhB,cAAc,EAEd,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAwBlB,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAmC;IAEvD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IAEzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmB;IAE3C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAsB;IAEnD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA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AAC,mBAAmB;IAgC3B,OAAO,CAAC,oBAAoB;IAsE5B,OAAO,CAAC,2BAA2B;IAWnC,OAAO,CAAC,mBAAmB;IAqB3B,OAAO,CAAC,wBAAwB;IAahC,OAAO,CAAC,mBAAmB;IAiB3B;;;;OAIG;IACH,OAAO,CAAC,oBAAoB;IAe5B;;;OAGG;IACH,OAAO,CAAC,6BAA6B;CA2DtC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1312,6 +1312,7 @@ var AssistantClient = class {
|
|
|
1312
1312
|
setFhirContext(resource) {
|
|
1313
1313
|
const id = generateMessageId();
|
|
1314
1314
|
const resourceType = typeof resource === "object" && resource && "resourceType" in resource ? String(resource.resourceType) : "Resource";
|
|
1315
|
+
const sanitizedResource = this.sanitizeFhirResource(resource);
|
|
1315
1316
|
this.pushInteraction({
|
|
1316
1317
|
id,
|
|
1317
1318
|
label: `Updating ${resourceType} context`,
|
|
@@ -1325,7 +1326,7 @@ var AssistantClient = class {
|
|
|
1325
1326
|
method: "fhirContext",
|
|
1326
1327
|
params: {
|
|
1327
1328
|
mediaType: "application/fhir+json",
|
|
1328
|
-
data:
|
|
1329
|
+
data: sanitizedResource
|
|
1329
1330
|
}
|
|
1330
1331
|
});
|
|
1331
1332
|
this.pendingRequests.set(id, { id, method: "fhirContext" });
|
|
@@ -1904,7 +1905,21 @@ var AssistantClient = class {
|
|
|
1904
1905
|
const message = this.messageStore.getMessageById(id);
|
|
1905
1906
|
if (message) {
|
|
1906
1907
|
const data = result?.data ?? result;
|
|
1907
|
-
if (Array.isArray(data)
|
|
1908
|
+
if (Array.isArray(data)) {
|
|
1909
|
+
this.messageStore.setMessageResult(id, data);
|
|
1910
|
+
for (const item of data) {
|
|
1911
|
+
if (item?.mediaType === "application/fhir+json" && item?.data) {
|
|
1912
|
+
this.bus.emit("fhir:data", item.data);
|
|
1913
|
+
const sessionId = getSessionIdFromToken(this.token);
|
|
1914
|
+
const resourceType = typeof item.data === "object" && item.data && "resourceType" in item.data ? String(item.data.resourceType) : "unknown";
|
|
1915
|
+
this.logStructured("info", "FHIR data received", {
|
|
1916
|
+
messageId: id,
|
|
1917
|
+
resourceType,
|
|
1918
|
+
sessionId: sessionId ?? "unknown"
|
|
1919
|
+
});
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
} else if (typeof data === "string") {
|
|
1908
1923
|
this.messageStore.setMessageResult(id, data);
|
|
1909
1924
|
} else if (result?.mediaType === "application/fhir+json") {
|
|
1910
1925
|
this.messageStore.setMessageResult(id, [
|
|
@@ -1987,6 +2002,65 @@ var AssistantClient = class {
|
|
|
1987
2002
|
};
|
|
1988
2003
|
this.emitRecording();
|
|
1989
2004
|
}
|
|
2005
|
+
/**
|
|
2006
|
+
* Sanitizes FHIR resources by removing empty answer values that fail FHIR validation.
|
|
2007
|
+
* Specifically handles QuestionnaireResponse resources by removing empty valueString entries
|
|
2008
|
+
* and empty answer arrays to comply with FHIR validation patterns.
|
|
2009
|
+
*/
|
|
2010
|
+
sanitizeFhirResource(resource) {
|
|
2011
|
+
if (!resource || typeof resource !== "object") {
|
|
2012
|
+
return resource;
|
|
2013
|
+
}
|
|
2014
|
+
const resourceObj = resource;
|
|
2015
|
+
if (resourceObj.resourceType === "QuestionnaireResponse") {
|
|
2016
|
+
return this.sanitizeQuestionnaireResponse(resourceObj);
|
|
2017
|
+
}
|
|
2018
|
+
return resource;
|
|
2019
|
+
}
|
|
2020
|
+
/**
|
|
2021
|
+
* Recursively sanitizes a QuestionnaireResponse by removing empty answer values.
|
|
2022
|
+
* Removes empty valueString entries and empty answer arrays to comply with FHIR validation.
|
|
2023
|
+
*/
|
|
2024
|
+
sanitizeQuestionnaireResponse(resource) {
|
|
2025
|
+
const sanitized = { ...resource };
|
|
2026
|
+
if (Array.isArray(sanitized.item)) {
|
|
2027
|
+
sanitized.item = sanitized.item.map((item) => {
|
|
2028
|
+
if (!item || typeof item !== "object") {
|
|
2029
|
+
return item;
|
|
2030
|
+
}
|
|
2031
|
+
const itemObj = item;
|
|
2032
|
+
const sanitizedItem = { ...itemObj };
|
|
2033
|
+
if (Array.isArray(itemObj.item)) {
|
|
2034
|
+
sanitizedItem.item = itemObj.item.map((nestedItem) => {
|
|
2035
|
+
if (nestedItem && typeof nestedItem === "object") {
|
|
2036
|
+
return this.sanitizeQuestionnaireResponse(nestedItem);
|
|
2037
|
+
}
|
|
2038
|
+
return nestedItem;
|
|
2039
|
+
});
|
|
2040
|
+
}
|
|
2041
|
+
if (Array.isArray(itemObj.answer)) {
|
|
2042
|
+
const sanitizedAnswers = itemObj.answer.filter((answer) => {
|
|
2043
|
+
if (!answer || typeof answer !== "object") {
|
|
2044
|
+
return true;
|
|
2045
|
+
}
|
|
2046
|
+
const answerObj = answer;
|
|
2047
|
+
const valueString = answerObj.valueString;
|
|
2048
|
+
if (typeof valueString === "string" && valueString.trim() === "") {
|
|
2049
|
+
return false;
|
|
2050
|
+
}
|
|
2051
|
+
return true;
|
|
2052
|
+
});
|
|
2053
|
+
if (sanitizedAnswers.length > 0) {
|
|
2054
|
+
sanitizedItem.answer = sanitizedAnswers;
|
|
2055
|
+
} else {
|
|
2056
|
+
delete sanitizedItem.answer;
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
return sanitizedItem;
|
|
2060
|
+
});
|
|
2061
|
+
}
|
|
2062
|
+
return sanitized;
|
|
2063
|
+
}
|
|
1990
2064
|
};
|
|
1991
2065
|
|
|
1992
2066
|
// src/headless/create-assistant.ts
|
package/dist/index.js
CHANGED
|
@@ -1285,6 +1285,7 @@ var AssistantClient = class {
|
|
|
1285
1285
|
setFhirContext(resource) {
|
|
1286
1286
|
const id = generateMessageId();
|
|
1287
1287
|
const resourceType = typeof resource === "object" && resource && "resourceType" in resource ? String(resource.resourceType) : "Resource";
|
|
1288
|
+
const sanitizedResource = this.sanitizeFhirResource(resource);
|
|
1288
1289
|
this.pushInteraction({
|
|
1289
1290
|
id,
|
|
1290
1291
|
label: `Updating ${resourceType} context`,
|
|
@@ -1298,7 +1299,7 @@ var AssistantClient = class {
|
|
|
1298
1299
|
method: "fhirContext",
|
|
1299
1300
|
params: {
|
|
1300
1301
|
mediaType: "application/fhir+json",
|
|
1301
|
-
data:
|
|
1302
|
+
data: sanitizedResource
|
|
1302
1303
|
}
|
|
1303
1304
|
});
|
|
1304
1305
|
this.pendingRequests.set(id, { id, method: "fhirContext" });
|
|
@@ -1877,7 +1878,21 @@ var AssistantClient = class {
|
|
|
1877
1878
|
const message = this.messageStore.getMessageById(id);
|
|
1878
1879
|
if (message) {
|
|
1879
1880
|
const data = result?.data ?? result;
|
|
1880
|
-
if (Array.isArray(data)
|
|
1881
|
+
if (Array.isArray(data)) {
|
|
1882
|
+
this.messageStore.setMessageResult(id, data);
|
|
1883
|
+
for (const item of data) {
|
|
1884
|
+
if (item?.mediaType === "application/fhir+json" && item?.data) {
|
|
1885
|
+
this.bus.emit("fhir:data", item.data);
|
|
1886
|
+
const sessionId = getSessionIdFromToken(this.token);
|
|
1887
|
+
const resourceType = typeof item.data === "object" && item.data && "resourceType" in item.data ? String(item.data.resourceType) : "unknown";
|
|
1888
|
+
this.logStructured("info", "FHIR data received", {
|
|
1889
|
+
messageId: id,
|
|
1890
|
+
resourceType,
|
|
1891
|
+
sessionId: sessionId ?? "unknown"
|
|
1892
|
+
});
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
} else if (typeof data === "string") {
|
|
1881
1896
|
this.messageStore.setMessageResult(id, data);
|
|
1882
1897
|
} else if (result?.mediaType === "application/fhir+json") {
|
|
1883
1898
|
this.messageStore.setMessageResult(id, [
|
|
@@ -1960,6 +1975,65 @@ var AssistantClient = class {
|
|
|
1960
1975
|
};
|
|
1961
1976
|
this.emitRecording();
|
|
1962
1977
|
}
|
|
1978
|
+
/**
|
|
1979
|
+
* Sanitizes FHIR resources by removing empty answer values that fail FHIR validation.
|
|
1980
|
+
* Specifically handles QuestionnaireResponse resources by removing empty valueString entries
|
|
1981
|
+
* and empty answer arrays to comply with FHIR validation patterns.
|
|
1982
|
+
*/
|
|
1983
|
+
sanitizeFhirResource(resource) {
|
|
1984
|
+
if (!resource || typeof resource !== "object") {
|
|
1985
|
+
return resource;
|
|
1986
|
+
}
|
|
1987
|
+
const resourceObj = resource;
|
|
1988
|
+
if (resourceObj.resourceType === "QuestionnaireResponse") {
|
|
1989
|
+
return this.sanitizeQuestionnaireResponse(resourceObj);
|
|
1990
|
+
}
|
|
1991
|
+
return resource;
|
|
1992
|
+
}
|
|
1993
|
+
/**
|
|
1994
|
+
* Recursively sanitizes a QuestionnaireResponse by removing empty answer values.
|
|
1995
|
+
* Removes empty valueString entries and empty answer arrays to comply with FHIR validation.
|
|
1996
|
+
*/
|
|
1997
|
+
sanitizeQuestionnaireResponse(resource) {
|
|
1998
|
+
const sanitized = { ...resource };
|
|
1999
|
+
if (Array.isArray(sanitized.item)) {
|
|
2000
|
+
sanitized.item = sanitized.item.map((item) => {
|
|
2001
|
+
if (!item || typeof item !== "object") {
|
|
2002
|
+
return item;
|
|
2003
|
+
}
|
|
2004
|
+
const itemObj = item;
|
|
2005
|
+
const sanitizedItem = { ...itemObj };
|
|
2006
|
+
if (Array.isArray(itemObj.item)) {
|
|
2007
|
+
sanitizedItem.item = itemObj.item.map((nestedItem) => {
|
|
2008
|
+
if (nestedItem && typeof nestedItem === "object") {
|
|
2009
|
+
return this.sanitizeQuestionnaireResponse(nestedItem);
|
|
2010
|
+
}
|
|
2011
|
+
return nestedItem;
|
|
2012
|
+
});
|
|
2013
|
+
}
|
|
2014
|
+
if (Array.isArray(itemObj.answer)) {
|
|
2015
|
+
const sanitizedAnswers = itemObj.answer.filter((answer) => {
|
|
2016
|
+
if (!answer || typeof answer !== "object") {
|
|
2017
|
+
return true;
|
|
2018
|
+
}
|
|
2019
|
+
const answerObj = answer;
|
|
2020
|
+
const valueString = answerObj.valueString;
|
|
2021
|
+
if (typeof valueString === "string" && valueString.trim() === "") {
|
|
2022
|
+
return false;
|
|
2023
|
+
}
|
|
2024
|
+
return true;
|
|
2025
|
+
});
|
|
2026
|
+
if (sanitizedAnswers.length > 0) {
|
|
2027
|
+
sanitizedItem.answer = sanitizedAnswers;
|
|
2028
|
+
} else {
|
|
2029
|
+
delete sanitizedItem.answer;
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
return sanitizedItem;
|
|
2033
|
+
});
|
|
2034
|
+
}
|
|
2035
|
+
return sanitized;
|
|
2036
|
+
}
|
|
1963
2037
|
};
|
|
1964
2038
|
|
|
1965
2039
|
// src/headless/create-assistant.ts
|