@h-ai/ai 1.0.0-beta.2 → 1.0.0-beta.3
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/README.en.md +8 -6
- package/README.ja.md +8 -6
- package/README.md +8 -6
- package/dist/{ai-audio-ws-protocol-nfhO0tOo.d.ts → ai-audio-ws-protocol-1VhScfis.d.ts} +18 -18
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +1 -1
- package/dist/{chunk-HEVXR252.js → chunk-GAC5RLAG.js} +24 -21
- package/dist/chunk-GAC5RLAG.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +18 -12
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/dist/chunk-HEVXR252.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { aiM, AIConfigSchema, MemoryConfigSchema, RetrievalConfigSchema, KnowledgeConfigSchema, TokenConfigSchema, SummaryConfigSchema, CompressConfigSchema, AudioConfigSchema, ImageConfigSchema, resolveImageModel, resolveModelEntry, resolveAudioModel, ensureAudioCredential, resolveModelApi } from './chunk-
|
|
2
|
-
export { A2AConfigSchema, A2ASkillConfigSchema, AIConfigSchema, AUDIO_WS_PATH, ApiTypeSchema, AudioConfigSchema, AudioFormatSchema, AudioModelEntrySchema, AudioOperationSchema, AudioOperationsSchema, AudioProviderSchema, AudioWsClientMessageSchema, AudioWsDoneMessageSchema, AudioWsStartMessageSchema, AudioWsTextMessageSchema, CompressConfigSchema, CompressionStrategySchema, EmbeddingConfigSchema, EntityTypeSchema, FileConfigSchema, ImageConfigSchema, ImageModelEntrySchema, ImageProviderSchema, KnowledgeConfigSchema, LLMConfigSchema, MCPConfigSchema, MCPServerCapabilitiesSchema, MCPServerConfigSchema, MemoryConfigSchema, MemoryTypeSchema, ModelEntrySchema, ModelScenarioSchema, OptionalSecretSchema, RetrievalConfigSchema, RetrievalSourceSchema, SummaryConfigSchema, TokenConfigSchema, ensureAudioCredential, resolveAudioModel, resolveImageModel, resolveModelApi, resolveModelEntry, serializePlayableAudio } from './chunk-
|
|
1
|
+
import { aiM, AIConfigSchema, MemoryConfigSchema, RetrievalConfigSchema, KnowledgeConfigSchema, TokenConfigSchema, SummaryConfigSchema, CompressConfigSchema, AudioConfigSchema, ImageConfigSchema, resolveImageModel, resolveModelEntry, resolveAudioModel, ensureAudioCredential, resolveModelApi } from './chunk-GAC5RLAG.js';
|
|
2
|
+
export { A2AConfigSchema, A2ASkillConfigSchema, AIConfigSchema, AUDIO_WS_PATH, ApiTypeSchema, AudioConfigSchema, AudioFormatSchema, AudioModelEntrySchema, AudioOperationSchema, AudioOperationsSchema, AudioProviderSchema, AudioWsClientMessageSchema, AudioWsDoneMessageSchema, AudioWsStartMessageSchema, AudioWsTextMessageSchema, CompressConfigSchema, CompressionStrategySchema, EmbeddingConfigSchema, EntityTypeSchema, FileConfigSchema, ImageConfigSchema, ImageModelEntrySchema, ImageProviderSchema, KnowledgeConfigSchema, LLMConfigSchema, MCPConfigSchema, MCPServerCapabilitiesSchema, MCPServerConfigSchema, MemoryConfigSchema, MemoryTypeSchema, ModelEntrySchema, ModelScenarioSchema, OptionalSecretSchema, RetrievalConfigSchema, RetrievalSourceSchema, SummaryConfigSchema, TokenConfigSchema, ensureAudioCredential, resolveAudioModel, resolveImageModel, resolveModelApi, resolveModelEntry, serializePlayableAudio } from './chunk-GAC5RLAG.js';
|
|
3
3
|
import { HaiAIError } from './chunk-HYMP57AC.js';
|
|
4
4
|
export { HaiAIError } from './chunk-HYMP57AC.js';
|
|
5
5
|
import process from 'process';
|
|
@@ -5615,7 +5615,7 @@ function createAnthropicProvider(deps) {
|
|
|
5615
5615
|
const apiKey = tempModel?.apiKey ?? entry?.apiKey ?? config.llm.apiKey ?? (process.env.HAI_AI_LLM_APIKEY?.trim() || process.env.ANTHROPIC_API_KEY);
|
|
5616
5616
|
if (!apiKey)
|
|
5617
5617
|
return err(HaiAIError.CONFIGURATION_ERROR, aiM("ai_configError", { params: { error: "API Key is required for Anthropic" } }));
|
|
5618
|
-
const globalBaseUrl = config.llm.
|
|
5618
|
+
const globalBaseUrl = config.llm.protocol === "anthropic" ? config.llm.baseUrl ?? (process.env.HAI_AI_LLM_BASEURL?.trim() || void 0) : void 0;
|
|
5619
5619
|
const baseUrl = (tempModel?.baseUrl ?? entry?.baseUrl ?? globalBaseUrl ?? process.env.ANTHROPIC_BASE_URL ?? DEFAULT_ANTHROPIC_BASE_URL).replace(/\/+$/, "");
|
|
5620
5620
|
return ok({
|
|
5621
5621
|
apiKey,
|
|
@@ -5729,7 +5729,7 @@ function createAnthropicProvider(deps) {
|
|
|
5729
5729
|
if (config.llm.model)
|
|
5730
5730
|
models.add(config.llm.model);
|
|
5731
5731
|
for (const entry of config.llm.models ?? []) {
|
|
5732
|
-
if ((entry.
|
|
5732
|
+
if ((entry.protocol ?? config.llm.protocol) === "anthropic")
|
|
5733
5733
|
models.add(entry.model);
|
|
5734
5734
|
}
|
|
5735
5735
|
return ok([...models]);
|
|
@@ -5955,9 +5955,9 @@ function createOpenAIProvider(deps) {
|
|
|
5955
5955
|
});
|
|
5956
5956
|
if (!resolvedResult.success)
|
|
5957
5957
|
return resolvedResult;
|
|
5958
|
-
const { apiKey, baseUrl, timeout, model, api } = resolvedResult.data;
|
|
5958
|
+
const { apiKey, baseUrl, timeout, model, protocol: api } = resolvedResult.data;
|
|
5959
5959
|
const resolvedApi = api === "responses" ? "responses" : "chat";
|
|
5960
|
-
return ok({ client: getClient(apiKey ?? "", baseUrl ?? "https://api.openai.com/v1", timeout), model,
|
|
5960
|
+
return ok({ client: getClient(apiKey ?? "", baseUrl ?? "https://api.openai.com/v1", timeout), model, protocol: resolvedApi });
|
|
5961
5961
|
}
|
|
5962
5962
|
function resolveTempClient(tempModel) {
|
|
5963
5963
|
const apiKey = tempModel.apiKey ?? config.llm.apiKey ?? (process.env.HAI_AI_LLM_APIKEY?.trim() || process.env.OPENAI_API_KEY);
|
|
@@ -5965,11 +5965,11 @@ function createOpenAIProvider(deps) {
|
|
|
5965
5965
|
return err(HaiAIError.CONFIGURATION_ERROR, aiM("ai_configError", { params: { error: "API Key is required for temp model" } }));
|
|
5966
5966
|
const baseUrl = tempModel.baseUrl ?? config.llm.baseUrl ?? (process.env.HAI_AI_LLM_BASEURL?.trim() || process.env.OPENAI_BASE_URL) ?? "https://api.openai.com/v1";
|
|
5967
5967
|
const timeout = tempModel.timeout ?? config.llm.timeout ?? 6e4;
|
|
5968
|
-
const api = (tempModel.
|
|
5968
|
+
const api = (tempModel.protocol ?? config.llm.protocol) === "responses" ? "responses" : "chat";
|
|
5969
5969
|
return ok({
|
|
5970
5970
|
client: getTempClient(apiKey, baseUrl, timeout),
|
|
5971
5971
|
model: tempModel.model,
|
|
5972
|
-
api,
|
|
5972
|
+
protocol: api,
|
|
5973
5973
|
maxTokens: tempModel.maxTokens ?? config.llm.maxTokens,
|
|
5974
5974
|
temperature: tempModel.temperature ?? config.llm.temperature
|
|
5975
5975
|
});
|
|
@@ -5995,7 +5995,7 @@ function createOpenAIProvider(deps) {
|
|
|
5995
5995
|
if (!clientResult.success)
|
|
5996
5996
|
return clientResult;
|
|
5997
5997
|
const resolved = clientResult.data;
|
|
5998
|
-
const { client, model, maxTokens, temperature, api } = resolved;
|
|
5998
|
+
const { client, model, maxTokens, temperature, protocol: api } = resolved;
|
|
5999
5999
|
const { objectId: _objectId, sessionId: _sessionId, tempModel: _tempModel, signal, ...openaiRequest } = request;
|
|
6000
6000
|
try {
|
|
6001
6001
|
if (api === "responses") {
|
|
@@ -6023,7 +6023,7 @@ function createOpenAIProvider(deps) {
|
|
|
6023
6023
|
if (!clientResult.success)
|
|
6024
6024
|
throw new Error(clientResult.error.message);
|
|
6025
6025
|
const resolved = clientResult.data;
|
|
6026
|
-
const { client, model, maxTokens, temperature, api } = resolved;
|
|
6026
|
+
const { client, model, maxTokens, temperature, protocol: api } = resolved;
|
|
6027
6027
|
const { objectId: _objectId, sessionId: _sessionId, tempModel: _tempModel, signal, ...openaiRequest } = request;
|
|
6028
6028
|
if (api === "responses") {
|
|
6029
6029
|
const responsesStream = await client.responses.create(
|
|
@@ -6077,14 +6077,14 @@ function createLLMProvider(deps) {
|
|
|
6077
6077
|
return anthropic;
|
|
6078
6078
|
}
|
|
6079
6079
|
function pick(request) {
|
|
6080
|
-
const api = resolveModelApi(deps.config.llm, request.model, request.tempModel?.
|
|
6080
|
+
const api = resolveModelApi(deps.config.llm, request.model, request.tempModel?.protocol);
|
|
6081
6081
|
return api === "anthropic" ? getAnthropic() : openai;
|
|
6082
6082
|
}
|
|
6083
6083
|
return {
|
|
6084
6084
|
chat: (request) => pick(request).chat(request),
|
|
6085
6085
|
chatStream: (request) => pick(request).chatStream(request),
|
|
6086
6086
|
listModels: () => {
|
|
6087
|
-
const api = deps.config.llm.
|
|
6087
|
+
const api = deps.config.llm.protocol ?? "chat";
|
|
6088
6088
|
return api === "anthropic" ? getAnthropic().listModels() : openai.listModels();
|
|
6089
6089
|
}
|
|
6090
6090
|
};
|
|
@@ -6119,6 +6119,8 @@ function createAILLMFunctions(config, deps) {
|
|
|
6119
6119
|
}
|
|
6120
6120
|
}
|
|
6121
6121
|
async function chatWithRecord(request) {
|
|
6122
|
+
if (request.tempModel && Object.hasOwn(request.tempModel, "api"))
|
|
6123
|
+
return err(HaiAIError.INVALID_REQUEST, aiM("ai_llmProtocolRenamed"));
|
|
6122
6124
|
const start = Date.now();
|
|
6123
6125
|
const context = { model: request.model ?? request.tempModel?.model, messageCount: request.messages.length };
|
|
6124
6126
|
logger18.debug("LLM chat started", context);
|
|
@@ -6168,6 +6170,8 @@ function createAILLMFunctions(config, deps) {
|
|
|
6168
6170
|
return result;
|
|
6169
6171
|
}
|
|
6170
6172
|
async function* chatStreamWithRecord(request) {
|
|
6173
|
+
if (request.tempModel && Object.hasOwn(request.tempModel, "api"))
|
|
6174
|
+
throw new Error(aiM("ai_llmProtocolRenamed"));
|
|
6171
6175
|
const start = Date.now();
|
|
6172
6176
|
const logContext = { model: request.model ?? request.tempModel?.model, messageCount: request.messages.length };
|
|
6173
6177
|
logger18.debug("LLM chat stream started", logContext);
|
|
@@ -9983,6 +9987,8 @@ var streamOperations = {
|
|
|
9983
9987
|
};
|
|
9984
9988
|
var ai = {
|
|
9985
9989
|
async init(config, options) {
|
|
9990
|
+
if (Object.keys(process.env).some((name) => /^HAI_AI_LLM_(?:MODELS_\d+_)?API$/.test(name)))
|
|
9991
|
+
return err(HaiAIError.CONFIGURATION_ERROR, aiM("ai_llmProtocolRenamed"));
|
|
9986
9992
|
if (initInProgress) {
|
|
9987
9993
|
logger32.warn("AI init already in progress, skipping concurrent call");
|
|
9988
9994
|
return err(HaiAIError.INIT_IN_PROGRESS, aiM("ai_initInProgress"));
|