Skip to content

Commit 65493e0

Browse files
buildContents jsDoc updated.
1 parent cbadd36 commit 65493e0

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/base.mjs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,14 +458,21 @@ class TinyAiInstance extends EventEmitter {
458458
return history && typeof history.model === 'string' ? history.model : null;
459459
}
460460

461+
/**
462+
* @typedef {Object} AIContentData
463+
* @property {Array<Record<'text' | 'inlineData', string | { mime_type: string, data: string } | null>>} parts
464+
* @property {string|undefined} [role]
465+
* @property {string|number|undefined} [finishReason]
466+
*/
467+
461468
/**
462469
* Build content data for an AI session.
463470
*
464471
* @param {Array<*>} [contents] - An optional array to which the built content data will be pushed.
465472
* @param {Record<string, any>} item - The item containing content parts or a content object.
466473
* @param {string|null} [role] - The role to be associated with the content (optional).
467474
* @param {boolean} [rmFinishReason=false] - If true, removes the `finishReason` property from the content.
468-
* @returns {Object|undefined} The constructed content data object, or undefined if pushed to an array.
475+
* @returns {AIContentData|number} The constructed content data object, or array length if pushed to an array.
469476
*/
470477
buildContents(contents, item = {}, role = null, rmFinishReason = false) {
471478
// Content Data
@@ -491,11 +498,9 @@ class TinyAiInstance extends EventEmitter {
491498
for (const index in item.parts) insertPart(item.parts[index]);
492499
} else if (item.content) insertPart(item.content);
493500

494-
if (!rmFinishReason) {
501+
if (!rmFinishReason)
495502
if (typeof item.finishReason === 'string' || typeof item.finishReason === 'number')
496503
contentData.finishReason = item.finishReason;
497-
} else if (typeof contentData.finishReason !== 'undefined')
498-
contentData.finishReason = undefined;
499504

500505
// Complete
501506
if (Array.isArray(contents)) return contents.push(contentData);

0 commit comments

Comments
 (0)