@elizaos/plugin-sql 2.0.0-alpha.13 → 2.0.0-alpha.15
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/browser/index.browser.js +611 -1
- package/dist/browser/index.browser.js.map +3 -3
- package/dist/browser/index.d.ts +2 -2
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.node.cjs +7101 -0
- package/dist/cjs/index.node.cjs.map +53 -0
- package/dist/index.d.ts +2 -2
- package/dist/node/index.d.ts +2 -2
- package/dist/node/index.node.js +2344 -7927
- package/dist/node/index.node.js.map +6 -105
- package/package.json +2 -1
|
@@ -3789,6 +3789,76 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
|
|
|
3789
3789
|
});
|
|
3790
3790
|
return result || [];
|
|
3791
3791
|
}
|
|
3792
|
+
async getAgentsByIds(agentIds) {
|
|
3793
|
+
if (agentIds.length === 0)
|
|
3794
|
+
return [];
|
|
3795
|
+
return this.withDatabase(async () => {
|
|
3796
|
+
const rows = await this.db.select().from(agentTable).where(inArray(agentTable.id, agentIds));
|
|
3797
|
+
return rows.map((row) => {
|
|
3798
|
+
const bioValue = !row.bio ? "" : Array.isArray(row.bio) ? row.bio : row.bio;
|
|
3799
|
+
return {
|
|
3800
|
+
...row,
|
|
3801
|
+
username: row.username || "",
|
|
3802
|
+
id: row.id,
|
|
3803
|
+
system: !row.system ? undefined : row.system,
|
|
3804
|
+
bio: bioValue,
|
|
3805
|
+
createdAt: row.createdAt.getTime(),
|
|
3806
|
+
updatedAt: row.updatedAt.getTime()
|
|
3807
|
+
};
|
|
3808
|
+
});
|
|
3809
|
+
});
|
|
3810
|
+
}
|
|
3811
|
+
async createAgents(agents) {
|
|
3812
|
+
if (agents.length === 0)
|
|
3813
|
+
return [];
|
|
3814
|
+
return this.withDatabase(async () => {
|
|
3815
|
+
const ids = [];
|
|
3816
|
+
for (const agent of agents) {
|
|
3817
|
+
if (agent.id) {
|
|
3818
|
+
const success = await this.createAgent(agent);
|
|
3819
|
+
if (success)
|
|
3820
|
+
ids.push(agent.id);
|
|
3821
|
+
}
|
|
3822
|
+
}
|
|
3823
|
+
return ids;
|
|
3824
|
+
});
|
|
3825
|
+
}
|
|
3826
|
+
async updateAgents(updates) {
|
|
3827
|
+
for (const { agentId, agent } of updates) {
|
|
3828
|
+
const success = await this.updateAgent(agentId, agent);
|
|
3829
|
+
if (!success)
|
|
3830
|
+
return false;
|
|
3831
|
+
}
|
|
3832
|
+
return true;
|
|
3833
|
+
}
|
|
3834
|
+
async upsertAgents(agents) {
|
|
3835
|
+
for (const agent of agents) {
|
|
3836
|
+
if (!agent.id)
|
|
3837
|
+
continue;
|
|
3838
|
+
const existing = await this.getAgent(agent.id);
|
|
3839
|
+
if (existing) {
|
|
3840
|
+
await this.updateAgent(agent.id, agent);
|
|
3841
|
+
} else {
|
|
3842
|
+
await this.createAgent(agent);
|
|
3843
|
+
}
|
|
3844
|
+
}
|
|
3845
|
+
}
|
|
3846
|
+
async deleteAgents(agentIds) {
|
|
3847
|
+
if (agentIds.length === 0)
|
|
3848
|
+
return true;
|
|
3849
|
+
return this.withDatabase(async () => {
|
|
3850
|
+
try {
|
|
3851
|
+
await this.db.delete(agentTable).where(inArray(agentTable.id, agentIds));
|
|
3852
|
+
return true;
|
|
3853
|
+
} catch (error) {
|
|
3854
|
+
logger9.error({
|
|
3855
|
+
src: "plugin:sql",
|
|
3856
|
+
error: error instanceof Error ? error.message : String(error)
|
|
3857
|
+
}, "Failed to delete agents");
|
|
3858
|
+
return false;
|
|
3859
|
+
}
|
|
3860
|
+
});
|
|
3861
|
+
}
|
|
3792
3862
|
async createAgent(agent) {
|
|
3793
3863
|
const _isDuplicateKeyError = (error) => {
|
|
3794
3864
|
if (!error || typeof error !== "object")
|
|
@@ -5866,6 +5936,546 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
|
|
|
5866
5936
|
await this.db.delete(pairingAllowlistTable).where(eq2(pairingAllowlistTable.id, id));
|
|
5867
5937
|
});
|
|
5868
5938
|
}
|
|
5939
|
+
async isReady() {
|
|
5940
|
+
try {
|
|
5941
|
+
await this.db.execute(sql27`SELECT 1`);
|
|
5942
|
+
return true;
|
|
5943
|
+
} catch {
|
|
5944
|
+
return false;
|
|
5945
|
+
}
|
|
5946
|
+
}
|
|
5947
|
+
async getConnection() {
|
|
5948
|
+
return this.db;
|
|
5949
|
+
}
|
|
5950
|
+
async transaction(callback, _options) {
|
|
5951
|
+
return callback(this);
|
|
5952
|
+
}
|
|
5953
|
+
async getComponentsByNaturalKeys(keys) {
|
|
5954
|
+
if (keys.length === 0)
|
|
5955
|
+
return [];
|
|
5956
|
+
const results = [];
|
|
5957
|
+
for (const key of keys) {
|
|
5958
|
+
const component = await this.getComponent(key.entityId, key.type, key.worldId, key.sourceEntityId);
|
|
5959
|
+
results.push(component);
|
|
5960
|
+
}
|
|
5961
|
+
return results;
|
|
5962
|
+
}
|
|
5963
|
+
async getComponentsForEntities(entityIds, worldId, sourceEntityId) {
|
|
5964
|
+
if (entityIds.length === 0)
|
|
5965
|
+
return [];
|
|
5966
|
+
return this.withDatabase(async () => {
|
|
5967
|
+
const conditions = [inArray(componentTable.entityId, entityIds)];
|
|
5968
|
+
if (worldId) {
|
|
5969
|
+
conditions.push(eq2(componentTable.worldId, worldId));
|
|
5970
|
+
}
|
|
5971
|
+
if (sourceEntityId) {
|
|
5972
|
+
conditions.push(eq2(componentTable.sourceEntityId, sourceEntityId));
|
|
5973
|
+
}
|
|
5974
|
+
const result = await this.db.select().from(componentTable).where(and(...conditions));
|
|
5975
|
+
return result.map((component) => ({
|
|
5976
|
+
...component,
|
|
5977
|
+
id: component.id,
|
|
5978
|
+
entityId: component.entityId,
|
|
5979
|
+
agentId: component.agentId,
|
|
5980
|
+
roomId: component.roomId,
|
|
5981
|
+
worldId: component.worldId ?? "",
|
|
5982
|
+
sourceEntityId: component.sourceEntityId ?? "",
|
|
5983
|
+
data: component.data,
|
|
5984
|
+
createdAt: component.createdAt.getTime()
|
|
5985
|
+
}));
|
|
5986
|
+
});
|
|
5987
|
+
}
|
|
5988
|
+
async createComponents(components) {
|
|
5989
|
+
if (components.length === 0)
|
|
5990
|
+
return [];
|
|
5991
|
+
return this.withDatabase(async () => {
|
|
5992
|
+
const ids = [];
|
|
5993
|
+
for (const component of components) {
|
|
5994
|
+
const success = await this.createComponent(component);
|
|
5995
|
+
if (success)
|
|
5996
|
+
ids.push(component.id);
|
|
5997
|
+
}
|
|
5998
|
+
return ids;
|
|
5999
|
+
});
|
|
6000
|
+
}
|
|
6001
|
+
async getComponentsByIds(componentIds) {
|
|
6002
|
+
if (componentIds.length === 0)
|
|
6003
|
+
return [];
|
|
6004
|
+
return this.withDatabase(async () => {
|
|
6005
|
+
const result = await this.db.select().from(componentTable).where(inArray(componentTable.id, componentIds));
|
|
6006
|
+
return result.map((component) => ({
|
|
6007
|
+
...component,
|
|
6008
|
+
id: component.id,
|
|
6009
|
+
entityId: component.entityId,
|
|
6010
|
+
agentId: component.agentId,
|
|
6011
|
+
roomId: component.roomId,
|
|
6012
|
+
worldId: component.worldId ?? "",
|
|
6013
|
+
sourceEntityId: component.sourceEntityId ?? "",
|
|
6014
|
+
data: component.data,
|
|
6015
|
+
createdAt: component.createdAt.getTime()
|
|
6016
|
+
}));
|
|
6017
|
+
});
|
|
6018
|
+
}
|
|
6019
|
+
async updateComponents(components) {
|
|
6020
|
+
for (const component of components) {
|
|
6021
|
+
await this.updateComponent(component);
|
|
6022
|
+
}
|
|
6023
|
+
}
|
|
6024
|
+
async deleteComponents(componentIds) {
|
|
6025
|
+
if (componentIds.length === 0)
|
|
6026
|
+
return;
|
|
6027
|
+
return this.withDatabase(async () => {
|
|
6028
|
+
await this.db.delete(componentTable).where(inArray(componentTable.id, componentIds));
|
|
6029
|
+
});
|
|
6030
|
+
}
|
|
6031
|
+
async upsertComponents(components, _options) {
|
|
6032
|
+
for (const component of components) {
|
|
6033
|
+
const existing = await this.getComponent(component.entityId, component.type, component.worldId, component.sourceEntityId);
|
|
6034
|
+
if (existing) {
|
|
6035
|
+
await this.updateComponent({ ...component, id: existing.id });
|
|
6036
|
+
} else {
|
|
6037
|
+
await this.createComponent(component);
|
|
6038
|
+
}
|
|
6039
|
+
}
|
|
6040
|
+
}
|
|
6041
|
+
async patchComponents(_updates, _options) {}
|
|
6042
|
+
async upsertEntities(entities) {
|
|
6043
|
+
for (const entity of entities) {
|
|
6044
|
+
const existing = await this.getEntitiesByIds([entity.id]);
|
|
6045
|
+
if (existing && existing.length > 0) {
|
|
6046
|
+
await this.updateEntity(entity);
|
|
6047
|
+
} else {
|
|
6048
|
+
await this.createEntities([entity]);
|
|
6049
|
+
}
|
|
6050
|
+
}
|
|
6051
|
+
}
|
|
6052
|
+
async queryEntities(params) {
|
|
6053
|
+
if (params.entityIds?.length) {
|
|
6054
|
+
const entities = await this.getEntitiesByIds(params.entityIds);
|
|
6055
|
+
return entities || [];
|
|
6056
|
+
}
|
|
6057
|
+
return this.withDatabase(async () => {
|
|
6058
|
+
const conditions = [];
|
|
6059
|
+
if (params.agentId) {
|
|
6060
|
+
conditions.push(eq2(entityTable.agentId, params.agentId));
|
|
6061
|
+
}
|
|
6062
|
+
if (params.componentType) {
|
|
6063
|
+
const subquery = sql27`EXISTS (
|
|
6064
|
+
SELECT 1 FROM ${componentTable}
|
|
6065
|
+
WHERE ${componentTable.entityId} = ${entityTable.id}
|
|
6066
|
+
AND ${componentTable.type} = ${params.componentType}
|
|
6067
|
+
)`;
|
|
6068
|
+
conditions.push(subquery);
|
|
6069
|
+
}
|
|
6070
|
+
let query = this.db.select().from(entityTable).where(conditions.length > 0 ? and(...conditions) : undefined);
|
|
6071
|
+
if (params.limit) {
|
|
6072
|
+
query = query.limit(params.limit);
|
|
6073
|
+
}
|
|
6074
|
+
if (params.offset) {
|
|
6075
|
+
query = query.offset(params.offset);
|
|
6076
|
+
}
|
|
6077
|
+
const result = await query;
|
|
6078
|
+
return result.map((row) => ({
|
|
6079
|
+
...row,
|
|
6080
|
+
id: row.id,
|
|
6081
|
+
agentId: row.agentId,
|
|
6082
|
+
names: row.names || [],
|
|
6083
|
+
metadata: row.metadata || {}
|
|
6084
|
+
}));
|
|
6085
|
+
});
|
|
6086
|
+
}
|
|
6087
|
+
async updateEntities(entities) {
|
|
6088
|
+
for (const entity of entities) {
|
|
6089
|
+
await this.updateEntity(entity);
|
|
6090
|
+
}
|
|
6091
|
+
}
|
|
6092
|
+
async deleteEntities(entityIds) {
|
|
6093
|
+
for (const entityId of entityIds) {
|
|
6094
|
+
await this.deleteEntity(entityId);
|
|
6095
|
+
}
|
|
6096
|
+
}
|
|
6097
|
+
async getEntitiesForRooms(roomIds, includeComponents) {
|
|
6098
|
+
const result = [];
|
|
6099
|
+
for (const roomId of roomIds) {
|
|
6100
|
+
const entities = await this.getEntitiesForRoom(roomId, includeComponents);
|
|
6101
|
+
result.push({ roomId, entities });
|
|
6102
|
+
}
|
|
6103
|
+
return result;
|
|
6104
|
+
}
|
|
6105
|
+
async createLogs(params) {
|
|
6106
|
+
for (const param of params) {
|
|
6107
|
+
await this.log(param);
|
|
6108
|
+
}
|
|
6109
|
+
}
|
|
6110
|
+
async getLogsByIds(logIds) {
|
|
6111
|
+
if (logIds.length === 0)
|
|
6112
|
+
return [];
|
|
6113
|
+
return this.withDatabase(async () => {
|
|
6114
|
+
const result = await this.db.select().from(logTable).where(inArray(logTable.id, logIds));
|
|
6115
|
+
return result.map((log) => ({
|
|
6116
|
+
...log,
|
|
6117
|
+
id: log.id,
|
|
6118
|
+
entityId: log.entityId,
|
|
6119
|
+
roomId: log.roomId,
|
|
6120
|
+
type: log.type,
|
|
6121
|
+
body: log.body,
|
|
6122
|
+
createdAt: new Date(log.createdAt)
|
|
6123
|
+
}));
|
|
6124
|
+
});
|
|
6125
|
+
}
|
|
6126
|
+
async updateLogs(logs) {
|
|
6127
|
+
return this.withDatabase(async () => {
|
|
6128
|
+
for (const { id, updates } of logs) {
|
|
6129
|
+
const setValues = {};
|
|
6130
|
+
if (updates.body !== undefined)
|
|
6131
|
+
setValues.body = updates.body;
|
|
6132
|
+
if (updates.type !== undefined)
|
|
6133
|
+
setValues.type = updates.type;
|
|
6134
|
+
if (Object.keys(setValues).length > 0) {
|
|
6135
|
+
await this.db.update(logTable).set(setValues).where(eq2(logTable.id, id));
|
|
6136
|
+
}
|
|
6137
|
+
}
|
|
6138
|
+
});
|
|
6139
|
+
}
|
|
6140
|
+
async deleteLogs(logIds) {
|
|
6141
|
+
if (logIds.length === 0)
|
|
6142
|
+
return;
|
|
6143
|
+
return this.withDatabase(async () => {
|
|
6144
|
+
await this.db.delete(logTable).where(inArray(logTable.id, logIds));
|
|
6145
|
+
});
|
|
6146
|
+
}
|
|
6147
|
+
async createMemories(memories) {
|
|
6148
|
+
const ids = [];
|
|
6149
|
+
for (const { memory, tableName, unique: unique3 } of memories) {
|
|
6150
|
+
const memoryWithUnique = unique3 !== undefined ? { ...memory, unique: unique3 } : memory;
|
|
6151
|
+
const id = await this.createMemory(memoryWithUnique, tableName);
|
|
6152
|
+
ids.push(id);
|
|
6153
|
+
}
|
|
6154
|
+
return ids;
|
|
6155
|
+
}
|
|
6156
|
+
async updateMemories(memories) {
|
|
6157
|
+
for (const memory of memories) {
|
|
6158
|
+
await this.updateMemory(memory);
|
|
6159
|
+
}
|
|
6160
|
+
}
|
|
6161
|
+
async upsertMemories(memories, _options) {
|
|
6162
|
+
for (const { memory, tableName } of memories) {
|
|
6163
|
+
if (memory.id) {
|
|
6164
|
+
const existing = await this.getMemoryById(memory.id);
|
|
6165
|
+
if (existing) {
|
|
6166
|
+
await this.updateMemory(memory);
|
|
6167
|
+
continue;
|
|
6168
|
+
}
|
|
6169
|
+
}
|
|
6170
|
+
await this.createMemory(memory, tableName);
|
|
6171
|
+
}
|
|
6172
|
+
}
|
|
6173
|
+
async deleteMemories(memoryIds) {
|
|
6174
|
+
await this.deleteManyMemories(memoryIds);
|
|
6175
|
+
}
|
|
6176
|
+
async getWorldsByIds(worldIds) {
|
|
6177
|
+
if (worldIds.length === 0)
|
|
6178
|
+
return [];
|
|
6179
|
+
return this.withDatabase(async () => {
|
|
6180
|
+
const result = await this.db.select().from(worldTable).where(inArray(worldTable.id, worldIds));
|
|
6181
|
+
return result.map((world) => this.mapWorldResult(world));
|
|
6182
|
+
});
|
|
6183
|
+
}
|
|
6184
|
+
async createWorlds(worlds) {
|
|
6185
|
+
const ids = [];
|
|
6186
|
+
for (const world of worlds) {
|
|
6187
|
+
const id = await this.createWorld(world);
|
|
6188
|
+
ids.push(id);
|
|
6189
|
+
}
|
|
6190
|
+
return ids;
|
|
6191
|
+
}
|
|
6192
|
+
async deleteWorlds(worldIds) {
|
|
6193
|
+
for (const id of worldIds) {
|
|
6194
|
+
await this.removeWorld(id);
|
|
6195
|
+
}
|
|
6196
|
+
}
|
|
6197
|
+
async updateWorlds(worlds) {
|
|
6198
|
+
for (const world of worlds) {
|
|
6199
|
+
await this.updateWorld(world);
|
|
6200
|
+
}
|
|
6201
|
+
}
|
|
6202
|
+
async upsertWorlds(worlds) {
|
|
6203
|
+
for (const world of worlds) {
|
|
6204
|
+
const existing = await this.getWorld(world.id);
|
|
6205
|
+
if (existing) {
|
|
6206
|
+
await this.updateWorld(world);
|
|
6207
|
+
} else {
|
|
6208
|
+
await this.createWorld(world);
|
|
6209
|
+
}
|
|
6210
|
+
}
|
|
6211
|
+
}
|
|
6212
|
+
async deleteRoomsByWorldIds(worldIds) {
|
|
6213
|
+
for (const worldId of worldIds) {
|
|
6214
|
+
await this.deleteRoomsByWorldId(worldId);
|
|
6215
|
+
}
|
|
6216
|
+
}
|
|
6217
|
+
async getRoomsByWorlds(worldIds, limit, offset) {
|
|
6218
|
+
if (worldIds.length === 0)
|
|
6219
|
+
return [];
|
|
6220
|
+
return this.withDatabase(async () => {
|
|
6221
|
+
const conditions = [
|
|
6222
|
+
inArray(roomTable.worldId, worldIds),
|
|
6223
|
+
eq2(roomTable.agentId, this.agentId)
|
|
6224
|
+
];
|
|
6225
|
+
let query = this.db.select().from(roomTable).where(and(...conditions));
|
|
6226
|
+
if (offset) {
|
|
6227
|
+
query = query.offset(offset);
|
|
6228
|
+
}
|
|
6229
|
+
if (limit) {
|
|
6230
|
+
query = query.limit(limit);
|
|
6231
|
+
}
|
|
6232
|
+
const result = await query;
|
|
6233
|
+
return result.map((room) => ({
|
|
6234
|
+
...room,
|
|
6235
|
+
id: room.id,
|
|
6236
|
+
name: room.name ?? undefined,
|
|
6237
|
+
agentId: room.agentId,
|
|
6238
|
+
messageServerId: room.messageServerId,
|
|
6239
|
+
serverId: room.messageServerId,
|
|
6240
|
+
worldId: room.worldId,
|
|
6241
|
+
channelId: room.channelId,
|
|
6242
|
+
type: room.type,
|
|
6243
|
+
metadata: room.metadata
|
|
6244
|
+
}));
|
|
6245
|
+
});
|
|
6246
|
+
}
|
|
6247
|
+
async upsertRooms(rooms) {
|
|
6248
|
+
for (const room of rooms) {
|
|
6249
|
+
const existing = await this.getRoomsByIds([room.id]);
|
|
6250
|
+
if (existing && existing.length > 0) {
|
|
6251
|
+
await this.updateRoom(room);
|
|
6252
|
+
} else {
|
|
6253
|
+
await this.createRooms([room]);
|
|
6254
|
+
}
|
|
6255
|
+
}
|
|
6256
|
+
}
|
|
6257
|
+
async createRoomParticipants(entityIds, roomId) {
|
|
6258
|
+
const ids = [];
|
|
6259
|
+
for (const entityId of entityIds) {
|
|
6260
|
+
const success = await this.addParticipant(entityId, roomId);
|
|
6261
|
+
if (success) {
|
|
6262
|
+
ids.push(`${roomId}:${entityId}`);
|
|
6263
|
+
}
|
|
6264
|
+
}
|
|
6265
|
+
return ids;
|
|
6266
|
+
}
|
|
6267
|
+
async deleteParticipants(participants) {
|
|
6268
|
+
for (const { entityId, roomId } of participants) {
|
|
6269
|
+
const success = await this.removeParticipant(entityId, roomId);
|
|
6270
|
+
if (!success)
|
|
6271
|
+
return false;
|
|
6272
|
+
}
|
|
6273
|
+
return true;
|
|
6274
|
+
}
|
|
6275
|
+
async updateParticipants(participants) {
|
|
6276
|
+
for (const { entityId, roomId, updates } of participants) {
|
|
6277
|
+
if (updates.roomState !== undefined) {
|
|
6278
|
+
await this.setParticipantUserState(roomId, entityId, updates.roomState);
|
|
6279
|
+
}
|
|
6280
|
+
}
|
|
6281
|
+
}
|
|
6282
|
+
async updateRooms(rooms) {
|
|
6283
|
+
for (const room of rooms) {
|
|
6284
|
+
await this.updateRoom(room);
|
|
6285
|
+
}
|
|
6286
|
+
}
|
|
6287
|
+
async deleteRooms(roomIds) {
|
|
6288
|
+
for (const roomId of roomIds) {
|
|
6289
|
+
await this.deleteRoom(roomId);
|
|
6290
|
+
}
|
|
6291
|
+
}
|
|
6292
|
+
async getParticipantsForEntities(entityIds) {
|
|
6293
|
+
const result = [];
|
|
6294
|
+
for (const entityId of entityIds) {
|
|
6295
|
+
const participants = await this.getParticipantsForEntity(entityId);
|
|
6296
|
+
result.push(...participants);
|
|
6297
|
+
}
|
|
6298
|
+
return result;
|
|
6299
|
+
}
|
|
6300
|
+
async getParticipantsForRooms(roomIds) {
|
|
6301
|
+
const result = [];
|
|
6302
|
+
for (const roomId of roomIds) {
|
|
6303
|
+
const entityIds = await this.getParticipantsForRoom(roomId);
|
|
6304
|
+
result.push({ roomId, entityIds });
|
|
6305
|
+
}
|
|
6306
|
+
return result;
|
|
6307
|
+
}
|
|
6308
|
+
async areRoomParticipants(pairs) {
|
|
6309
|
+
const results = [];
|
|
6310
|
+
for (const { roomId, entityId } of pairs) {
|
|
6311
|
+
const isParticipant = await this.isRoomParticipant(roomId, entityId);
|
|
6312
|
+
results.push(isParticipant);
|
|
6313
|
+
}
|
|
6314
|
+
return results;
|
|
6315
|
+
}
|
|
6316
|
+
async getParticipantUserStates(pairs) {
|
|
6317
|
+
const results = [];
|
|
6318
|
+
for (const { roomId, entityId } of pairs) {
|
|
6319
|
+
const state = await this.getParticipantUserState(roomId, entityId);
|
|
6320
|
+
results.push(state);
|
|
6321
|
+
}
|
|
6322
|
+
return results;
|
|
6323
|
+
}
|
|
6324
|
+
async updateParticipantUserStates(updates) {
|
|
6325
|
+
for (const { roomId, entityId, state } of updates) {
|
|
6326
|
+
await this.setParticipantUserState(roomId, entityId, state);
|
|
6327
|
+
}
|
|
6328
|
+
}
|
|
6329
|
+
async getRelationshipsByPairs(pairs) {
|
|
6330
|
+
const results = [];
|
|
6331
|
+
for (const pair of pairs) {
|
|
6332
|
+
const rel = await this.getRelationship(pair);
|
|
6333
|
+
results.push(rel);
|
|
6334
|
+
}
|
|
6335
|
+
return results;
|
|
6336
|
+
}
|
|
6337
|
+
async createRelationships(relationships) {
|
|
6338
|
+
const ids = [];
|
|
6339
|
+
for (const rel of relationships) {
|
|
6340
|
+
const id = v4_default();
|
|
6341
|
+
const success = await this.createRelationship(rel);
|
|
6342
|
+
if (success)
|
|
6343
|
+
ids.push(id);
|
|
6344
|
+
}
|
|
6345
|
+
return ids;
|
|
6346
|
+
}
|
|
6347
|
+
async getRelationshipsByIds(relationshipIds) {
|
|
6348
|
+
if (relationshipIds.length === 0)
|
|
6349
|
+
return [];
|
|
6350
|
+
return this.withDatabase(async () => {
|
|
6351
|
+
const result = await this.db.select().from(relationshipTable).where(inArray(relationshipTable.id, relationshipIds));
|
|
6352
|
+
return result.map((relationship) => ({
|
|
6353
|
+
...relationship,
|
|
6354
|
+
id: relationship.id,
|
|
6355
|
+
sourceEntityId: relationship.sourceEntityId,
|
|
6356
|
+
targetEntityId: relationship.targetEntityId,
|
|
6357
|
+
agentId: relationship.agentId,
|
|
6358
|
+
tags: relationship.tags ?? [],
|
|
6359
|
+
metadata: relationship.metadata ?? {},
|
|
6360
|
+
createdAt: relationship.createdAt.toISOString()
|
|
6361
|
+
}));
|
|
6362
|
+
});
|
|
6363
|
+
}
|
|
6364
|
+
async updateRelationships(relationships) {
|
|
6365
|
+
for (const relationship of relationships) {
|
|
6366
|
+
await this.updateRelationship(relationship);
|
|
6367
|
+
}
|
|
6368
|
+
}
|
|
6369
|
+
async deleteRelationships(relationshipIds) {
|
|
6370
|
+
if (relationshipIds.length === 0)
|
|
6371
|
+
return;
|
|
6372
|
+
return this.withDatabase(async () => {
|
|
6373
|
+
await this.db.delete(relationshipTable).where(inArray(relationshipTable.id, relationshipIds));
|
|
6374
|
+
});
|
|
6375
|
+
}
|
|
6376
|
+
async getCaches(keys) {
|
|
6377
|
+
const result = new Map;
|
|
6378
|
+
for (const key of keys) {
|
|
6379
|
+
const value = await this.getCache(key);
|
|
6380
|
+
if (value !== undefined) {
|
|
6381
|
+
result.set(key, value);
|
|
6382
|
+
}
|
|
6383
|
+
}
|
|
6384
|
+
return result;
|
|
6385
|
+
}
|
|
6386
|
+
async setCaches(entries) {
|
|
6387
|
+
for (const { key, value } of entries) {
|
|
6388
|
+
const success = await this.setCache(key, value);
|
|
6389
|
+
if (!success)
|
|
6390
|
+
return false;
|
|
6391
|
+
}
|
|
6392
|
+
return true;
|
|
6393
|
+
}
|
|
6394
|
+
async deleteCaches(keys) {
|
|
6395
|
+
for (const key of keys) {
|
|
6396
|
+
const success = await this.deleteCache(key);
|
|
6397
|
+
if (!success)
|
|
6398
|
+
return false;
|
|
6399
|
+
}
|
|
6400
|
+
return true;
|
|
6401
|
+
}
|
|
6402
|
+
async createTasks(tasks) {
|
|
6403
|
+
const ids = [];
|
|
6404
|
+
for (const task of tasks) {
|
|
6405
|
+
const id = await this.createTask(task);
|
|
6406
|
+
ids.push(id);
|
|
6407
|
+
}
|
|
6408
|
+
return ids;
|
|
6409
|
+
}
|
|
6410
|
+
async getTasksByIds(taskIds) {
|
|
6411
|
+
const tasks = [];
|
|
6412
|
+
for (const taskId of taskIds) {
|
|
6413
|
+
const task = await this.getTask(taskId);
|
|
6414
|
+
if (task)
|
|
6415
|
+
tasks.push(task);
|
|
6416
|
+
}
|
|
6417
|
+
return tasks;
|
|
6418
|
+
}
|
|
6419
|
+
async updateTasks(updates) {
|
|
6420
|
+
for (const { id, task } of updates) {
|
|
6421
|
+
await this.updateTask(id, task);
|
|
6422
|
+
}
|
|
6423
|
+
}
|
|
6424
|
+
async deleteTasks(taskIds) {
|
|
6425
|
+
for (const taskId of taskIds) {
|
|
6426
|
+
await this.deleteTask(taskId);
|
|
6427
|
+
}
|
|
6428
|
+
}
|
|
6429
|
+
async getPairingAllowlists(queries) {
|
|
6430
|
+
const result = [];
|
|
6431
|
+
for (const { channel, agentId } of queries) {
|
|
6432
|
+
const entries = await this.getPairingAllowlist(channel, agentId);
|
|
6433
|
+
result.push({ channel, agentId, entries });
|
|
6434
|
+
}
|
|
6435
|
+
return result;
|
|
6436
|
+
}
|
|
6437
|
+
async createPairingRequests(requests) {
|
|
6438
|
+
const ids = [];
|
|
6439
|
+
for (const request of requests) {
|
|
6440
|
+
const id = await this.createPairingRequest(request);
|
|
6441
|
+
ids.push(id);
|
|
6442
|
+
}
|
|
6443
|
+
return ids;
|
|
6444
|
+
}
|
|
6445
|
+
async updatePairingRequests(requests) {
|
|
6446
|
+
for (const request of requests) {
|
|
6447
|
+
await this.updatePairingRequest(request);
|
|
6448
|
+
}
|
|
6449
|
+
}
|
|
6450
|
+
async deletePairingRequests(ids) {
|
|
6451
|
+
for (const id of ids) {
|
|
6452
|
+
await this.deletePairingRequest(id);
|
|
6453
|
+
}
|
|
6454
|
+
}
|
|
6455
|
+
async createPairingAllowlistEntries(entries) {
|
|
6456
|
+
const ids = [];
|
|
6457
|
+
for (const entry of entries) {
|
|
6458
|
+
const id = await this.createPairingAllowlistEntry(entry);
|
|
6459
|
+
ids.push(id);
|
|
6460
|
+
}
|
|
6461
|
+
return ids;
|
|
6462
|
+
}
|
|
6463
|
+
async updatePairingAllowlistEntries(entries) {
|
|
6464
|
+
return this.withDatabase(async () => {
|
|
6465
|
+
for (const entry of entries) {
|
|
6466
|
+
if (!entry.id)
|
|
6467
|
+
continue;
|
|
6468
|
+
await this.db.update(pairingAllowlistTable).set({
|
|
6469
|
+
metadata: entry.metadata || {}
|
|
6470
|
+
}).where(eq2(pairingAllowlistTable.id, entry.id));
|
|
6471
|
+
}
|
|
6472
|
+
});
|
|
6473
|
+
}
|
|
6474
|
+
async deletePairingAllowlistEntries(ids) {
|
|
6475
|
+
for (const id of ids) {
|
|
6476
|
+
await this.deletePairingAllowlistEntry(id);
|
|
6477
|
+
}
|
|
6478
|
+
}
|
|
5869
6479
|
}
|
|
5870
6480
|
|
|
5871
6481
|
// pglite/adapter.ts
|
|
@@ -6095,5 +6705,5 @@ export {
|
|
|
6095
6705
|
DatabaseMigrationService
|
|
6096
6706
|
};
|
|
6097
6707
|
|
|
6098
|
-
//# debugId=
|
|
6708
|
+
//# debugId=2BF5F5F274B3DB0364756E2164756E21
|
|
6099
6709
|
//# sourceMappingURL=index.browser.js.map
|