Skip to content

Commit

Permalink
doc: 调整函数相关jsdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
TBXark committed Aug 14, 2024
1 parent bf2448f commit c271e6d
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 35 deletions.
2 changes: 1 addition & 1 deletion dist/buildinfo.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"sha":"3ca5cf2","timestamp":1723601022}
{"sha":"bf2448f","timestamp":1723602033}
6 changes: 3 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ var Environment = class {
// -- 版本数据 --
//
// 当前版本
BUILD_TIMESTAMP = 1723601022;
BUILD_TIMESTAMP = 1723602033;
// 当前版本 commit id
BUILD_VERSION = "3ca5cf2";
BUILD_VERSION = "bf2448f";
// -- 基础配置 --
/**
* @type {I18n | null}
Expand Down Expand Up @@ -1048,7 +1048,7 @@ ERROR: ${e.message}`;
throw new Error(options.errorExtractor(result));
}
try {
onResult?.(result);
await onResult?.(result);
return options.fullContentExtractor(result);
} catch (e) {
console.error(e);
Expand Down
2 changes: 1 addition & 1 deletion dist/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1723601022
1723602033
13 changes: 0 additions & 13 deletions src/agent/agents.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,6 @@ export function loadChatLLM(context) {
return null;
}


/**
* @typedef {Function} ImageAgentRequest
* @param {string} prompt
* @param {ContextType} context
*/

/**
* @typedef {object} ImageAgent
* @property {string} name
* @property {Function} enable
* @property {ImageAgentRequest} request
*/
/**
* @type {ImageAgent[]}
*/
Expand Down
2 changes: 1 addition & 1 deletion src/agent/anthropic.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async function renderAnthropicMessage(item) {
* 发送消息到Anthropic AI
* @param {LlmParams} params
* @param {ContextType} context
* @param {Function} onStream
* @param {AgentTextHandler} onStream
* @returns {Promise<string>}
*/
export async function requestCompletionsFromAnthropicAI(params, context, onStream) {
Expand Down
2 changes: 1 addition & 1 deletion src/agent/azure.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function isAzureImageEnable(context) {
* 发送消息到Azure ChatGPT
* @param {LlmParams} params
* @param {ContextType} context
* @param {Function} onStream
* @param {AgentTextHandler} onStream
* @returns {Promise<string>}
*/
export async function requestCompletionsFromAzureOpenAI(params, context, onStream) {
Expand Down
2 changes: 1 addition & 1 deletion src/agent/cohere.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function renderCohereMessage(item) {
* 发送消息到Cohere AI
* @param {LlmParams} params
* @param {ContextType} context
* @param {Function} onStream
* @param {AgentTextHandler} onStream
* @returns {Promise<string>}
*/
export async function requestCompletionsFromCohereAI(params, context, onStream) {
Expand Down
2 changes: 1 addition & 1 deletion src/agent/gemini.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function renderGeminiMessage(item) {
* 发送消息到Gemini
* @param {LlmParams} params
* @param {ContextType} context
* @param {Function} onStream
* @param {AgentTextHandler} onStream
* @returns {Promise<string>}
*/
export async function requestCompletionsFromGeminiAI(params, context, onStream) {
Expand Down
2 changes: 1 addition & 1 deletion src/agent/mistralai.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function renderMistralMessage(item) {
* 发送消息到Mistral AI
* @param {LlmParams} params
* @param {ContextType} context
* @param {Function} onStream
* @param {AgentTextHandler} onStream
* @returns {Promise<string>}
*/
export async function requestCompletionsFromMistralAI(params, context, onStream) {
Expand Down
2 changes: 1 addition & 1 deletion src/agent/openai.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export async function renderOpenAIMessage(item) {
* 发送消息到ChatGPT
* @param {LlmParams} params
* @param {ContextType} context
* @param {Function} onStream
* @param {AgentTextHandler} onStream
* @returns {Promise<string>}
*/
export async function requestCompletionsFromOpenAI(params, context, onStream) {
Expand Down
22 changes: 15 additions & 7 deletions src/agent/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,27 @@ import {Stream} from './stream.js';


/**
* @typedef {Function} StreamBuilder
* @callback StreamBuilder
* @param {Response} resp
* @param {AbortController} controller
* @returns {Stream}
* @typedef {Function} SSEContentExtractor
*/
/**
* @callback SSEContentExtractor
* @param {object} data
* @returns {string|null}
* @typedef {Function} FullContentExtractor
*/
/**
* @callback FullContentExtractor
* @param {object} data
* @returns {string|null}
* @typedef {object} ErrorExtractor
*/
/**
* @callback ErrorExtractor
* @param {object} data
* @returns {string|null}
*/
/**
* @typedef {object} SseChatCompatibleOptions
* @property {StreamBuilder} streamBuilder
* @property {SSEContentExtractor} contentExtractor
Expand Down Expand Up @@ -75,8 +83,8 @@ export function isEventStreamResponse(resp) {
* @param {object} header
* @param {object} body
* @param {ContextType} context
* @param {Function} onStream
* @param {Function} onResult
* @param {AgentTextHandler| null} onStream
* @param {AgentTextHandler | null} onResult
* @param {SseChatCompatibleOptions | null} options
* @returns {Promise<string>}
*/
Expand Down Expand Up @@ -150,7 +158,7 @@ export async function requestChatCompletions(url, header, body, context, onStrea
}

try {
onResult?.(result);
await onResult?.(result);
return options.fullContentExtractor(result);
} catch (e) {
console.error(e);
Expand Down
2 changes: 1 addition & 1 deletion src/agent/workersai.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function renderWorkerAIMessage(item) {
* 发送消息到Workers AI
* @param {LlmParams} params
* @param {ContextType} context
* @param {Function} onStream
* @param {AgentTextHandler} onStream
* @returns {Promise<string>}
*/
export async function requestCompletionsFromWorkersAI(params, context, onStream) {
Expand Down
32 changes: 29 additions & 3 deletions src/types/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,46 @@
*/

/**
* @typedef {Function} ChatAgentRequest
* @callback IsAgentEnable
* @param {ContextType} context
* @returns {boolean}
*/

/**
* @callback AgentTextHandler
* @param {string} text
* @returns {Promise<any>}
*/

/**
* @callback ChatAgentRequest
* @param {LlmParams} params
* @param {ContextType} context
* @param {Function} onStream
* @param {AgentTextHandler} onStream
* @returns {Promise<string>}
*/

/**
* @typedef {object} ChatAgent
* @property {string} name
* @property {Function} enable
* @property {IsAgentEnable} enable
* @property {ChatAgentRequest} request
*/

/**
* @callback ImageAgentRequest
* @param {string} prompt
* @param {ContextType} context
* @returns {Promise<string|Blob>}
*/

/**
* @typedef {object} ImageAgent
* @property {string} name
* @property {IsAgentEnable} enable
* @property {ImageAgentRequest} request
*/

/**
* @typedef {object} HistoryItem
* @property {string} role
Expand Down

0 comments on commit c271e6d

Please sign in to comment.