@h-ai/ai 1.0.0-beta.28 → 1.0.0-beta.29
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 +2 -0
- package/README.ja.md +2 -0
- package/README.md +2 -0
- package/dist/browser.js +1 -1
- package/dist/{chunk-EENBKRIH.js → chunk-W44R24T2.js} +5 -2
- package/dist/chunk-W44R24T2.js.map +1 -0
- package/dist/index.js +90 -60
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/dist/chunk-EENBKRIH.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { platformOptionsSchema, aiM, AIConfigSchema, MemoryConfigSchema, ModelEntrySchema, AudioModelEntrySchema, ImageModelEntrySchema, MCPExternalServerSchema, RetrievalSourceSchema, KnowledgeConfigSchema, TokenConfigSchema, SummaryConfigSchema, CompressConfigSchema, ACPConfigSchema, ACPAgentSchema, ACPWorkspaceSchema, AudioConfigSchema, resolveModelEntry, resolveAudioModel, ensureAudioCredential, platformScopeSchema, resolveModelApi, platformRequestSchema, platformRunSchema, sessionIdentitySchema, branchNameSchema, ImageConfigSchema, resolveImageModel, ACPPublishSchema } from './chunk-
|
|
2
|
-
export { A2AConfigSchema, A2ASkillConfigSchema, ACPAgentSchema, ACPConfigSchema, ACPPublishSchema, ACPRepositorySchema, ACPWorkspaceSchema, 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, MCPExternalServerSchema, MCPServerCapabilitiesSchema, MCPServerConfigSchema, MemoryConfigSchema, MemoryTypeSchema, ModelCapabilitiesSchema, ModelEntrySchema, ModelScenarioSchema, OptionalSecretSchema, RetrievalConfigSchema, RetrievalSourceSchema, SummaryConfigSchema, TokenConfigSchema, ensureAudioCredential, resolveAudioModel, resolveImageModel, resolveModelApi, resolveModelEntry, serializePlayableAudio } from './chunk-
|
|
1
|
+
import { platformOptionsSchema, aiM, AIConfigSchema, MemoryConfigSchema, ModelEntrySchema, AudioModelEntrySchema, ImageModelEntrySchema, MCPExternalServerSchema, RetrievalSourceSchema, KnowledgeConfigSchema, TokenConfigSchema, SummaryConfigSchema, CompressConfigSchema, ACPConfigSchema, ACPAgentSchema, ACPWorkspaceSchema, AudioConfigSchema, resolveModelEntry, resolveAudioModel, ensureAudioCredential, platformScopeSchema, resolveModelApi, platformRequestSchema, platformRunSchema, sessionIdentitySchema, branchNameSchema, ImageConfigSchema, resolveImageModel, ACPPublishSchema } from './chunk-W44R24T2.js';
|
|
2
|
+
export { A2AConfigSchema, A2ASkillConfigSchema, ACPAgentSchema, ACPConfigSchema, ACPPublishSchema, ACPRepositorySchema, ACPWorkspaceSchema, 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, MCPExternalServerSchema, MCPServerCapabilitiesSchema, MCPServerConfigSchema, MemoryConfigSchema, MemoryTypeSchema, ModelCapabilitiesSchema, ModelEntrySchema, ModelScenarioSchema, OptionalSecretSchema, RetrievalConfigSchema, RetrievalSourceSchema, SummaryConfigSchema, TokenConfigSchema, ensureAudioCredential, resolveAudioModel, resolveImageModel, resolveModelApi, resolveModelEntry, serializePlayableAudio } from './chunk-W44R24T2.js';
|
|
3
3
|
import { HaiAIError } from './chunk-NRDLMUSY.js';
|
|
4
4
|
export { HaiAIError } from './chunk-NRDLMUSY.js';
|
|
5
5
|
import { TaskState, SendMessageRequest, Message, Role, AgentCard, TaskStatus, Task } from '@a2a-js/sdk';
|
|
@@ -16891,6 +16891,7 @@ function requireSqlSuccess(result) {
|
|
|
16891
16891
|
return result;
|
|
16892
16892
|
}
|
|
16893
16893
|
var MAX_BATCH_SQL_PARAMS = 900;
|
|
16894
|
+
var POSTGRES_SCHEMA_LOCK = "hai:ai:store-schema";
|
|
16894
16895
|
function dataTimestamp(data, field, fallback) {
|
|
16895
16896
|
if (typeof data !== "object" || data === null)
|
|
16896
16897
|
return fallback;
|
|
@@ -17007,9 +17008,10 @@ var ReldbAIRelStore = class _ReldbAIRelStore {
|
|
|
17007
17008
|
}
|
|
17008
17009
|
}
|
|
17009
17010
|
/** 创建表及索引(幂等) */
|
|
17010
|
-
async createTable() {
|
|
17011
|
+
async createTable(connection = this.connection) {
|
|
17011
17012
|
const t = this.table;
|
|
17012
17013
|
const db = this.dbType;
|
|
17014
|
+
const execute2 = async (statement) => requireSqlSuccess(await connection.execute(statement));
|
|
17013
17015
|
const idType = db === "mysql" ? "VARCHAR(512)" : "TEXT";
|
|
17014
17016
|
const scopeType = db === "mysql" ? "VARCHAR(255)" : "TEXT";
|
|
17015
17017
|
const dataType = db === "postgresql" ? "JSONB" : db === "mysql" ? "JSON" : "TEXT";
|
|
@@ -17025,28 +17027,51 @@ var ReldbAIRelStore = class _ReldbAIRelStore {
|
|
|
17025
17027
|
cols.push("version VARCHAR(36) NOT NULL", `data ${dataType} NOT NULL`, `created_at BIGINT NOT NULL`, `updated_at BIGINT NOT NULL`);
|
|
17026
17028
|
if (db === "mysql" && this.memoryVectorKey)
|
|
17027
17029
|
cols.push(this.mysqlMemoryVectorColumn(this.memoryVectorKey));
|
|
17028
|
-
await
|
|
17030
|
+
await execute2(`CREATE TABLE IF NOT EXISTS ${t} (${cols.join(", ")})`);
|
|
17029
17031
|
if (this.gate) {
|
|
17030
|
-
await
|
|
17032
|
+
await execute2(`CREATE TABLE IF NOT EXISTS ${this.gate} (id INTEGER PRIMARY KEY, marker INTEGER NOT NULL)`);
|
|
17031
17033
|
const conflict = db === "mysql" ? "ON DUPLICATE KEY UPDATE id = id" : "ON CONFLICT(id) DO NOTHING";
|
|
17032
|
-
await
|
|
17034
|
+
await execute2(`INSERT INTO ${this.gate} (id, marker) VALUES (1, 0) ${conflict}`);
|
|
17033
17035
|
}
|
|
17036
|
+
const indexes = [];
|
|
17034
17037
|
if (this.hasObjectId)
|
|
17035
|
-
|
|
17038
|
+
indexes.push(["object_id", "object_id"]);
|
|
17036
17039
|
if (this.hasSessionId)
|
|
17037
|
-
|
|
17040
|
+
indexes.push(["session_id", "session_id"]);
|
|
17038
17041
|
if (this.hasObjectId && this.hasSessionId)
|
|
17039
|
-
|
|
17042
|
+
indexes.push(["object_session", "object_id, session_id"]);
|
|
17040
17043
|
if (this.hasStatus)
|
|
17041
|
-
|
|
17044
|
+
indexes.push(["status", "status"]);
|
|
17042
17045
|
if (this.hasRefId)
|
|
17043
|
-
|
|
17046
|
+
indexes.push(["ref_id", "ref_id"]);
|
|
17044
17047
|
if (this.hasUpdatedAtIndex)
|
|
17045
|
-
|
|
17046
|
-
if (this.memoryVectorKey)
|
|
17047
|
-
|
|
17048
|
+
indexes.push(["updated_at", "updated_at, id"]);
|
|
17049
|
+
if (this.memoryVectorKey && db !== "mysql")
|
|
17050
|
+
indexes.push(["vector_key", `(${this.memoryVectorKey})`]);
|
|
17048
17051
|
if (this.hasScopeIndex && db === "postgresql")
|
|
17049
|
-
|
|
17052
|
+
indexes.push(["data_gin", "data jsonb_path_ops", "GIN"]);
|
|
17053
|
+
const existing = db === "postgresql" && indexes.length > 0 ? requireSqlSuccess(await connection.query(`
|
|
17054
|
+
SELECT c.relname AS name, i.indisvalid AS valid FROM pg_catalog.pg_index AS i
|
|
17055
|
+
JOIN pg_catalog.pg_class AS c ON c.oid = i.indexrelid
|
|
17056
|
+
WHERE i.indrelid = pg_catalog.to_regclass(?)
|
|
17057
|
+
`, [t])).data : [];
|
|
17058
|
+
const existingIndexes = new Map(existing.map((row) => [row.name, row.valid]));
|
|
17059
|
+
for (const [suffix, columns, method] of indexes) {
|
|
17060
|
+
const name = `idx_${t}_${suffix}`;
|
|
17061
|
+
if (db === "mysql") {
|
|
17062
|
+
await this.createMysqlIndex(name, columns);
|
|
17063
|
+
continue;
|
|
17064
|
+
}
|
|
17065
|
+
if (existingIndexes.get(name) === false)
|
|
17066
|
+
throw new Error(aiM("ai_storeIndexMismatch"));
|
|
17067
|
+
if (existingIndexes.has(name))
|
|
17068
|
+
continue;
|
|
17069
|
+
const ifMissing = db === "sqlite" ? "IF NOT EXISTS " : "";
|
|
17070
|
+
const using = method ? ` USING ${method}` : "";
|
|
17071
|
+
await execute2(`CREATE INDEX ${ifMissing}${name} ON ${t}${using} (${columns})`);
|
|
17072
|
+
}
|
|
17073
|
+
if (db === "mysql" && this.memoryVectorKey)
|
|
17074
|
+
await this.createMysqlMemoryVectorIndex(this.memoryVectorKey);
|
|
17050
17075
|
}
|
|
17051
17076
|
/** MySQL 在新表中直接创建生成列,已有表在首次升级时添加该列。 */
|
|
17052
17077
|
mysqlMemoryVectorColumn(key) {
|
|
@@ -17056,12 +17081,8 @@ var ReldbAIRelStore = class _ReldbAIRelStore {
|
|
|
17056
17081
|
) VIRTUAL`;
|
|
17057
17082
|
}
|
|
17058
17083
|
/** 索引覆盖旧记录,无需逐条回写。MySQL 查询使用命名生成列以命中索引。 */
|
|
17059
|
-
async
|
|
17084
|
+
async createMysqlMemoryVectorIndex(key) {
|
|
17060
17085
|
const name = `idx_${this.table}_vector_key`;
|
|
17061
|
-
if (this.dbType !== "mysql") {
|
|
17062
|
-
await this.sql.execute(`CREATE INDEX IF NOT EXISTS ${name} ON ${this.table}((${key}))`);
|
|
17063
|
-
return;
|
|
17064
|
-
}
|
|
17065
17086
|
const read = async () => requireSqlSuccess(await this.sql.get(
|
|
17066
17087
|
"SELECT EXTRA AS extra FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND COLUMN_NAME = ?",
|
|
17067
17088
|
[this.table, key]
|
|
@@ -17076,36 +17097,32 @@ var ReldbAIRelStore = class _ReldbAIRelStore {
|
|
|
17076
17097
|
}
|
|
17077
17098
|
if ((await read())?.extra !== "VIRTUAL GENERATED")
|
|
17078
17099
|
throw new Error(aiM("ai_storeIndexMismatch"));
|
|
17079
|
-
await this.
|
|
17100
|
+
await this.createMysqlIndex(name, key);
|
|
17080
17101
|
}
|
|
17081
17102
|
/**
|
|
17082
17103
|
* MySQL 并发首次创建只接受明确的重复名称错误,并重读结构,权限/DDL/不匹配仍失败。
|
|
17083
17104
|
*/
|
|
17084
|
-
async
|
|
17085
|
-
|
|
17086
|
-
|
|
17087
|
-
|
|
17088
|
-
|
|
17089
|
-
|
|
17090
|
-
|
|
17091
|
-
|
|
17092
|
-
|
|
17093
|
-
if (existing
|
|
17094
|
-
|
|
17095
|
-
throw new Error(aiM("ai_storeIndexMismatch"));
|
|
17096
|
-
return;
|
|
17097
|
-
}
|
|
17098
|
-
try {
|
|
17099
|
-
await this.sql.execute(`CREATE INDEX ${name} ON ${this.table}(${columns})`);
|
|
17100
|
-
} catch (error) {
|
|
17101
|
-
if (!isMysqlError(error, "ER_DUP_KEYNAME", 1061))
|
|
17102
|
-
throw error;
|
|
17103
|
-
if (!matches(await read()))
|
|
17104
|
-
throw new Error(aiM("ai_storeIndexMismatch"), { cause: error });
|
|
17105
|
-
}
|
|
17105
|
+
async createMysqlIndex(name, columns) {
|
|
17106
|
+
const read = async () => requireSqlSuccess(await this.sql.query(
|
|
17107
|
+
"SELECT COLUMN_NAME AS column_name, SEQ_IN_INDEX AS seq_in_index, NON_UNIQUE AS non_unique, SUB_PART AS sub_part, INDEX_TYPE AS index_type, COLLATION AS collation, IS_VISIBLE AS is_visible, EXPRESSION AS expression FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND INDEX_NAME = ? ORDER BY SEQ_IN_INDEX",
|
|
17108
|
+
[this.table, name]
|
|
17109
|
+
)).data;
|
|
17110
|
+
const expected = columns.split(",").map((column) => column.trim());
|
|
17111
|
+
const matches = (definition) => definition.length === expected.length && definition.every((column, index) => column.column_name === expected[index] && Number(column.seq_in_index) === index + 1 && Number(column.non_unique) === 1 && column.sub_part === null && column.index_type === "BTREE" && column.collation === "A" && column.is_visible === "YES" && column.expression === null);
|
|
17112
|
+
const existing = await read();
|
|
17113
|
+
if (existing.length > 0) {
|
|
17114
|
+
if (!matches(existing))
|
|
17115
|
+
throw new Error(aiM("ai_storeIndexMismatch"));
|
|
17106
17116
|
return;
|
|
17107
17117
|
}
|
|
17108
|
-
|
|
17118
|
+
try {
|
|
17119
|
+
await this.sql.execute(`CREATE INDEX ${name} ON ${this.table}(${columns})`);
|
|
17120
|
+
} catch (error) {
|
|
17121
|
+
if (!isMysqlError(error, "ER_DUP_KEYNAME", 1061))
|
|
17122
|
+
throw error;
|
|
17123
|
+
if (!matches(await read()))
|
|
17124
|
+
throw new Error(aiM("ai_storeIndexMismatch"), { cause: error });
|
|
17125
|
+
}
|
|
17109
17126
|
}
|
|
17110
17127
|
/** 普通写入也更换版本,使并发条件写入识别所有较新修改。 */
|
|
17111
17128
|
async save(id3, data, scope) {
|
|
@@ -17562,9 +17579,32 @@ var VecdbAIVectorStore = class {
|
|
|
17562
17579
|
}
|
|
17563
17580
|
};
|
|
17564
17581
|
function createDbStoreProvider(deps) {
|
|
17565
|
-
const { sql, jsonOps, vecdb: vecdbDep } = deps;
|
|
17582
|
+
const { sql, tx, jsonOps, vecdb: vecdbDep } = deps;
|
|
17566
17583
|
const dbType = deps.dbType ?? "sqlite";
|
|
17567
17584
|
const relStores = /* @__PURE__ */ new Map();
|
|
17585
|
+
async function prepareTables(groups) {
|
|
17586
|
+
if (dbType === "postgresql") {
|
|
17587
|
+
if (!tx)
|
|
17588
|
+
throw new TypeError(aiM("ai_storeTransactionRequired"));
|
|
17589
|
+
requireSqlSuccess(await tx.wrap(async (connection) => {
|
|
17590
|
+
requireSqlSuccess(await connection.execute("SET TRANSACTION ISOLATION LEVEL READ COMMITTED"));
|
|
17591
|
+
requireSqlSuccess(await connection.execute("SELECT pg_catalog.pg_advisory_xact_lock(pg_catalog.hashtextextended(?, 0))", [POSTGRES_SCHEMA_LOCK]));
|
|
17592
|
+
for (const stores of groups) {
|
|
17593
|
+
for (const store of stores)
|
|
17594
|
+
await store.createTable(connection);
|
|
17595
|
+
}
|
|
17596
|
+
}));
|
|
17597
|
+
return;
|
|
17598
|
+
}
|
|
17599
|
+
const results = await Promise.allSettled(Array.from(groups, async (stores) => {
|
|
17600
|
+
for (const store of stores)
|
|
17601
|
+
await store.createTable();
|
|
17602
|
+
}));
|
|
17603
|
+
for (const result of results) {
|
|
17604
|
+
if (result.status === "rejected")
|
|
17605
|
+
throw result.reason;
|
|
17606
|
+
}
|
|
17607
|
+
}
|
|
17568
17608
|
return {
|
|
17569
17609
|
name: "db",
|
|
17570
17610
|
get stateScope() {
|
|
@@ -17573,7 +17613,7 @@ function createDbStoreProvider(deps) {
|
|
|
17573
17613
|
return dbType !== "sqlite" && sharedVector ? "shared" : "local";
|
|
17574
17614
|
},
|
|
17575
17615
|
createRelStore(name, options) {
|
|
17576
|
-
const store = new ReldbAIRelStore(sql, name, jsonOps, dbType, options,
|
|
17616
|
+
const store = new ReldbAIRelStore(sql, name, jsonOps, dbType, options, tx);
|
|
17577
17617
|
const stores = relStores.get(name) ?? [];
|
|
17578
17618
|
stores.push(store);
|
|
17579
17619
|
relStores.set(name, stores);
|
|
@@ -17593,24 +17633,14 @@ function createDbStoreProvider(deps) {
|
|
|
17593
17633
|
documents,
|
|
17594
17634
|
collections,
|
|
17595
17635
|
vecdb: vecdbDep,
|
|
17596
|
-
prepare:
|
|
17597
|
-
|
|
17598
|
-
|
|
17599
|
-
}
|
|
17636
|
+
prepare: () => prepareTables([
|
|
17637
|
+
[documents, collections]
|
|
17638
|
+
])
|
|
17600
17639
|
});
|
|
17601
17640
|
},
|
|
17602
17641
|
async initialize() {
|
|
17603
17642
|
if (relStores.size > 0) {
|
|
17604
|
-
|
|
17605
|
-
...relStores.values()
|
|
17606
|
-
].map(async (stores) => {
|
|
17607
|
-
for (const store of stores)
|
|
17608
|
-
await store.createTable();
|
|
17609
|
-
}));
|
|
17610
|
-
for (const result of results) {
|
|
17611
|
-
if (result.status === "rejected")
|
|
17612
|
-
throw result.reason;
|
|
17613
|
-
}
|
|
17643
|
+
await prepareTables(relStores.values());
|
|
17614
17644
|
logger34.debug("DB store provider initialized", { tableCount: relStores.size });
|
|
17615
17645
|
}
|
|
17616
17646
|
},
|