@relayfx/sdk 0.0.27 → 0.0.28
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/index.js +1435 -1115
- package/dist/types/store-sql/address/address-book-repository.d.ts +11 -2
- package/dist/types/store-sql/agent/agent-definition-repository.d.ts +17 -2
- package/dist/types/store-sql/child/child-execution-repository.d.ts +11 -2
- package/dist/types/store-sql/cluster/cluster-registry-repository.d.ts +4 -4
- package/dist/types/store-sql/compaction/compaction-repository.d.ts +10 -2
- package/dist/types/store-sql/permission/permission-rule-repository.d.ts +9 -3
- package/dist/types/store-sql/session/context-epoch-repository.d.ts +8 -2
- package/dist/types/store-sql/tool/tool-call-repository.d.ts +17 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -863,10 +863,11 @@ __export(exports_address_book_repository, {
|
|
|
863
863
|
Service: () => Service3,
|
|
864
864
|
RouteKind: () => RouteKind2,
|
|
865
865
|
AddressNotFound: () => AddressNotFound,
|
|
866
|
+
AddressBookRow: () => AddressBookRow,
|
|
866
867
|
AddressBookRepositoryError: () => AddressBookRepositoryError
|
|
867
868
|
});
|
|
868
|
-
import {
|
|
869
|
-
import
|
|
869
|
+
import { Clock, Context as Context3, Effect as Effect3, Layer as Layer3, Schema as Schema13 } from "effect";
|
|
870
|
+
import * as SqlClient3 from "effect/unstable/sql/SqlClient";
|
|
870
871
|
|
|
871
872
|
// ../store-sql/src/database/database-service.ts
|
|
872
873
|
var exports_database_service = {};
|
|
@@ -954,539 +955,143 @@ var encodeJson = (value) => JSON.stringify(value);
|
|
|
954
955
|
var decodeJson = (value) => typeof value === "string" ? JSON.parse(value) : value;
|
|
955
956
|
var decodeBool = (value) => value === true || value === 1 || value === "1";
|
|
956
957
|
|
|
957
|
-
// ../store-sql/src/
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
958
|
+
// ../store-sql/src/tenant/tenant-id.ts
|
|
959
|
+
import { and, eq } from "drizzle-orm";
|
|
960
|
+
import { Context as Context2, Effect as Effect2, Layer as Layer2, Option } from "effect";
|
|
961
|
+
|
|
962
|
+
class Service2 extends Context2.Service()("@relayfx/store-sql/TenantId") {
|
|
963
|
+
}
|
|
964
|
+
var make = (tenantId) => Service2.of({ tenantId });
|
|
965
|
+
var layer2 = (tenantId) => Layer2.succeed(Service2, make(tenantId));
|
|
966
|
+
var systemLayer = layer2(exports_ids_schema.SystemTenantId);
|
|
967
|
+
var current = Effect2.gen(function* () {
|
|
968
|
+
const service = yield* Effect2.serviceOption(Service2);
|
|
969
|
+
return Option.match(service, {
|
|
970
|
+
onNone: () => exports_ids_schema.SystemTenantId,
|
|
971
|
+
onSome: (value) => value.tenantId
|
|
972
|
+
});
|
|
973
|
+
}).pipe(Effect2.withSpan("TenantId.current"));
|
|
974
|
+
var predicate = (tenantId, tenantColumn, ...conditions) => and(eq(tenantColumn, tenantId), ...conditions);
|
|
975
|
+
|
|
976
|
+
// ../store-sql/src/address/address-book-repository.ts
|
|
977
|
+
var RouteKind2 = exports_address_schema.RouteKind;
|
|
978
|
+
|
|
979
|
+
class AddressNotFound extends Schema13.TaggedErrorClass()("AddressNotFound", {
|
|
980
|
+
address_id: exports_ids_schema.AddressId
|
|
981
|
+
}) {
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
class AddressBookRepositoryError extends Schema13.TaggedErrorClass()("AddressBookRepositoryError", {
|
|
985
|
+
message: Schema13.String
|
|
986
|
+
}) {
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
class Service3 extends Context3.Service()("@relayfx/store-sql/AddressBookRepository") {
|
|
990
|
+
}
|
|
991
|
+
var AddressBookRow = Schema13.Struct({
|
|
992
|
+
id: Schema13.String,
|
|
993
|
+
address_id: Schema13.String,
|
|
994
|
+
route_kind: Schema13.String,
|
|
995
|
+
route_key: Schema13.String,
|
|
996
|
+
metadata_json: Schema13.Unknown,
|
|
997
|
+
created_at: Schema13.Union([Schema13.Date, Schema13.String, Schema13.Number]),
|
|
998
|
+
updated_at: Schema13.Union([Schema13.Date, Schema13.String, Schema13.Number])
|
|
999
|
+
}).annotate({ identifier: "Relay.AddressBook.Row" });
|
|
1000
|
+
var metadata = (input) => input.metadata ?? {};
|
|
1001
|
+
var toEntry = (row) => ({
|
|
1002
|
+
id: exports_ids_schema.AddressBookEntryId.make(row.id),
|
|
1003
|
+
addressId: exports_ids_schema.AddressId.make(row.address_id),
|
|
1004
|
+
routeKind: row.route_kind,
|
|
1005
|
+
routeKey: row.route_key,
|
|
1006
|
+
metadata: decodeJson(row.metadata_json),
|
|
1007
|
+
createdAt: fromDbTimestamp(row.created_at),
|
|
1008
|
+
updatedAt: fromDbTimestamp(row.updated_at)
|
|
988
1009
|
});
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
},
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
tenantId: tenantId(),
|
|
1045
|
-
id: text2("id").$type().notNull(),
|
|
1046
|
-
name: text2("name").notNull(),
|
|
1047
|
-
currentRevision: integer("current_revision").$type().notNull(),
|
|
1048
|
-
definitionJson: jsonb("definition_json").$type().notNull(),
|
|
1049
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
1050
|
-
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
|
|
1051
|
-
}, (table) => [
|
|
1052
|
-
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_skill_definitions" }),
|
|
1053
|
-
index("idx_relay_skill_definitions_name").on(table.tenantId, table.name)
|
|
1054
|
-
]);
|
|
1055
|
-
var relaySkillDefinitionRevisions = pgTable("relay_skill_definition_revisions", {
|
|
1056
|
-
tenantId: tenantId(),
|
|
1057
|
-
skillDefinitionId: text2("skill_definition_id").notNull().$type(),
|
|
1058
|
-
revision: integer("revision").notNull().$type(),
|
|
1059
|
-
name: text2("name").notNull(),
|
|
1060
|
-
definitionJson: jsonb("definition_json").$type().notNull(),
|
|
1061
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
1062
|
-
}, (table) => [
|
|
1063
|
-
primaryKey({
|
|
1064
|
-
columns: [table.tenantId, table.skillDefinitionId, table.revision],
|
|
1065
|
-
name: "pk_relay_skill_definition_revisions"
|
|
1066
|
-
}),
|
|
1067
|
-
index("idx_relay_skill_definition_revisions_definition").on(table.tenantId, table.skillDefinitionId, table.revision)
|
|
1068
|
-
]);
|
|
1069
|
-
var relayExecutionSkillPins = pgTable("relay_execution_skill_pins", {
|
|
1070
|
-
tenantId: tenantId(),
|
|
1071
|
-
executionId: text2("execution_id").notNull().$type(),
|
|
1072
|
-
skillDefinitionId: text2("skill_definition_id").notNull().$type(),
|
|
1073
|
-
skillDefinitionRevision: integer("skill_definition_revision").notNull().$type(),
|
|
1074
|
-
skillDefinitionSnapshotJson: jsonb("skill_definition_snapshot_json").$type().notNull(),
|
|
1075
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
1076
|
-
}, (table) => [
|
|
1077
|
-
primaryKey({
|
|
1078
|
-
columns: [table.tenantId, table.executionId, table.skillDefinitionId],
|
|
1079
|
-
name: "pk_relay_execution_skill_pins"
|
|
1080
|
-
}),
|
|
1081
|
-
index("idx_relay_execution_skill_pins_execution").on(table.tenantId, table.executionId)
|
|
1082
|
-
]);
|
|
1083
|
-
var relayAgentChats = pgTable("relay_agent_chats", {
|
|
1084
|
-
tenantId: tenantId(),
|
|
1085
|
-
executionId: text2("execution_id").$type().notNull(),
|
|
1086
|
-
exportJson: jsonb("export_json").notNull(),
|
|
1087
|
-
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
|
|
1088
|
-
}, (table) => [primaryKey({ columns: [table.tenantId, table.executionId], name: "pk_relay_agent_chats" })]);
|
|
1089
|
-
var relayAgentCompactions = pgTable("relay_agent_compactions", {
|
|
1090
|
-
tenantId: tenantId(),
|
|
1091
|
-
executionId: text2("execution_id").notNull().$type(),
|
|
1092
|
-
checkpointId: text2("checkpoint_id").notNull(),
|
|
1093
|
-
summary: text2("summary").notNull(),
|
|
1094
|
-
firstKeptEntryId: text2("first_kept_entry_id").$type().notNull(),
|
|
1095
|
-
turn: integer("turn").notNull(),
|
|
1096
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
1097
|
-
}, (table) => [
|
|
1098
|
-
primaryKey({
|
|
1099
|
-
columns: [table.tenantId, table.executionId, table.checkpointId],
|
|
1100
|
-
name: "pk_relay_agent_compactions"
|
|
1101
|
-
}),
|
|
1102
|
-
index("idx_relay_agent_compactions_execution_turn").on(table.tenantId, table.executionId, table.turn)
|
|
1103
|
-
]);
|
|
1104
|
-
var relayMemoryRecords = pgTable("relay_memory_records", {
|
|
1105
|
-
tenantId: tenantId(),
|
|
1106
|
-
id: text2("id").notNull(),
|
|
1107
|
-
agent: text2("agent").notNull(),
|
|
1108
|
-
subject: text2("subject").$type().notNull(),
|
|
1109
|
-
embedding: doublePrecision("embedding").array().notNull(),
|
|
1110
|
-
partsJson: jsonb("parts_json").$type().notNull(),
|
|
1111
|
-
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
1112
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
1113
|
-
}, (table) => [
|
|
1114
|
-
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_memory_records" }),
|
|
1115
|
-
index("idx_relay_memory_records_agent_subject").on(table.tenantId, table.agent, table.subject)
|
|
1116
|
-
]);
|
|
1117
|
-
var relayPermissionRules = pgTable("relay_permission_rules", {
|
|
1118
|
-
tenantId: tenantId(),
|
|
1119
|
-
agent: text2("agent").notNull(),
|
|
1120
|
-
scope: text2("scope").notNull(),
|
|
1121
|
-
pattern: text2("pattern").notNull(),
|
|
1122
|
-
ruleJson: jsonb("rule_json").$type().notNull(),
|
|
1123
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
1124
|
-
}, (table) => [
|
|
1125
|
-
primaryKey({
|
|
1126
|
-
columns: [table.tenantId, table.agent, table.scope, table.pattern],
|
|
1127
|
-
name: "pk_relay_permission_rules"
|
|
1128
|
-
}),
|
|
1129
|
-
index("idx_relay_permission_rules_agent_scope").on(table.tenantId, table.agent, table.scope)
|
|
1130
|
-
]);
|
|
1131
|
-
var relaySteeringMessages = pgTable("relay_steering_messages", {
|
|
1132
|
-
tenantId: tenantId(),
|
|
1133
|
-
executionId: text2("execution_id").notNull(),
|
|
1134
|
-
kind: text2("kind").notNull(),
|
|
1135
|
-
sequence: integer("sequence").notNull(),
|
|
1136
|
-
contentJson: jsonb("content_json").$type().notNull(),
|
|
1137
|
-
drainId: text2("drain_id"),
|
|
1138
|
-
consumedAt: timestamp("consumed_at", { withTimezone: true }),
|
|
1139
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
1140
|
-
}, (table) => [
|
|
1141
|
-
primaryKey({
|
|
1142
|
-
columns: [table.tenantId, table.executionId, table.kind, table.sequence],
|
|
1143
|
-
name: "pk_relay_steering_messages"
|
|
1144
|
-
}),
|
|
1145
|
-
index("idx_relay_steering_messages_unconsumed").on(table.tenantId, table.executionId, table.kind, table.consumedAt, table.sequence),
|
|
1146
|
-
index("idx_relay_steering_messages_drain").on(table.tenantId, table.executionId, table.kind, table.drainId, table.sequence)
|
|
1147
|
-
]);
|
|
1148
|
-
var relaySteeringDrains = pgTable("relay_steering_drains", {
|
|
1149
|
-
tenantId: tenantId(),
|
|
1150
|
-
executionId: text2("execution_id").notNull(),
|
|
1151
|
-
kind: text2("kind").notNull(),
|
|
1152
|
-
drainId: text2("drain_id").notNull(),
|
|
1153
|
-
messageSequencesJson: jsonb("message_sequences_json").$type().notNull().default([]),
|
|
1154
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
1155
|
-
}, (table) => [
|
|
1156
|
-
primaryKey({
|
|
1157
|
-
columns: [table.tenantId, table.executionId, table.kind, table.drainId],
|
|
1158
|
-
name: "pk_relay_steering_drains"
|
|
1159
|
-
})
|
|
1160
|
-
]);
|
|
1161
|
-
var relaySessions = pgTable("relay_sessions", {
|
|
1162
|
-
tenantId: tenantId(),
|
|
1163
|
-
id: text2("id").$type().notNull(),
|
|
1164
|
-
rootAddressId: text2("root_address_id").$type().notNull(),
|
|
1165
|
-
leafEntryId: text2("leaf_entry_id").$type(),
|
|
1166
|
-
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
1167
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
1168
|
-
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
|
|
1169
|
-
}, (table) => [
|
|
1170
|
-
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_sessions" }),
|
|
1171
|
-
index("idx_relay_sessions_updated_id").on(table.tenantId, table.updatedAt, table.id),
|
|
1172
|
-
index("idx_relay_sessions_root_updated_id").on(table.tenantId, table.rootAddressId, table.updatedAt, table.id)
|
|
1173
|
-
]);
|
|
1174
|
-
var relaySessionEntries = pgTable("relay_session_entries", {
|
|
1175
|
-
tenantId: tenantId(),
|
|
1176
|
-
id: text2("id").$type().notNull(),
|
|
1177
|
-
sessionId: text2("session_id").$type().notNull(),
|
|
1178
|
-
parentId: text2("parent_id").$type(),
|
|
1179
|
-
tag: text2("tag").notNull(),
|
|
1180
|
-
payloadJson: jsonb("payload_json").notNull(),
|
|
1181
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
1182
|
-
}, (table) => [
|
|
1183
|
-
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_session_entries" }),
|
|
1184
|
-
index("idx_relay_session_entries_session_created").on(table.tenantId, table.sessionId, table.createdAt, table.id),
|
|
1185
|
-
index("idx_relay_session_entries_session_parent").on(table.tenantId, table.sessionId, table.parentId)
|
|
1186
|
-
]);
|
|
1187
|
-
var relayExecutionContextEpochs = pgTable("relay_execution_context_epochs", {
|
|
1188
|
-
tenantId: tenantId(),
|
|
1189
|
-
executionId: text2("execution_id").$type().notNull(),
|
|
1190
|
-
baseline: text2("baseline").notNull(),
|
|
1191
|
-
dynamicSourceIdsJson: jsonb("dynamic_source_ids_json").$type().notNull().default([]),
|
|
1192
|
-
openedAt: timestamp("opened_at", { withTimezone: true }).notNull().defaultNow()
|
|
1193
|
-
}, (table) => [primaryKey({ columns: [table.tenantId, table.executionId], name: "pk_relay_execution_context_epochs" })]);
|
|
1194
|
-
var relayExecutions = pgTable("relay_executions", {
|
|
1195
|
-
tenantId: tenantId(),
|
|
1196
|
-
id: text2("id").$type().notNull(),
|
|
1197
|
-
rootAddressId: text2("root_address_id").$type().notNull(),
|
|
1198
|
-
sessionId: text2("session_id").$type(),
|
|
1199
|
-
status: text2("status").$type().notNull(),
|
|
1200
|
-
agentDefinitionId: text2("agent_definition_id").$type(),
|
|
1201
|
-
agentDefinitionRevision: integer("agent_definition_revision").$type(),
|
|
1202
|
-
agentDefinitionSnapshotJson: jsonb("agent_definition_snapshot_json").$type(),
|
|
1203
|
-
agentDefinitionToolInputSchemaDigestsJson: jsonb("agent_definition_tool_input_schema_digests_json").$type().notNull().default({}),
|
|
1204
|
-
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
1205
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
1206
|
-
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
|
|
1207
|
-
}, (table) => [
|
|
1208
|
-
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_executions" }),
|
|
1209
|
-
index("idx_relay_executions_root_status").on(table.tenantId, table.rootAddressId, table.status),
|
|
1210
|
-
index("idx_relay_executions_session_updated_id").on(table.tenantId, table.sessionId, table.updatedAt, table.id),
|
|
1211
|
-
index("idx_relay_executions_updated_id").on(table.tenantId, table.updatedAt, table.id),
|
|
1212
|
-
index("idx_relay_executions_root_status_updated_id").on(table.tenantId, table.rootAddressId, table.status, table.updatedAt, table.id)
|
|
1213
|
-
]);
|
|
1214
|
-
var relayChildExecutions = pgTable("relay_child_executions", {
|
|
1215
|
-
tenantId: tenantId(),
|
|
1216
|
-
id: text2("id").$type().notNull(),
|
|
1217
|
-
executionId: text2("execution_id").$type().notNull(),
|
|
1218
|
-
addressId: text2("address_id").$type().notNull(),
|
|
1219
|
-
status: text2("status").$type().notNull(),
|
|
1220
|
-
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
1221
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
1222
|
-
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
|
|
1223
|
-
}, (table) => [
|
|
1224
|
-
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_child_executions" }),
|
|
1225
|
-
index("idx_relay_child_executions_parent").on(table.tenantId, table.executionId)
|
|
1226
|
-
]);
|
|
1227
|
-
var relayEnvelopes = pgTable("relay_envelopes", {
|
|
1228
|
-
tenantId: tenantId(),
|
|
1229
|
-
id: text2("id").$type().notNull(),
|
|
1230
|
-
executionId: text2("execution_id").$type().notNull(),
|
|
1231
|
-
fromAddressId: text2("from_address_id").$type().notNull(),
|
|
1232
|
-
toAddressId: text2("to_address_id").$type().notNull(),
|
|
1233
|
-
contentJson: jsonb("content_json").$type().notNull(),
|
|
1234
|
-
waitJson: jsonb("wait_json").$type(),
|
|
1235
|
-
correlationKey: text2("correlation_key"),
|
|
1236
|
-
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
1237
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
1238
|
-
}, (table) => [
|
|
1239
|
-
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_envelopes" }),
|
|
1240
|
-
index("idx_relay_envelopes_execution").on(table.tenantId, table.executionId, table.createdAt),
|
|
1241
|
-
index("idx_relay_envelopes_to_address").on(table.tenantId, table.toAddressId, table.createdAt)
|
|
1242
|
-
]);
|
|
1243
|
-
var relayWaits = pgTable("relay_waits", {
|
|
1244
|
-
tenantId: tenantId(),
|
|
1245
|
-
id: text2("id").$type().notNull(),
|
|
1246
|
-
executionId: text2("execution_id").$type().notNull(),
|
|
1247
|
-
envelopeId: text2("envelope_id").$type(),
|
|
1248
|
-
mode: text2("mode").$type().notNull(),
|
|
1249
|
-
correlationKey: text2("correlation_key"),
|
|
1250
|
-
state: text2("state").notNull().default("open"),
|
|
1251
|
-
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
1252
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
1253
|
-
resolvedAt: timestamp("resolved_at", { withTimezone: true })
|
|
1254
|
-
}, (table) => [
|
|
1255
|
-
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_waits" }),
|
|
1256
|
-
index("idx_relay_waits_execution_state").on(table.tenantId, table.executionId, table.state)
|
|
1257
|
-
]);
|
|
1258
|
-
var relayWorkspaceLeases = pgTable("relay_workspace_leases", {
|
|
1259
|
-
tenantId: tenantId(),
|
|
1260
|
-
id: text2("id").$type().notNull(),
|
|
1261
|
-
executionId: text2("execution_id").$type().notNull(),
|
|
1262
|
-
providerKey: text2("provider_key").$type().notNull(),
|
|
1263
|
-
sandboxRef: text2("sandbox_ref").$type(),
|
|
1264
|
-
latestSnapshotRef: text2("latest_snapshot_ref").$type(),
|
|
1265
|
-
status: text2("status").$type().notNull(),
|
|
1266
|
-
resumeStrategy: text2("resume_strategy").$type().notNull(),
|
|
1267
|
-
region: text2("region"),
|
|
1268
|
-
requestJson: jsonb("request_json").$type(),
|
|
1269
|
-
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
1270
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
1271
|
-
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
|
|
1272
|
-
}, (table) => [
|
|
1273
|
-
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_workspace_leases" }),
|
|
1274
|
-
uniqueIndex("uq_relay_workspace_leases_active_execution").on(table.tenantId, table.executionId).where(sql2`${table.status} not in ('released', 'failed')`),
|
|
1275
|
-
index("idx_relay_workspace_leases_execution").on(table.tenantId, table.executionId),
|
|
1276
|
-
index("idx_relay_workspace_leases_status_updated").on(table.tenantId, table.status, table.updatedAt)
|
|
1277
|
-
]);
|
|
1278
|
-
var relayWorkspaceSnapshots = pgTable("relay_workspace_snapshots", {
|
|
1279
|
-
tenantId: tenantId(),
|
|
1280
|
-
id: text2("id").$type().notNull(),
|
|
1281
|
-
leaseId: text2("lease_id").$type().notNull(),
|
|
1282
|
-
executionId: text2("execution_id").$type().notNull(),
|
|
1283
|
-
reason: text2("reason").$type().notNull(),
|
|
1284
|
-
snapshotRef: text2("snapshot_ref").$type().notNull(),
|
|
1285
|
-
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
1286
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
1287
|
-
}, (table) => [
|
|
1288
|
-
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_workspace_snapshots" }),
|
|
1289
|
-
index("idx_relay_workspace_snapshots_lease").on(table.tenantId, table.leaseId, table.createdAt),
|
|
1290
|
-
index("idx_relay_workspace_snapshots_execution").on(table.tenantId, table.executionId, table.createdAt)
|
|
1291
|
-
]);
|
|
1292
|
-
var relayEnvelopeReady = pgTable("relay_envelope_ready", {
|
|
1293
|
-
tenantId: tenantId(),
|
|
1294
|
-
id: text2("id").$type().notNull(),
|
|
1295
|
-
envelopeId: text2("envelope_id").$type().notNull(),
|
|
1296
|
-
routeType: text2("route_type").notNull(),
|
|
1297
|
-
routeKey: text2("route_key").notNull(),
|
|
1298
|
-
state: text2("state").notNull().default("ready"),
|
|
1299
|
-
availableAt: timestamp("available_at", { withTimezone: true }).notNull().defaultNow(),
|
|
1300
|
-
attempt: integer("attempt").notNull().default(0),
|
|
1301
|
-
claimOwner: text2("claim_owner"),
|
|
1302
|
-
claimExpiresAt: timestamp("claim_expires_at", { withTimezone: true }),
|
|
1303
|
-
lastError: text2("last_error"),
|
|
1304
|
-
idempotencyKey: text2("idempotency_key"),
|
|
1305
|
-
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
1306
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
1307
|
-
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
1308
|
-
claimedAt: timestamp("claimed_at", { withTimezone: true }),
|
|
1309
|
-
acknowledgedAt: timestamp("acknowledged_at", { withTimezone: true })
|
|
1310
|
-
}, (table) => [
|
|
1311
|
-
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_envelope_ready" }),
|
|
1312
|
-
index("idx_relay_envelope_ready_state_available").on(table.tenantId, table.state, table.availableAt),
|
|
1313
|
-
index("idx_relay_envelope_ready_claim_expires").on(table.tenantId, table.claimExpiresAt),
|
|
1314
|
-
uniqueIndex("uq_relay_envelope_ready_idempotency").on(table.tenantId, table.idempotencyKey)
|
|
1315
|
-
]);
|
|
1316
|
-
var relaySchedules = pgTable("relay_schedules", {
|
|
1317
|
-
tenantId: tenantId(),
|
|
1318
|
-
id: text2("id").$type().notNull(),
|
|
1319
|
-
kind: text2("kind").notNull(),
|
|
1320
|
-
targetKind: text2("target_kind").notNull(),
|
|
1321
|
-
addressId: text2("address_id").$type(),
|
|
1322
|
-
waitId: text2("wait_id").$type(),
|
|
1323
|
-
cronExpr: text2("cron_expr"),
|
|
1324
|
-
inputJson: jsonb("input_json").$type(),
|
|
1325
|
-
state: text2("state").notNull().default("active"),
|
|
1326
|
-
nextRunAt: timestamp("next_run_at", { withTimezone: true }).notNull(),
|
|
1327
|
-
attempt: integer("attempt").notNull().default(0),
|
|
1328
|
-
claimOwner: text2("claim_owner"),
|
|
1329
|
-
claimExpiresAt: timestamp("claim_expires_at", { withTimezone: true }),
|
|
1330
|
-
lastError: text2("last_error"),
|
|
1331
|
-
idempotencyKey: text2("idempotency_key"),
|
|
1332
|
-
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
1333
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
1334
|
-
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
|
|
1335
|
-
}, (table) => [
|
|
1336
|
-
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_schedules" }),
|
|
1337
|
-
index("idx_relay_schedules_state_next_run").on(table.tenantId, table.state, table.nextRunAt),
|
|
1338
|
-
index("idx_relay_schedules_claim_expires").on(table.tenantId, table.claimExpiresAt),
|
|
1339
|
-
index("idx_relay_schedules_wait").on(table.tenantId, table.waitId),
|
|
1340
|
-
uniqueIndex("uq_relay_schedules_idempotency").on(table.tenantId, table.idempotencyKey)
|
|
1341
|
-
]);
|
|
1342
|
-
var relayExecutionEvents = pgTable("relay_execution_events", {
|
|
1343
|
-
tenantId: tenantId(),
|
|
1344
|
-
id: text2("id").$type().notNull(),
|
|
1345
|
-
executionId: text2("execution_id").$type().notNull(),
|
|
1346
|
-
childExecutionId: text2("child_execution_id").$type(),
|
|
1347
|
-
type: text2("type").notNull(),
|
|
1348
|
-
sequence: integer("sequence").notNull(),
|
|
1349
|
-
cursor: text2("cursor").notNull(),
|
|
1350
|
-
contentJson: jsonb("content_json").$type(),
|
|
1351
|
-
dataJson: jsonb("data_json").$type().notNull().default({}),
|
|
1352
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
1353
|
-
}, (table) => [
|
|
1354
|
-
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_execution_events" }),
|
|
1355
|
-
index("idx_relay_execution_events_execution").on(table.tenantId, table.executionId, table.createdAt),
|
|
1356
|
-
uniqueIndex("uq_relay_execution_events_sequence").on(table.tenantId, table.executionId, table.sequence),
|
|
1357
|
-
uniqueIndex("uq_relay_execution_events_cursor").on(table.tenantId, table.cursor)
|
|
1358
|
-
]);
|
|
1359
|
-
var relayToolCalls = pgTable("relay_tool_calls", {
|
|
1360
|
-
tenantId: tenantId(),
|
|
1361
|
-
id: text2("id").$type().notNull(),
|
|
1362
|
-
executionId: text2("execution_id").$type().notNull(),
|
|
1363
|
-
name: text2("name").notNull(),
|
|
1364
|
-
inputJson: jsonb("input_json").notNull(),
|
|
1365
|
-
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
1366
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
1367
|
-
}, (table) => [
|
|
1368
|
-
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_tool_calls" }),
|
|
1369
|
-
index("idx_relay_tool_calls_execution").on(table.tenantId, table.executionId, table.createdAt)
|
|
1370
|
-
]);
|
|
1371
|
-
var relayToolResults = pgTable("relay_tool_results", {
|
|
1372
|
-
tenantId: tenantId(),
|
|
1373
|
-
toolCallId: text2("tool_call_id").$type().notNull(),
|
|
1374
|
-
outputJson: jsonb("output_json").notNull(),
|
|
1375
|
-
error: text2("error"),
|
|
1376
|
-
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
1377
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
1378
|
-
}, (table) => [primaryKey({ columns: [table.tenantId, table.toolCallId], name: "pk_relay_tool_results" })]);
|
|
1379
|
-
var relayRouteAttempts = pgTable("relay_route_attempts", {
|
|
1380
|
-
tenantId: tenantId(),
|
|
1381
|
-
id: text2("id").notNull(),
|
|
1382
|
-
envelopeReadyId: text2("envelope_ready_id").$type().notNull(),
|
|
1383
|
-
routeKey: text2("route_key").notNull(),
|
|
1384
|
-
state: text2("state").notNull(),
|
|
1385
|
-
detail: text2("detail"),
|
|
1386
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
1387
|
-
}, (table) => [
|
|
1388
|
-
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_route_attempts" }),
|
|
1389
|
-
index("idx_relay_route_attempts_ready").on(table.tenantId, table.envelopeReadyId, table.createdAt)
|
|
1390
|
-
]);
|
|
1391
|
-
var relayIdempotencyKeys = pgTable("relay_idempotency_keys", {
|
|
1392
|
-
tenantId: tenantId(),
|
|
1393
|
-
id: text2("id").notNull(),
|
|
1394
|
-
scope: text2("scope").notNull(),
|
|
1395
|
-
operation: text2("operation").notNull(),
|
|
1396
|
-
key: text2("key").notNull(),
|
|
1397
|
-
resultJson: jsonb("result_json").$type(),
|
|
1398
|
-
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
1399
|
-
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
1400
|
-
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
1401
|
-
expiresAt: timestamp("expires_at", { withTimezone: true })
|
|
1402
|
-
}, (table) => [
|
|
1403
|
-
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_idempotency_keys" }),
|
|
1404
|
-
uniqueIndex("uq_relay_idempotency_scope_operation_key").on(table.tenantId, table.scope, table.operation, table.key)
|
|
1405
|
-
]);
|
|
1406
|
-
|
|
1407
|
-
// ../store-sql/src/tenant/tenant-id.ts
|
|
1408
|
-
import { and, eq } from "drizzle-orm";
|
|
1409
|
-
import { Context as Context2, Effect as Effect2, Layer as Layer2, Option } from "effect";
|
|
1410
|
-
|
|
1411
|
-
class Service2 extends Context2.Service()("@relayfx/store-sql/TenantId") {
|
|
1412
|
-
}
|
|
1413
|
-
var make = (tenantId2) => Service2.of({ tenantId: tenantId2 });
|
|
1414
|
-
var layer2 = (tenantId2) => Layer2.succeed(Service2, make(tenantId2));
|
|
1415
|
-
var systemLayer = layer2(exports_ids_schema.SystemTenantId);
|
|
1416
|
-
var current = Effect2.gen(function* () {
|
|
1417
|
-
const service = yield* Effect2.serviceOption(Service2);
|
|
1418
|
-
return Option.match(service, {
|
|
1419
|
-
onNone: () => exports_ids_schema.SystemTenantId,
|
|
1420
|
-
onSome: (value) => value.tenantId
|
|
1010
|
+
var toRepositoryError = (error) => new AddressBookRepositoryError({ message: String(error) });
|
|
1011
|
+
var decodeRow = (row) => Schema13.decodeUnknownEffect(AddressBookRow)(row).pipe(Effect3.mapError(toRepositoryError));
|
|
1012
|
+
var layer3 = Layer3.effect(Service3, Effect3.gen(function* () {
|
|
1013
|
+
const sql2 = yield* SqlClient3.SqlClient;
|
|
1014
|
+
const columns = sql2.literal(["id", "address_id", "route_kind", "route_key", "metadata_json", "created_at", "updated_at"].join(", "));
|
|
1015
|
+
const selectByAddress = (tenantId, addressId) => sql2`
|
|
1016
|
+
SELECT ${columns}
|
|
1017
|
+
FROM relay_address_book_entries
|
|
1018
|
+
WHERE tenant_id = ${tenantId} AND address_id = ${addressId}
|
|
1019
|
+
`;
|
|
1020
|
+
const upsertEntry = sql2.onDialectOrElse({
|
|
1021
|
+
mysql: () => (tenantId, input, now) => sql2.withTransaction(Effect3.gen(function* () {
|
|
1022
|
+
yield* sql2`
|
|
1023
|
+
INSERT INTO relay_address_book_entries (
|
|
1024
|
+
tenant_id, ${columns}
|
|
1025
|
+
)
|
|
1026
|
+
VALUES (
|
|
1027
|
+
${tenantId},
|
|
1028
|
+
${input.id},
|
|
1029
|
+
${input.addressId},
|
|
1030
|
+
${input.routeKind},
|
|
1031
|
+
${input.routeKey},
|
|
1032
|
+
${encodeJson(metadata(input))},
|
|
1033
|
+
${timestampParam(sql2, now)},
|
|
1034
|
+
${timestampParam(sql2, now)}
|
|
1035
|
+
)
|
|
1036
|
+
ON DUPLICATE KEY UPDATE
|
|
1037
|
+
route_kind = VALUES(route_kind),
|
|
1038
|
+
route_key = VALUES(route_key),
|
|
1039
|
+
metadata_json = VALUES(metadata_json),
|
|
1040
|
+
updated_at = VALUES(updated_at)
|
|
1041
|
+
`;
|
|
1042
|
+
return yield* selectByAddress(tenantId, input.addressId);
|
|
1043
|
+
})),
|
|
1044
|
+
orElse: () => (tenantId, input, now) => sql2`
|
|
1045
|
+
INSERT INTO relay_address_book_entries (
|
|
1046
|
+
tenant_id, ${columns}
|
|
1047
|
+
)
|
|
1048
|
+
VALUES (
|
|
1049
|
+
${tenantId},
|
|
1050
|
+
${input.id},
|
|
1051
|
+
${input.addressId},
|
|
1052
|
+
${input.routeKind},
|
|
1053
|
+
${input.routeKey},
|
|
1054
|
+
${encodeJson(metadata(input))},
|
|
1055
|
+
${timestampParam(sql2, now)},
|
|
1056
|
+
${timestampParam(sql2, now)}
|
|
1057
|
+
)
|
|
1058
|
+
ON CONFLICT (tenant_id, address_id) DO UPDATE SET
|
|
1059
|
+
route_kind = excluded.route_kind,
|
|
1060
|
+
route_key = excluded.route_key,
|
|
1061
|
+
metadata_json = excluded.metadata_json,
|
|
1062
|
+
updated_at = excluded.updated_at
|
|
1063
|
+
RETURNING ${columns}
|
|
1064
|
+
`
|
|
1421
1065
|
});
|
|
1422
|
-
}).pipe(Effect2.withSpan("TenantId.current"));
|
|
1423
|
-
var predicate = (tenantId2, tenantColumn, ...conditions) => and(eq(tenantColumn, tenantId2), ...conditions);
|
|
1424
|
-
|
|
1425
|
-
// ../store-sql/src/address/address-book-repository.ts
|
|
1426
|
-
var RouteKind2 = exports_address_schema.RouteKind;
|
|
1427
|
-
|
|
1428
|
-
class AddressNotFound extends Schema13.TaggedErrorClass()("AddressNotFound", {
|
|
1429
|
-
address_id: exports_ids_schema.AddressId
|
|
1430
|
-
}) {
|
|
1431
|
-
}
|
|
1432
|
-
|
|
1433
|
-
class AddressBookRepositoryError extends Schema13.TaggedErrorClass()("AddressBookRepositoryError", {
|
|
1434
|
-
message: Schema13.String
|
|
1435
|
-
}) {
|
|
1436
|
-
}
|
|
1437
|
-
|
|
1438
|
-
class Service3 extends Context3.Service()("@relayfx/store-sql/AddressBookRepository") {
|
|
1439
|
-
}
|
|
1440
|
-
var metadata = (input) => input.metadata ?? {};
|
|
1441
|
-
var toEntry = (row) => ({
|
|
1442
|
-
id: row.id,
|
|
1443
|
-
addressId: row.addressId,
|
|
1444
|
-
routeKind: row.routeKind,
|
|
1445
|
-
routeKey: row.routeKey,
|
|
1446
|
-
metadata: row.metadataJson,
|
|
1447
|
-
createdAt: fromPgDate(row.createdAt),
|
|
1448
|
-
updatedAt: fromPgDate(row.updatedAt)
|
|
1449
|
-
});
|
|
1450
|
-
var mapDatabaseError = (effect) => effect.pipe(Effect3.mapError((error) => new AddressBookRepositoryError({ message: String(error) })));
|
|
1451
|
-
var layer3 = Layer3.effect(Service3, Effect3.gen(function* () {
|
|
1452
|
-
const db = yield* Service;
|
|
1453
1066
|
const upsert = Effect3.fn("AddressBookRepository.upsert")(function* (input) {
|
|
1454
|
-
const
|
|
1455
|
-
const
|
|
1456
|
-
|
|
1457
|
-
id: input.id,
|
|
1458
|
-
addressId: input.addressId,
|
|
1459
|
-
routeKind: input.routeKind,
|
|
1460
|
-
routeKey: input.routeKey,
|
|
1461
|
-
metadataJson: metadata(input)
|
|
1462
|
-
}).onConflictDoUpdate({
|
|
1463
|
-
target: [relayAddressBookEntries.tenantId, relayAddressBookEntries.addressId],
|
|
1464
|
-
set: {
|
|
1465
|
-
routeKind: input.routeKind,
|
|
1466
|
-
routeKey: input.routeKey,
|
|
1467
|
-
metadataJson: metadata(input),
|
|
1468
|
-
updatedAt: sql3`now()`
|
|
1469
|
-
}
|
|
1470
|
-
}).returning());
|
|
1067
|
+
const tenantId = yield* current;
|
|
1068
|
+
const now = yield* Clock.currentTimeMillis;
|
|
1069
|
+
const rows = yield* upsertEntry(tenantId, input, now).pipe(Effect3.mapError(toRepositoryError));
|
|
1471
1070
|
const row = rows[0];
|
|
1472
1071
|
if (row === undefined) {
|
|
1473
1072
|
return yield* Effect3.fail(new AddressBookRepositoryError({ message: "Address upsert returned no row" }));
|
|
1474
1073
|
}
|
|
1475
|
-
return toEntry(row);
|
|
1074
|
+
return toEntry(yield* decodeRow(row));
|
|
1476
1075
|
});
|
|
1477
1076
|
const resolve = Effect3.fn("AddressBookRepository.resolve")(function* (addressId) {
|
|
1478
|
-
const
|
|
1479
|
-
const rows = yield*
|
|
1077
|
+
const tenantId = yield* current;
|
|
1078
|
+
const rows = yield* selectByAddress(tenantId, addressId).pipe(Effect3.mapError(toRepositoryError));
|
|
1480
1079
|
const row = rows[0];
|
|
1481
1080
|
if (row === undefined) {
|
|
1482
1081
|
return yield* Effect3.fail(new AddressNotFound({ address_id: addressId }));
|
|
1483
1082
|
}
|
|
1484
|
-
return toEntry(row);
|
|
1083
|
+
return toEntry(yield* decodeRow(row));
|
|
1485
1084
|
});
|
|
1486
1085
|
const list = Effect3.fn("AddressBookRepository.list")(function* () {
|
|
1487
|
-
const
|
|
1488
|
-
const rows = yield*
|
|
1489
|
-
|
|
1086
|
+
const tenantId = yield* current;
|
|
1087
|
+
const rows = yield* sql2`
|
|
1088
|
+
SELECT ${columns}
|
|
1089
|
+
FROM relay_address_book_entries
|
|
1090
|
+
WHERE tenant_id = ${tenantId}
|
|
1091
|
+
ORDER BY address_id ASC
|
|
1092
|
+
`.pipe(Effect3.mapError(toRepositoryError));
|
|
1093
|
+
const decoded = yield* Effect3.forEach(rows, decodeRow);
|
|
1094
|
+
return decoded.map(toEntry);
|
|
1490
1095
|
});
|
|
1491
1096
|
return Service3.of({ upsert, resolve, list });
|
|
1492
1097
|
}));
|
|
@@ -1543,7 +1148,7 @@ __export(exports_agent_chat_repository, {
|
|
|
1543
1148
|
AgentChatRepositoryError: () => AgentChatRepositoryError
|
|
1544
1149
|
});
|
|
1545
1150
|
import { Context as Context4, Effect as Effect4, Layer as Layer4, Schema as Schema14 } from "effect";
|
|
1546
|
-
import * as
|
|
1151
|
+
import * as SqlClient5 from "effect/unstable/sql/SqlClient";
|
|
1547
1152
|
class AgentChatRepositoryError extends Schema14.TaggedErrorClass()("AgentChatRepositoryError", {
|
|
1548
1153
|
message: Schema14.String
|
|
1549
1154
|
}) {
|
|
@@ -1561,29 +1166,29 @@ var toRecord = (row) => ({
|
|
|
1561
1166
|
exportData: decodeJson(row.export_json),
|
|
1562
1167
|
updatedAt: fromDbTimestamp(row.updated_at)
|
|
1563
1168
|
});
|
|
1564
|
-
var
|
|
1565
|
-
var
|
|
1169
|
+
var toRepositoryError2 = (error) => new AgentChatRepositoryError({ message: String(error) });
|
|
1170
|
+
var decodeRow2 = (row) => Schema14.decodeUnknownEffect(AgentChatRow)(row).pipe(Effect4.mapError(toRepositoryError2));
|
|
1566
1171
|
var layer4 = Layer4.effect(Service4, Effect4.gen(function* () {
|
|
1567
|
-
const
|
|
1568
|
-
const selectByKey = (
|
|
1172
|
+
const sql2 = yield* SqlClient5.SqlClient;
|
|
1173
|
+
const selectByKey = (tenantId, executionId) => sql2`
|
|
1569
1174
|
SELECT execution_id, export_json, updated_at
|
|
1570
1175
|
FROM relay_agent_chats
|
|
1571
|
-
WHERE tenant_id = ${
|
|
1176
|
+
WHERE tenant_id = ${tenantId} AND execution_id = ${executionId}
|
|
1572
1177
|
`;
|
|
1573
|
-
const upsert2 =
|
|
1574
|
-
mysql: () => (
|
|
1575
|
-
yield*
|
|
1178
|
+
const upsert2 = sql2.onDialectOrElse({
|
|
1179
|
+
mysql: () => (tenantId, input) => sql2.withTransaction(Effect4.gen(function* () {
|
|
1180
|
+
yield* sql2`
|
|
1576
1181
|
INSERT INTO relay_agent_chats (tenant_id, execution_id, export_json, updated_at)
|
|
1577
|
-
VALUES (${
|
|
1182
|
+
VALUES (${tenantId}, ${input.executionId}, ${encodeJson(input.exportData)}, ${timestampParam(sql2, input.updatedAt)})
|
|
1578
1183
|
ON DUPLICATE KEY UPDATE
|
|
1579
1184
|
export_json = VALUES(export_json),
|
|
1580
1185
|
updated_at = VALUES(updated_at)
|
|
1581
1186
|
`;
|
|
1582
|
-
return yield* selectByKey(
|
|
1187
|
+
return yield* selectByKey(tenantId, input.executionId);
|
|
1583
1188
|
})),
|
|
1584
|
-
orElse: () => (
|
|
1189
|
+
orElse: () => (tenantId, input) => sql2`
|
|
1585
1190
|
INSERT INTO relay_agent_chats (tenant_id, execution_id, export_json, updated_at)
|
|
1586
|
-
VALUES (${
|
|
1191
|
+
VALUES (${tenantId}, ${input.executionId}, ${encodeJson(input.exportData)}, ${timestampParam(sql2, input.updatedAt)})
|
|
1587
1192
|
ON CONFLICT (tenant_id, execution_id) DO UPDATE SET
|
|
1588
1193
|
export_json = excluded.export_json,
|
|
1589
1194
|
updated_at = excluded.updated_at
|
|
@@ -1591,18 +1196,18 @@ var layer4 = Layer4.effect(Service4, Effect4.gen(function* () {
|
|
|
1591
1196
|
`
|
|
1592
1197
|
});
|
|
1593
1198
|
const save = Effect4.fn("AgentChatRepository.save")(function* (input) {
|
|
1594
|
-
const
|
|
1595
|
-
const rows = yield* upsert2(
|
|
1199
|
+
const tenantId = yield* current;
|
|
1200
|
+
const rows = yield* upsert2(tenantId, input).pipe(Effect4.mapError(toRepositoryError2));
|
|
1596
1201
|
const row = rows[0];
|
|
1597
1202
|
if (row === undefined) {
|
|
1598
1203
|
return yield* Effect4.fail(new AgentChatRepositoryError({ message: "Agent chat upsert returned no row" }));
|
|
1599
1204
|
}
|
|
1600
|
-
return toRecord(yield*
|
|
1205
|
+
return toRecord(yield* decodeRow2(row));
|
|
1601
1206
|
});
|
|
1602
1207
|
const get = Effect4.fn("AgentChatRepository.get")(function* (executionId) {
|
|
1603
|
-
const
|
|
1604
|
-
const rows = yield* selectByKey(
|
|
1605
|
-
return rows[0] === undefined ? undefined : toRecord(yield*
|
|
1208
|
+
const tenantId = yield* current;
|
|
1209
|
+
const rows = yield* selectByKey(tenantId, executionId).pipe(Effect4.mapError(toRepositoryError2));
|
|
1210
|
+
return rows[0] === undefined ? undefined : toRecord(yield* decodeRow2(rows[0]));
|
|
1606
1211
|
});
|
|
1607
1212
|
return Service4.of({ save, get });
|
|
1608
1213
|
}));
|
|
@@ -1644,10 +1249,12 @@ __export(exports_agent_definition_repository, {
|
|
|
1644
1249
|
getRevision: () => getRevision,
|
|
1645
1250
|
get: () => get2,
|
|
1646
1251
|
Service: () => Service5,
|
|
1252
|
+
AgentDefinitionRow: () => AgentDefinitionRow,
|
|
1253
|
+
AgentDefinitionRevisionRow: () => AgentDefinitionRevisionRow,
|
|
1647
1254
|
AgentDefinitionRepositoryError: () => AgentDefinitionRepositoryError
|
|
1648
1255
|
});
|
|
1649
|
-
import { asc as asc2, desc, eq as eq3, sql as sql4 } from "drizzle-orm";
|
|
1650
1256
|
import { Context as Context5, Effect as Effect5, Layer as Layer5, Schema as Schema15 } from "effect";
|
|
1257
|
+
import * as SqlClient7 from "effect/unstable/sql/SqlClient";
|
|
1651
1258
|
class AgentDefinitionRepositoryError extends Schema15.TaggedErrorClass()("AgentDefinitionRepositoryError", {
|
|
1652
1259
|
message: Schema15.String
|
|
1653
1260
|
}) {
|
|
@@ -1655,29 +1262,45 @@ class AgentDefinitionRepositoryError extends Schema15.TaggedErrorClass()("AgentD
|
|
|
1655
1262
|
|
|
1656
1263
|
class Service5 extends Context5.Service()("@relayfx/store-sql/AgentDefinitionRepository") {
|
|
1657
1264
|
}
|
|
1265
|
+
var AgentDefinitionRow = Schema15.Struct({
|
|
1266
|
+
id: Schema15.String,
|
|
1267
|
+
current_revision: Schema15.Number,
|
|
1268
|
+
definition_json: Schema15.Unknown,
|
|
1269
|
+
tool_input_schema_digests_json: Schema15.Unknown,
|
|
1270
|
+
created_at: Schema15.Union([Schema15.Date, Schema15.String, Schema15.Number]),
|
|
1271
|
+
updated_at: Schema15.Union([Schema15.Date, Schema15.String, Schema15.Number])
|
|
1272
|
+
}).annotate({ identifier: "Relay.AgentDefinition.Row" });
|
|
1273
|
+
var AgentDefinitionRevisionRow = Schema15.Struct({
|
|
1274
|
+
agent_definition_id: Schema15.String,
|
|
1275
|
+
revision: Schema15.Number,
|
|
1276
|
+
definition_json: Schema15.Unknown,
|
|
1277
|
+
tool_input_schema_digests_json: Schema15.Unknown,
|
|
1278
|
+
created_at: Schema15.Union([Schema15.Date, Schema15.String, Schema15.Number])
|
|
1279
|
+
}).annotate({ identifier: "Relay.AgentDefinitionRevision.Row" });
|
|
1658
1280
|
var nonEmptyDigests = (digests) => digests === undefined || Object.keys(digests).length === 0 ? undefined : structuredClone(digests);
|
|
1281
|
+
var cloneDefinition = (definition) => Schema15.decodeUnknownSync(exports_agent_schema.Definition)(globalThis.structuredClone(definition));
|
|
1282
|
+
var rowDigests = (json) => nonEmptyDigests(decodeJson(json));
|
|
1659
1283
|
var toRecord2 = (row) => {
|
|
1660
|
-
const toolInputSchemaDigests =
|
|
1284
|
+
const toolInputSchemaDigests = rowDigests(row.tool_input_schema_digests_json);
|
|
1661
1285
|
return {
|
|
1662
|
-
id: row.id,
|
|
1663
|
-
currentRevision: row.
|
|
1664
|
-
definition: row.
|
|
1286
|
+
id: exports_ids_schema.AgentDefinitionId.make(row.id),
|
|
1287
|
+
currentRevision: row.current_revision,
|
|
1288
|
+
definition: cloneDefinition(decodeJson(row.definition_json)),
|
|
1665
1289
|
...toolInputSchemaDigests === undefined ? {} : { toolInputSchemaDigests },
|
|
1666
|
-
createdAt:
|
|
1667
|
-
updatedAt:
|
|
1290
|
+
createdAt: fromDbTimestamp(row.created_at),
|
|
1291
|
+
updatedAt: fromDbTimestamp(row.updated_at)
|
|
1668
1292
|
};
|
|
1669
1293
|
};
|
|
1670
1294
|
var toRevisionRecord = (row) => {
|
|
1671
|
-
const toolInputSchemaDigests =
|
|
1295
|
+
const toolInputSchemaDigests = rowDigests(row.tool_input_schema_digests_json);
|
|
1672
1296
|
return {
|
|
1673
|
-
id: row.
|
|
1297
|
+
id: exports_ids_schema.AgentDefinitionId.make(row.agent_definition_id),
|
|
1674
1298
|
revision: row.revision,
|
|
1675
|
-
definition: row.
|
|
1299
|
+
definition: cloneDefinition(decodeJson(row.definition_json)),
|
|
1676
1300
|
...toolInputSchemaDigests === undefined ? {} : { toolInputSchemaDigests },
|
|
1677
|
-
createdAt:
|
|
1301
|
+
createdAt: fromDbTimestamp(row.created_at)
|
|
1678
1302
|
};
|
|
1679
1303
|
};
|
|
1680
|
-
var cloneDefinition = (definition) => Schema15.decodeUnknownSync(exports_agent_schema.Definition)(globalThis.structuredClone(definition));
|
|
1681
1304
|
var cloneRecord = (record) => ({
|
|
1682
1305
|
...record,
|
|
1683
1306
|
definition: cloneDefinition(record.definition),
|
|
@@ -1693,72 +1316,123 @@ var compareByCreatedAtDesc = (left, right) => {
|
|
|
1693
1316
|
const createdAt = right.createdAt - left.createdAt;
|
|
1694
1317
|
return createdAt === 0 ? left.id.localeCompare(right.id) : createdAt;
|
|
1695
1318
|
};
|
|
1696
|
-
var
|
|
1697
|
-
var mapPutError = (
|
|
1319
|
+
var toRepositoryError3 = (error) => new AgentDefinitionRepositoryError({ message: String(error) });
|
|
1320
|
+
var mapPutError = (error) => error instanceof AgentDefinitionRepositoryError ? error : toRepositoryError3(error);
|
|
1321
|
+
var decodeRow3 = (row) => Schema15.decodeUnknownEffect(AgentDefinitionRow)(row).pipe(Effect5.mapError(toRepositoryError3));
|
|
1322
|
+
var decodeRevisionRow = (row) => Schema15.decodeUnknownEffect(AgentDefinitionRevisionRow)(row).pipe(Effect5.mapError(toRepositoryError3));
|
|
1698
1323
|
var layer5 = Layer5.effect(Service5, Effect5.gen(function* () {
|
|
1699
|
-
const
|
|
1324
|
+
const sql2 = yield* SqlClient7.SqlClient;
|
|
1325
|
+
const columns = sql2.literal(["id", "current_revision", "definition_json", "tool_input_schema_digests_json", "created_at", "updated_at"].join(", "));
|
|
1326
|
+
const revisionColumns = sql2.literal(["agent_definition_id", "revision", "definition_json", "tool_input_schema_digests_json", "created_at"].join(", "));
|
|
1327
|
+
const selectByKey = (tenantId, id2) => sql2`
|
|
1328
|
+
SELECT ${columns}
|
|
1329
|
+
FROM relay_agent_definitions
|
|
1330
|
+
WHERE tenant_id = ${tenantId} AND id = ${id2}
|
|
1331
|
+
`;
|
|
1332
|
+
const lockClause = sql2.onDialectOrElse({
|
|
1333
|
+
sqlite: () => sql2.literal(""),
|
|
1334
|
+
orElse: () => sql2.literal("FOR UPDATE")
|
|
1335
|
+
});
|
|
1336
|
+
const selectByKeyForUpdate = (tenantId, id2) => sql2`
|
|
1337
|
+
SELECT ${columns}
|
|
1338
|
+
FROM relay_agent_definitions
|
|
1339
|
+
WHERE tenant_id = ${tenantId} AND id = ${id2}
|
|
1340
|
+
${lockClause}
|
|
1341
|
+
`;
|
|
1700
1342
|
const put = Effect5.fn("AgentDefinitionRepository.put")(function* (input) {
|
|
1701
|
-
const
|
|
1702
|
-
return yield*
|
|
1703
|
-
const existingRows = yield*
|
|
1704
|
-
const existing = existingRows[0];
|
|
1705
|
-
if (existing !== undefined && sameDefinitionContent(existing.
|
|
1343
|
+
const tenantId = yield* current;
|
|
1344
|
+
return yield* sql2.withTransaction(Effect5.gen(function* () {
|
|
1345
|
+
const existingRows = yield* selectByKeyForUpdate(tenantId, input.id);
|
|
1346
|
+
const existing = existingRows[0] === undefined ? undefined : yield* decodeRow3(existingRows[0]);
|
|
1347
|
+
if (existing !== undefined && sameDefinitionContent(decodeJson(existing.definition_json), input.definition)) {
|
|
1706
1348
|
return toRecord2(existing);
|
|
1707
1349
|
}
|
|
1708
|
-
const
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1350
|
+
const nextRevision = (existing?.current_revision ?? 0) + 1;
|
|
1351
|
+
const definitionJson = encodeJson(input.definition);
|
|
1352
|
+
const digestsJson = encodeJson(input.toolInputSchemaDigests ?? {});
|
|
1353
|
+
if (existing === undefined) {
|
|
1354
|
+
yield* sql2`
|
|
1355
|
+
INSERT INTO relay_agent_definitions (
|
|
1356
|
+
tenant_id, id, name, current_revision, definition_json, tool_input_schema_digests_json, created_at, updated_at
|
|
1357
|
+
)
|
|
1358
|
+
VALUES (
|
|
1359
|
+
${tenantId},
|
|
1360
|
+
${input.id},
|
|
1361
|
+
${input.definition.name},
|
|
1362
|
+
${nextRevision},
|
|
1363
|
+
${definitionJson},
|
|
1364
|
+
${digestsJson},
|
|
1365
|
+
${timestampParam(sql2, input.now)},
|
|
1366
|
+
${timestampParam(sql2, input.now)}
|
|
1367
|
+
)
|
|
1368
|
+
`;
|
|
1369
|
+
} else {
|
|
1370
|
+
yield* sql2`
|
|
1371
|
+
UPDATE relay_agent_definitions
|
|
1372
|
+
SET name = ${input.definition.name},
|
|
1373
|
+
current_revision = ${nextRevision},
|
|
1374
|
+
definition_json = ${definitionJson},
|
|
1375
|
+
tool_input_schema_digests_json = ${digestsJson},
|
|
1376
|
+
updated_at = ${timestampParam(sql2, input.now)}
|
|
1377
|
+
WHERE tenant_id = ${tenantId} AND id = ${input.id}
|
|
1378
|
+
`;
|
|
1727
1379
|
}
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1380
|
+
yield* sql2`
|
|
1381
|
+
INSERT INTO relay_agent_definition_revisions (
|
|
1382
|
+
tenant_id, agent_definition_id, revision, name, definition_json, tool_input_schema_digests_json, created_at
|
|
1383
|
+
)
|
|
1384
|
+
VALUES (
|
|
1385
|
+
${tenantId},
|
|
1386
|
+
${input.id},
|
|
1387
|
+
${nextRevision},
|
|
1388
|
+
${input.definition.name},
|
|
1389
|
+
${definitionJson},
|
|
1390
|
+
${digestsJson},
|
|
1391
|
+
${timestampParam(sql2, input.now)}
|
|
1392
|
+
)
|
|
1393
|
+
`;
|
|
1394
|
+
const rows = yield* selectByKey(tenantId, input.id);
|
|
1395
|
+
if (rows[0] === undefined) {
|
|
1396
|
+
return yield* Effect5.fail(new AgentDefinitionRepositoryError({ message: "Agent definition put returned no row" }));
|
|
1739
1397
|
}
|
|
1740
|
-
return toRecord2(
|
|
1741
|
-
})));
|
|
1398
|
+
return toRecord2(yield* decodeRow3(rows[0]));
|
|
1399
|
+
})).pipe(Effect5.mapError(mapPutError));
|
|
1742
1400
|
});
|
|
1743
1401
|
const get2 = Effect5.fn("AgentDefinitionRepository.get")(function* (id2) {
|
|
1744
|
-
const
|
|
1745
|
-
const rows = yield*
|
|
1746
|
-
return rows[0] === undefined ? undefined : toRecord2(rows[0]);
|
|
1402
|
+
const tenantId = yield* current;
|
|
1403
|
+
const rows = yield* selectByKey(tenantId, id2).pipe(Effect5.mapError(toRepositoryError3));
|
|
1404
|
+
return rows[0] === undefined ? undefined : toRecord2(yield* decodeRow3(rows[0]));
|
|
1747
1405
|
});
|
|
1748
1406
|
const getRevision = Effect5.fn("AgentDefinitionRepository.getRevision")(function* (input) {
|
|
1749
|
-
const
|
|
1750
|
-
const rows = yield*
|
|
1751
|
-
|
|
1407
|
+
const tenantId = yield* current;
|
|
1408
|
+
const rows = yield* sql2`
|
|
1409
|
+
SELECT ${revisionColumns}
|
|
1410
|
+
FROM relay_agent_definition_revisions
|
|
1411
|
+
WHERE tenant_id = ${tenantId} AND agent_definition_id = ${input.id} AND revision = ${input.revision}
|
|
1412
|
+
`.pipe(Effect5.mapError(toRepositoryError3));
|
|
1413
|
+
return rows[0] === undefined ? undefined : toRevisionRecord(yield* decodeRevisionRow(rows[0]));
|
|
1752
1414
|
});
|
|
1753
1415
|
const list2 = Effect5.fn("AgentDefinitionRepository.list")(function* () {
|
|
1754
|
-
const
|
|
1755
|
-
const rows = yield*
|
|
1756
|
-
|
|
1416
|
+
const tenantId = yield* current;
|
|
1417
|
+
const rows = yield* sql2`
|
|
1418
|
+
SELECT ${columns}
|
|
1419
|
+
FROM relay_agent_definitions
|
|
1420
|
+
WHERE tenant_id = ${tenantId}
|
|
1421
|
+
ORDER BY created_at DESC, id ASC
|
|
1422
|
+
`.pipe(Effect5.mapError(toRepositoryError3));
|
|
1423
|
+
const decoded = yield* Effect5.forEach(rows, decodeRow3);
|
|
1424
|
+
return decoded.map(toRecord2);
|
|
1757
1425
|
});
|
|
1758
1426
|
const listRevisions = Effect5.fn("AgentDefinitionRepository.listRevisions")(function* (id2) {
|
|
1759
|
-
const
|
|
1760
|
-
const rows = yield*
|
|
1761
|
-
|
|
1427
|
+
const tenantId = yield* current;
|
|
1428
|
+
const rows = yield* sql2`
|
|
1429
|
+
SELECT ${revisionColumns}
|
|
1430
|
+
FROM relay_agent_definition_revisions
|
|
1431
|
+
WHERE tenant_id = ${tenantId} AND agent_definition_id = ${id2}
|
|
1432
|
+
ORDER BY revision DESC
|
|
1433
|
+
`.pipe(Effect5.mapError(toRepositoryError3));
|
|
1434
|
+
const decoded = yield* Effect5.forEach(rows, decodeRevisionRow);
|
|
1435
|
+
return decoded.map(toRevisionRecord);
|
|
1762
1436
|
});
|
|
1763
1437
|
return Service5.of({ put, get: get2, getRevision, list: list2, listRevisions });
|
|
1764
1438
|
}));
|
|
@@ -1845,11 +1519,12 @@ __export(exports_child_execution_repository, {
|
|
|
1845
1519
|
create: () => create,
|
|
1846
1520
|
Service: () => Service6,
|
|
1847
1521
|
DuplicateChildExecution: () => DuplicateChildExecution,
|
|
1522
|
+
ChildExecutionRow: () => ChildExecutionRow,
|
|
1848
1523
|
ChildExecutionRepositoryError: () => ChildExecutionRepositoryError,
|
|
1849
1524
|
ChildExecutionNotFound: () => ChildExecutionNotFound
|
|
1850
1525
|
});
|
|
1851
|
-
import { asc as asc3, eq as eq4 } from "drizzle-orm";
|
|
1852
1526
|
import { Context as Context6, Effect as Effect6, Layer as Layer6, Schema as Schema16 } from "effect";
|
|
1527
|
+
import * as SqlClient9 from "effect/unstable/sql/SqlClient";
|
|
1853
1528
|
class ChildExecutionRepositoryError extends Schema16.TaggedErrorClass()("ChildExecutionRepositoryError", {
|
|
1854
1529
|
message: Schema16.String
|
|
1855
1530
|
}) {
|
|
@@ -1867,62 +1542,112 @@ class ChildExecutionNotFound extends Schema16.TaggedErrorClass()("ChildExecution
|
|
|
1867
1542
|
|
|
1868
1543
|
class Service6 extends Context6.Service()("@relayfx/store-sql/ChildExecutionRepository") {
|
|
1869
1544
|
}
|
|
1545
|
+
var ChildExecutionRow = Schema16.Struct({
|
|
1546
|
+
id: Schema16.String,
|
|
1547
|
+
execution_id: Schema16.String,
|
|
1548
|
+
address_id: Schema16.String,
|
|
1549
|
+
status: Schema16.String,
|
|
1550
|
+
metadata_json: Schema16.Unknown,
|
|
1551
|
+
created_at: Schema16.Union([Schema16.Date, Schema16.String, Schema16.Number]),
|
|
1552
|
+
updated_at: Schema16.Union([Schema16.Date, Schema16.String, Schema16.Number])
|
|
1553
|
+
}).annotate({ identifier: "Relay.ChildExecution.Row" });
|
|
1870
1554
|
var metadata2 = (input) => input ?? {};
|
|
1871
|
-
var toInsert = (tenantId2, input) => ({
|
|
1872
|
-
tenantId: tenantId2,
|
|
1873
|
-
id: input.id,
|
|
1874
|
-
executionId: input.executionId,
|
|
1875
|
-
addressId: input.addressId,
|
|
1876
|
-
status: input.status,
|
|
1877
|
-
metadataJson: metadata2(input.metadata),
|
|
1878
|
-
createdAt: toPgDate(input.createdAt),
|
|
1879
|
-
updatedAt: toPgDate(input.createdAt)
|
|
1880
|
-
});
|
|
1881
1555
|
var toRecord3 = (row) => ({
|
|
1882
|
-
id: row.id,
|
|
1883
|
-
executionId: row.
|
|
1884
|
-
addressId: row.
|
|
1556
|
+
id: exports_ids_schema.ChildExecutionId.make(row.id),
|
|
1557
|
+
executionId: exports_ids_schema.ExecutionId.make(row.execution_id),
|
|
1558
|
+
addressId: exports_ids_schema.AddressId.make(row.address_id),
|
|
1885
1559
|
status: row.status,
|
|
1886
|
-
metadata: row.
|
|
1887
|
-
createdAt:
|
|
1888
|
-
updatedAt:
|
|
1560
|
+
metadata: decodeJson(row.metadata_json),
|
|
1561
|
+
createdAt: fromDbTimestamp(row.created_at),
|
|
1562
|
+
updatedAt: fromDbTimestamp(row.updated_at)
|
|
1889
1563
|
});
|
|
1890
|
-
var
|
|
1564
|
+
var toRepositoryError4 = (error) => new ChildExecutionRepositoryError({ message: String(error) });
|
|
1565
|
+
var decodeRow4 = (row) => Schema16.decodeUnknownEffect(ChildExecutionRow)(row).pipe(Effect6.mapError(toRepositoryError4));
|
|
1891
1566
|
var layer6 = Layer6.effect(Service6, Effect6.gen(function* () {
|
|
1892
|
-
const
|
|
1567
|
+
const sql2 = yield* SqlClient9.SqlClient;
|
|
1568
|
+
const columns = sql2.literal(["id", "execution_id", "address_id", "status", "metadata_json", "created_at", "updated_at"].join(", "));
|
|
1569
|
+
const selectByKey = (tenantId, id2) => sql2`
|
|
1570
|
+
SELECT ${columns}
|
|
1571
|
+
FROM relay_child_executions
|
|
1572
|
+
WHERE tenant_id = ${tenantId} AND id = ${id2}
|
|
1573
|
+
`;
|
|
1574
|
+
const insertStatement = (tenantId, input) => sql2`
|
|
1575
|
+
INSERT INTO relay_child_executions (
|
|
1576
|
+
tenant_id, ${columns}
|
|
1577
|
+
)
|
|
1578
|
+
VALUES (
|
|
1579
|
+
${tenantId},
|
|
1580
|
+
${input.id},
|
|
1581
|
+
${input.executionId},
|
|
1582
|
+
${input.addressId},
|
|
1583
|
+
${input.status},
|
|
1584
|
+
${encodeJson(metadata2(input.metadata))},
|
|
1585
|
+
${timestampParam(sql2, input.createdAt)},
|
|
1586
|
+
${timestampParam(sql2, input.createdAt)}
|
|
1587
|
+
)
|
|
1588
|
+
`;
|
|
1589
|
+
const insertChildExecution = sql2.onDialectOrElse({
|
|
1590
|
+
mysql: () => (tenantId, input) => sql2.withTransaction(Effect6.gen(function* () {
|
|
1591
|
+
yield* insertStatement(tenantId, input);
|
|
1592
|
+
return yield* selectByKey(tenantId, input.id);
|
|
1593
|
+
})),
|
|
1594
|
+
orElse: () => (tenantId, input) => sql2`
|
|
1595
|
+
${insertStatement(tenantId, input)}
|
|
1596
|
+
RETURNING ${columns}
|
|
1597
|
+
`
|
|
1598
|
+
});
|
|
1599
|
+
const updateStatement = (tenantId, input) => sql2`
|
|
1600
|
+
UPDATE relay_child_executions
|
|
1601
|
+
SET status = ${input.status},
|
|
1602
|
+
updated_at = ${timestampParam(sql2, input.updatedAt)}
|
|
1603
|
+
${input.metadata === undefined ? sql2.literal("") : sql2`, metadata_json = ${encodeJson(input.metadata)}`}
|
|
1604
|
+
WHERE tenant_id = ${tenantId} AND id = ${input.id}
|
|
1605
|
+
`;
|
|
1606
|
+
const updateChildExecution = sql2.onDialectOrElse({
|
|
1607
|
+
mysql: () => (tenantId, input) => sql2.withTransaction(Effect6.gen(function* () {
|
|
1608
|
+
yield* updateStatement(tenantId, input);
|
|
1609
|
+
return yield* selectByKey(tenantId, input.id);
|
|
1610
|
+
})),
|
|
1611
|
+
orElse: () => (tenantId, input) => sql2`
|
|
1612
|
+
${updateStatement(tenantId, input)}
|
|
1613
|
+
RETURNING ${columns}
|
|
1614
|
+
`
|
|
1615
|
+
});
|
|
1893
1616
|
const create = Effect6.fn("ChildExecutionRepository.create")(function* (input) {
|
|
1894
|
-
const
|
|
1895
|
-
const existing = yield*
|
|
1617
|
+
const tenantId = yield* current;
|
|
1618
|
+
const existing = yield* selectByKey(tenantId, input.id).pipe(Effect6.mapError(toRepositoryError4));
|
|
1896
1619
|
if (existing[0] !== undefined)
|
|
1897
1620
|
return yield* Effect6.fail(new DuplicateChildExecution({ id: input.id }));
|
|
1898
|
-
const rows = yield*
|
|
1621
|
+
const rows = yield* insertChildExecution(tenantId, input).pipe(Effect6.mapError(toRepositoryError4));
|
|
1899
1622
|
const row = rows[0];
|
|
1900
1623
|
if (row === undefined) {
|
|
1901
1624
|
return yield* Effect6.fail(new ChildExecutionRepositoryError({ message: "Child execution insert returned no row" }));
|
|
1902
1625
|
}
|
|
1903
|
-
return toRecord3(row);
|
|
1626
|
+
return toRecord3(yield* decodeRow4(row));
|
|
1904
1627
|
});
|
|
1905
1628
|
const get3 = Effect6.fn("ChildExecutionRepository.get")(function* (id2) {
|
|
1906
|
-
const
|
|
1907
|
-
const rows = yield*
|
|
1908
|
-
return rows[0] === undefined ? undefined : toRecord3(rows[0]);
|
|
1629
|
+
const tenantId = yield* current;
|
|
1630
|
+
const rows = yield* selectByKey(tenantId, id2).pipe(Effect6.mapError(toRepositoryError4));
|
|
1631
|
+
return rows[0] === undefined ? undefined : toRecord3(yield* decodeRow4(rows[0]));
|
|
1909
1632
|
});
|
|
1910
1633
|
const listByExecution = Effect6.fn("ChildExecutionRepository.listByExecution")(function* (executionId) {
|
|
1911
|
-
const
|
|
1912
|
-
const rows = yield*
|
|
1913
|
-
|
|
1634
|
+
const tenantId = yield* current;
|
|
1635
|
+
const rows = yield* sql2`
|
|
1636
|
+
SELECT ${columns}
|
|
1637
|
+
FROM relay_child_executions
|
|
1638
|
+
WHERE tenant_id = ${tenantId} AND execution_id = ${executionId}
|
|
1639
|
+
ORDER BY created_at ASC
|
|
1640
|
+
`.pipe(Effect6.mapError(toRepositoryError4));
|
|
1641
|
+
const decoded = yield* Effect6.forEach(rows, decodeRow4);
|
|
1642
|
+
return decoded.map(toRecord3);
|
|
1914
1643
|
});
|
|
1915
1644
|
const updateStatus = Effect6.fn("ChildExecutionRepository.updateStatus")(function* (input) {
|
|
1916
|
-
const
|
|
1917
|
-
const rows = yield*
|
|
1918
|
-
status: input.status,
|
|
1919
|
-
updatedAt: toPgDate(input.updatedAt),
|
|
1920
|
-
...input.metadata === undefined ? {} : { metadataJson: input.metadata }
|
|
1921
|
-
}).where(predicate(tenantId2, relayChildExecutions.tenantId, eq4(relayChildExecutions.id, input.id))).returning());
|
|
1645
|
+
const tenantId = yield* current;
|
|
1646
|
+
const rows = yield* updateChildExecution(tenantId, input).pipe(Effect6.mapError(toRepositoryError4));
|
|
1922
1647
|
const row = rows[0];
|
|
1923
1648
|
if (row === undefined)
|
|
1924
1649
|
return yield* Effect6.fail(new ChildExecutionNotFound({ id: input.id }));
|
|
1925
|
-
return toRecord3(row);
|
|
1650
|
+
return toRecord3(yield* decodeRow4(row));
|
|
1926
1651
|
});
|
|
1927
1652
|
return Service6.of({ create, get: get3, listByExecution, updateStatus });
|
|
1928
1653
|
}));
|
|
@@ -1996,8 +1721,7 @@ __export(exports_cluster_registry_repository, {
|
|
|
1996
1721
|
ClusterRegistryError: () => ClusterRegistryError
|
|
1997
1722
|
});
|
|
1998
1723
|
import { Context as Context7, Effect as Effect7, Layer as Layer7, Schema as Schema17 } from "effect";
|
|
1999
|
-
import
|
|
2000
|
-
|
|
1724
|
+
import * as SqlClient11 from "effect/unstable/sql/SqlClient";
|
|
2001
1725
|
class ClusterRegistryError extends Schema17.TaggedErrorClass()("ClusterRegistryError", {
|
|
2002
1726
|
message: Schema17.String
|
|
2003
1727
|
}) {
|
|
@@ -2007,48 +1731,41 @@ class Service7 extends Context7.Service()("@relayfx/store-sql/ClusterRegistryRep
|
|
|
2007
1731
|
}
|
|
2008
1732
|
var RunnerRow = Schema17.Struct({
|
|
2009
1733
|
address: Schema17.String,
|
|
2010
|
-
healthy: Schema17.Boolean,
|
|
2011
|
-
last_heartbeat: Schema17.Union([Schema17.Date, Schema17.
|
|
2012
|
-
owned_shards: Schema17.Union([Schema17.Number, Schema17.
|
|
1734
|
+
healthy: Schema17.Union([Schema17.Boolean, Schema17.Number, Schema17.String]),
|
|
1735
|
+
last_heartbeat: Schema17.Union([Schema17.Date, Schema17.String, Schema17.Number]),
|
|
1736
|
+
owned_shards: Schema17.Union([Schema17.Number, Schema17.String, Schema17.BigInt])
|
|
2013
1737
|
}).annotate({ identifier: "Relay.ClusterRegistry.RunnerRow" });
|
|
2014
1738
|
var LockRow = Schema17.Struct({
|
|
2015
1739
|
address: Schema17.String
|
|
2016
1740
|
}).annotate({ identifier: "Relay.ClusterRegistry.LockRow" });
|
|
2017
1741
|
var toRunnerRecord = (row) => ({
|
|
2018
1742
|
address: row.address,
|
|
2019
|
-
healthy: row.healthy,
|
|
2020
|
-
lastHeartbeat: row.last_heartbeat
|
|
2021
|
-
ownedShards: row.owned_shards
|
|
1743
|
+
healthy: decodeBool(row.healthy),
|
|
1744
|
+
lastHeartbeat: fromDbTimestamp(row.last_heartbeat),
|
|
1745
|
+
ownedShards: Number(row.owned_shards)
|
|
2022
1746
|
});
|
|
2023
1747
|
var toRegistryError = (error) => new ClusterRegistryError({ message: String(error) });
|
|
1748
|
+
var decodeRunnerRow = (row) => Schema17.decodeUnknownEffect(RunnerRow)(row).pipe(Effect7.mapError(toRegistryError));
|
|
1749
|
+
var decodeLockRow = (row) => Schema17.decodeUnknownEffect(LockRow)(row).pipe(Effect7.mapError(toRegistryError));
|
|
2024
1750
|
var layer7 = Layer7.effect(Service7, Effect7.gen(function* () {
|
|
2025
|
-
const
|
|
2026
|
-
const
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
const ownerQuery = SqlSchema.findAll({
|
|
2038
|
-
Request: Schema17.Struct({ shard_id: Schema17.String }),
|
|
2039
|
-
Result: LockRow,
|
|
2040
|
-
execute: ({ shard_id }) => sql5`SELECT address FROM cluster_locks WHERE shard_id = ${shard_id}`
|
|
1751
|
+
const sql2 = yield* SqlClient11.SqlClient;
|
|
1752
|
+
const selectRunners = () => sql2`
|
|
1753
|
+
SELECT r.address, r.healthy, r.last_heartbeat, COUNT(l.shard_id) AS owned_shards
|
|
1754
|
+
FROM cluster_runners r
|
|
1755
|
+
LEFT JOIN cluster_locks l ON l.address = r.address
|
|
1756
|
+
GROUP BY r.address, r.healthy, r.last_heartbeat
|
|
1757
|
+
ORDER BY r.address
|
|
1758
|
+
`;
|
|
1759
|
+
const selectOwner = (shardId) => sql2`SELECT address FROM cluster_locks WHERE shard_id = ${shardId}`;
|
|
1760
|
+
const listRunners = Effect7.fn("ClusterRegistryRepository.listRunners")(function* () {
|
|
1761
|
+
const rows = yield* selectRunners().pipe(Effect7.catchTag("SqlError", () => Effect7.succeed([])));
|
|
1762
|
+
return yield* Effect7.forEach(rows, (row) => Effect7.map(decodeRunnerRow(row), toRunnerRecord));
|
|
2041
1763
|
});
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
return rows.map(toRunnerRecord);
|
|
2046
|
-
}),
|
|
2047
|
-
lockOwner: Effect7.fn("ClusterRegistryRepository.lockOwner")(function* (shardId) {
|
|
2048
|
-
const rows = yield* ownerQuery({ shard_id: shardId }).pipe(Effect7.catchTag("SqlError", () => Effect7.succeed([])), Effect7.mapError(toRegistryError));
|
|
2049
|
-
return rows[0]?.address;
|
|
2050
|
-
})
|
|
1764
|
+
const lockOwner = Effect7.fn("ClusterRegistryRepository.lockOwner")(function* (shardId) {
|
|
1765
|
+
const rows = yield* selectOwner(shardId).pipe(Effect7.catchTag("SqlError", () => Effect7.succeed([])));
|
|
1766
|
+
return rows[0] === undefined ? undefined : (yield* decodeLockRow(rows[0])).address;
|
|
2051
1767
|
});
|
|
1768
|
+
return Service7.of({ listRunners, lockOwner });
|
|
2052
1769
|
}));
|
|
2053
1770
|
var memoryLayer5 = Layer7.succeed(Service7, Service7.of({
|
|
2054
1771
|
listRunners: () => Effect7.succeed([]),
|
|
@@ -2073,10 +1790,11 @@ __export(exports_compaction_repository, {
|
|
|
2073
1790
|
layer: () => layer8,
|
|
2074
1791
|
get: () => get4,
|
|
2075
1792
|
Service: () => Service8,
|
|
2076
|
-
CompactionRepositoryError: () => CompactionRepositoryError
|
|
1793
|
+
CompactionRepositoryError: () => CompactionRepositoryError,
|
|
1794
|
+
CompactionCheckpointRow: () => CompactionCheckpointRow
|
|
2077
1795
|
});
|
|
2078
|
-
import { asc as asc4, eq as eq5 } from "drizzle-orm";
|
|
2079
1796
|
import { Context as Context8, Effect as Effect8, Layer as Layer8, Schema as Schema18 } from "effect";
|
|
1797
|
+
import * as SqlClient13 from "effect/unstable/sql/SqlClient";
|
|
2080
1798
|
class CompactionRepositoryError extends Schema18.TaggedErrorClass()("CompactionRepositoryError", {
|
|
2081
1799
|
message: Schema18.String
|
|
2082
1800
|
}) {
|
|
@@ -2084,15 +1802,24 @@ class CompactionRepositoryError extends Schema18.TaggedErrorClass()("CompactionR
|
|
|
2084
1802
|
|
|
2085
1803
|
class Service8 extends Context8.Service()("@relayfx/store-sql/CompactionRepository") {
|
|
2086
1804
|
}
|
|
1805
|
+
var CompactionCheckpointRow = Schema18.Struct({
|
|
1806
|
+
execution_id: Schema18.String,
|
|
1807
|
+
checkpoint_id: Schema18.String,
|
|
1808
|
+
summary: Schema18.String,
|
|
1809
|
+
first_kept_entry_id: Schema18.String,
|
|
1810
|
+
turn: Schema18.Number,
|
|
1811
|
+
created_at: Schema18.Union([Schema18.Date, Schema18.String, Schema18.Number])
|
|
1812
|
+
}).annotate({ identifier: "Relay.CompactionCheckpoint.Row" });
|
|
2087
1813
|
var toRecord4 = (row) => ({
|
|
2088
|
-
executionId: row.
|
|
2089
|
-
checkpointId: row.
|
|
1814
|
+
executionId: exports_ids_schema.ExecutionId.make(row.execution_id),
|
|
1815
|
+
checkpointId: row.checkpoint_id,
|
|
2090
1816
|
summary: row.summary,
|
|
2091
|
-
firstKeptEntryId: row.
|
|
1817
|
+
firstKeptEntryId: exports_ids_schema.SessionEntryId.make(row.first_kept_entry_id),
|
|
2092
1818
|
turn: row.turn,
|
|
2093
|
-
createdAt:
|
|
1819
|
+
createdAt: fromDbTimestamp(row.created_at)
|
|
2094
1820
|
});
|
|
2095
|
-
var
|
|
1821
|
+
var toRepositoryError5 = (error) => new CompactionRepositoryError({ message: String(error) });
|
|
1822
|
+
var decodeRow5 = (row) => Schema18.decodeUnknownEffect(CompactionCheckpointRow)(row).pipe(Effect8.mapError(toRepositoryError5));
|
|
2096
1823
|
var key = (input) => `${input.executionId}:${input.checkpointId}`;
|
|
2097
1824
|
var sameCheckpoint = (record, input) => record.summary === input.summary && record.firstKeptEntryId === input.firstKeptEntryId && record.turn === input.turn;
|
|
2098
1825
|
var conflict = (input) => new CompactionRepositoryError({
|
|
@@ -2100,37 +1827,56 @@ var conflict = (input) => new CompactionRepositoryError({
|
|
|
2100
1827
|
});
|
|
2101
1828
|
var cloneRecord2 = (record) => structuredClone(record);
|
|
2102
1829
|
var layer8 = Layer8.effect(Service8, Effect8.gen(function* () {
|
|
2103
|
-
const
|
|
1830
|
+
const sql2 = yield* SqlClient13.SqlClient;
|
|
1831
|
+
const columns = sql2.literal(["execution_id", "checkpoint_id", "summary", "first_kept_entry_id", "turn", "created_at"].join(", "));
|
|
1832
|
+
const selectByKey = (tenantId, input) => sql2`
|
|
1833
|
+
SELECT ${columns}
|
|
1834
|
+
FROM relay_agent_compactions
|
|
1835
|
+
WHERE tenant_id = ${tenantId} AND execution_id = ${input.executionId} AND checkpoint_id = ${input.checkpointId}
|
|
1836
|
+
`;
|
|
1837
|
+
const insertValues = (tenantId, input) => sql2`
|
|
1838
|
+
(
|
|
1839
|
+
tenant_id, ${columns}
|
|
1840
|
+
)
|
|
1841
|
+
VALUES (
|
|
1842
|
+
${tenantId},
|
|
1843
|
+
${input.executionId},
|
|
1844
|
+
${input.checkpointId},
|
|
1845
|
+
${input.summary},
|
|
1846
|
+
${input.firstKeptEntryId},
|
|
1847
|
+
${input.turn},
|
|
1848
|
+
${timestampParam(sql2, input.createdAt)}
|
|
1849
|
+
)
|
|
1850
|
+
`;
|
|
1851
|
+
const insertCheckpoint = sql2.onDialectOrElse({
|
|
1852
|
+
mysql: () => (tenantId, input) => sql2.withTransaction(Effect8.gen(function* () {
|
|
1853
|
+
yield* sql2`
|
|
1854
|
+
INSERT IGNORE INTO relay_agent_compactions ${insertValues(tenantId, input)}
|
|
1855
|
+
`;
|
|
1856
|
+
return yield* selectByKey(tenantId, input);
|
|
1857
|
+
})),
|
|
1858
|
+
orElse: () => (tenantId, input) => sql2`
|
|
1859
|
+
INSERT INTO relay_agent_compactions ${insertValues(tenantId, input)}
|
|
1860
|
+
ON CONFLICT (tenant_id, execution_id, checkpoint_id) DO NOTHING
|
|
1861
|
+
RETURNING ${columns}
|
|
1862
|
+
`
|
|
1863
|
+
});
|
|
2104
1864
|
const get4 = Effect8.fn("CompactionRepository.get")(function* (input) {
|
|
2105
|
-
const
|
|
2106
|
-
const rows = yield*
|
|
2107
|
-
return rows[0] === undefined ? undefined : toRecord4(rows[0]);
|
|
1865
|
+
const tenantId = yield* current;
|
|
1866
|
+
const rows = yield* selectByKey(tenantId, input).pipe(Effect8.mapError(toRepositoryError5));
|
|
1867
|
+
return rows[0] === undefined ? undefined : toRecord4(yield* decodeRow5(rows[0]));
|
|
2108
1868
|
});
|
|
2109
1869
|
const record = Effect8.fn("CompactionRepository.record")(function* (input) {
|
|
2110
|
-
const
|
|
1870
|
+
const tenantId = yield* current;
|
|
2111
1871
|
const existing = yield* get4(input);
|
|
2112
1872
|
if (existing !== undefined) {
|
|
2113
1873
|
if (!sameCheckpoint(existing, input))
|
|
2114
1874
|
return yield* Effect8.fail(conflict(input));
|
|
2115
1875
|
return existing;
|
|
2116
1876
|
}
|
|
2117
|
-
const rows = yield*
|
|
2118
|
-
tenantId: tenantId2,
|
|
2119
|
-
executionId: input.executionId,
|
|
2120
|
-
checkpointId: input.checkpointId,
|
|
2121
|
-
summary: input.summary,
|
|
2122
|
-
firstKeptEntryId: input.firstKeptEntryId,
|
|
2123
|
-
turn: input.turn,
|
|
2124
|
-
createdAt: toPgDate(input.createdAt)
|
|
2125
|
-
}).onConflictDoNothing({
|
|
2126
|
-
target: [
|
|
2127
|
-
relayAgentCompactions.tenantId,
|
|
2128
|
-
relayAgentCompactions.executionId,
|
|
2129
|
-
relayAgentCompactions.checkpointId
|
|
2130
|
-
]
|
|
2131
|
-
}).returning());
|
|
1877
|
+
const rows = yield* insertCheckpoint(tenantId, input).pipe(Effect8.mapError(toRepositoryError5));
|
|
2132
1878
|
const row = rows[0];
|
|
2133
|
-
const saved = row === undefined ? yield* get4(input) : toRecord4(row);
|
|
1879
|
+
const saved = row === undefined ? yield* get4(input) : toRecord4(yield* decodeRow5(row));
|
|
2134
1880
|
if (saved === undefined)
|
|
2135
1881
|
return yield* Effect8.fail(new CompactionRepositoryError({ message: "Compaction checkpoint insert returned no row" }));
|
|
2136
1882
|
if (!sameCheckpoint(saved, input))
|
|
@@ -2138,9 +1884,15 @@ var layer8 = Layer8.effect(Service8, Effect8.gen(function* () {
|
|
|
2138
1884
|
return saved;
|
|
2139
1885
|
});
|
|
2140
1886
|
const list3 = Effect8.fn("CompactionRepository.list")(function* (executionId) {
|
|
2141
|
-
const
|
|
2142
|
-
const rows = yield*
|
|
2143
|
-
|
|
1887
|
+
const tenantId = yield* current;
|
|
1888
|
+
const rows = yield* sql2`
|
|
1889
|
+
SELECT ${columns}
|
|
1890
|
+
FROM relay_agent_compactions
|
|
1891
|
+
WHERE tenant_id = ${tenantId} AND execution_id = ${executionId}
|
|
1892
|
+
ORDER BY turn ASC, checkpoint_id ASC
|
|
1893
|
+
`.pipe(Effect8.mapError(toRepositoryError5));
|
|
1894
|
+
const decoded = yield* Effect8.forEach(rows, decodeRow5);
|
|
1895
|
+
return decoded.map(toRecord4);
|
|
2144
1896
|
});
|
|
2145
1897
|
return Service8.of({ get: get4, record, list: list3 });
|
|
2146
1898
|
}));
|
|
@@ -2208,7 +1960,7 @@ __export(exports_envelope_repository, {
|
|
|
2208
1960
|
EnvelopeNotFound: () => EnvelopeNotFound
|
|
2209
1961
|
});
|
|
2210
1962
|
import { Context as Context9, Effect as Effect9, Layer as Layer9, Schema as Schema19 } from "effect";
|
|
2211
|
-
import * as
|
|
1963
|
+
import * as SqlClient15 from "effect/unstable/sql/SqlClient";
|
|
2212
1964
|
var WaitState = Schema19.Literals(["open", "resolved", "timed_out", "cancelled"]).annotate({
|
|
2213
1965
|
identifier: "Relay.Store.WaitState"
|
|
2214
1966
|
});
|
|
@@ -2349,124 +2101,124 @@ var maxListWaitsLimit = 500;
|
|
|
2349
2101
|
var defaultListWaitsLimit = 50;
|
|
2350
2102
|
var listWaitsLimit = (input) => Math.min(Math.max(input.limit ?? defaultListWaitsLimit, 1), maxListWaitsLimit);
|
|
2351
2103
|
var compareWaitsDesc = (left, right) => right.createdAt - left.createdAt || (left.id < right.id ? 1 : left.id > right.id ? -1 : 0);
|
|
2352
|
-
var
|
|
2353
|
-
var decodeEnvelopeRow = (row) => Schema19.decodeUnknownEffect(EnvelopeRow)(row).pipe(Effect9.mapError(
|
|
2354
|
-
var decodeWaitRow = (row) => Schema19.decodeUnknownEffect(WaitRow)(row).pipe(Effect9.mapError(
|
|
2355
|
-
var decodeReadyRow = (row) => Schema19.decodeUnknownEffect(EnvelopeReadyRow)(row).pipe(Effect9.mapError(
|
|
2104
|
+
var toRepositoryError6 = (error) => new EnvelopeRepositoryError({ message: String(error) });
|
|
2105
|
+
var decodeEnvelopeRow = (row) => Schema19.decodeUnknownEffect(EnvelopeRow)(row).pipe(Effect9.mapError(toRepositoryError6));
|
|
2106
|
+
var decodeWaitRow = (row) => Schema19.decodeUnknownEffect(WaitRow)(row).pipe(Effect9.mapError(toRepositoryError6));
|
|
2107
|
+
var decodeReadyRow = (row) => Schema19.decodeUnknownEffect(EnvelopeReadyRow)(row).pipe(Effect9.mapError(toRepositoryError6));
|
|
2356
2108
|
var waitColumnsText = "id, execution_id, envelope_id, mode, correlation_key, state, metadata_json, created_at, resolved_at";
|
|
2357
2109
|
var readyColumnsText = "id, envelope_id, route_type, route_key, state, available_at, attempt, claim_owner, claim_expires_at, last_error, idempotency_key, metadata_json, created_at, updated_at, claimed_at, acknowledged_at";
|
|
2358
2110
|
var envelopeColumnsText = "id, execution_id, from_address_id, to_address_id, content_json, wait_json, correlation_key, metadata_json, created_at";
|
|
2359
2111
|
var layer9 = Layer9.effect(Service9, Effect9.gen(function* () {
|
|
2360
|
-
const
|
|
2361
|
-
const ts = (millis) => timestampParam(
|
|
2362
|
-
const waitColumns =
|
|
2363
|
-
const readyColumns =
|
|
2364
|
-
const envelopeColumns =
|
|
2365
|
-
const selectWaitById = (
|
|
2112
|
+
const sql2 = yield* SqlClient15.SqlClient;
|
|
2113
|
+
const ts = (millis) => timestampParam(sql2, millis);
|
|
2114
|
+
const waitColumns = sql2.literal(waitColumnsText);
|
|
2115
|
+
const readyColumns = sql2.literal(readyColumnsText);
|
|
2116
|
+
const envelopeColumns = sql2.literal(envelopeColumnsText);
|
|
2117
|
+
const selectWaitById = (tenantId, id2) => sql2`
|
|
2366
2118
|
SELECT ${waitColumns}
|
|
2367
2119
|
FROM relay_waits
|
|
2368
|
-
WHERE tenant_id = ${
|
|
2120
|
+
WHERE tenant_id = ${tenantId} AND id = ${id2}
|
|
2369
2121
|
`;
|
|
2370
|
-
const selectReadyById = (
|
|
2122
|
+
const selectReadyById = (tenantId, id2) => sql2`
|
|
2371
2123
|
SELECT ${readyColumns}
|
|
2372
2124
|
FROM relay_envelope_ready
|
|
2373
|
-
WHERE tenant_id = ${
|
|
2125
|
+
WHERE tenant_id = ${tenantId} AND id = ${id2}
|
|
2374
2126
|
`;
|
|
2375
|
-
const getWaitRow = (
|
|
2376
|
-
const rows = yield* selectWaitById(
|
|
2127
|
+
const getWaitRow = (tenantId, id2) => Effect9.gen(function* () {
|
|
2128
|
+
const rows = yield* selectWaitById(tenantId, id2).pipe(Effect9.mapError(toRepositoryError6));
|
|
2377
2129
|
return rows[0] === undefined ? undefined : yield* decodeWaitRow(rows[0]);
|
|
2378
2130
|
});
|
|
2379
|
-
const getReadyRow = (
|
|
2380
|
-
const rows = yield* selectReadyById(
|
|
2131
|
+
const getReadyRow = (tenantId, id2) => Effect9.gen(function* () {
|
|
2132
|
+
const rows = yield* selectReadyById(tenantId, id2).pipe(Effect9.mapError(toRepositoryError6));
|
|
2381
2133
|
return rows[0] === undefined ? undefined : yield* decodeReadyRow(rows[0]);
|
|
2382
2134
|
});
|
|
2383
2135
|
const acceptEnvelope = Effect9.fn("EnvelopeRepository.acceptEnvelope")(function* (input) {
|
|
2384
|
-
const
|
|
2136
|
+
const tenantId = yield* current;
|
|
2385
2137
|
const envelope = input.envelope;
|
|
2386
2138
|
const wait = envelope.wait;
|
|
2387
2139
|
const waitId = input.waitId;
|
|
2388
2140
|
const ready = input.ready;
|
|
2389
|
-
yield*
|
|
2390
|
-
yield*
|
|
2141
|
+
yield* sql2.withTransaction(Effect9.gen(function* () {
|
|
2142
|
+
yield* sql2`
|
|
2391
2143
|
INSERT INTO relay_envelopes (tenant_id, id, execution_id, from_address_id, to_address_id, content_json, wait_json, correlation_key, metadata_json, created_at)
|
|
2392
|
-
VALUES (${
|
|
2144
|
+
VALUES (${tenantId}, ${envelope.id}, ${envelope.execution_id}, ${envelope.from}, ${envelope.to}, ${encodeJson(envelope.content)}, ${wait === undefined ? null : encodeJson(wait)}, ${envelope.correlation_key ?? null}, ${encodeJson(metadata3(envelope.metadata))}, ${ts(envelope.created_at)})
|
|
2393
2145
|
`;
|
|
2394
2146
|
if (waitId !== undefined && wait !== undefined) {
|
|
2395
|
-
yield*
|
|
2147
|
+
yield* sql2`
|
|
2396
2148
|
INSERT INTO relay_waits (tenant_id, id, execution_id, envelope_id, mode, correlation_key, state, metadata_json, created_at)
|
|
2397
|
-
VALUES (${
|
|
2149
|
+
VALUES (${tenantId}, ${waitId}, ${envelope.execution_id}, ${envelope.id}, ${wait.mode}, ${wait.correlation_key ?? null}, 'open', ${encodeJson(metadata3(wait.metadata))}, ${ts(envelope.created_at)})
|
|
2398
2150
|
`;
|
|
2399
2151
|
}
|
|
2400
2152
|
if (ready !== undefined) {
|
|
2401
|
-
yield*
|
|
2153
|
+
yield* sql2`
|
|
2402
2154
|
INSERT INTO relay_envelope_ready (tenant_id, id, envelope_id, route_type, route_key, state, available_at, attempt, idempotency_key, metadata_json, created_at, updated_at)
|
|
2403
|
-
VALUES (${
|
|
2155
|
+
VALUES (${tenantId}, ${ready.id}, ${envelope.id}, ${ready.routeType}, ${ready.routeKey}, 'ready', ${ts(ready.availableAt)}, 0, ${ready.idempotencyKey ?? null}, ${encodeJson(metadata3(ready.metadata))}, ${ts(envelope.created_at)}, ${ts(envelope.created_at)})
|
|
2404
2156
|
`;
|
|
2405
2157
|
}
|
|
2406
|
-
})).pipe(Effect9.mapError(
|
|
2158
|
+
})).pipe(Effect9.mapError(toRepositoryError6));
|
|
2407
2159
|
return accepted(input);
|
|
2408
2160
|
});
|
|
2409
2161
|
const getEnvelope = Effect9.fn("EnvelopeRepository.getEnvelope")(function* (id2) {
|
|
2410
|
-
const
|
|
2411
|
-
const rows = yield*
|
|
2162
|
+
const tenantId = yield* current;
|
|
2163
|
+
const rows = yield* sql2`
|
|
2412
2164
|
SELECT ${envelopeColumns}
|
|
2413
2165
|
FROM relay_envelopes
|
|
2414
|
-
WHERE tenant_id = ${
|
|
2415
|
-
`.pipe(Effect9.mapError(
|
|
2166
|
+
WHERE tenant_id = ${tenantId} AND id = ${id2}
|
|
2167
|
+
`.pipe(Effect9.mapError(toRepositoryError6));
|
|
2416
2168
|
return rows[0] === undefined ? undefined : toEnvelope(yield* decodeEnvelopeRow(rows[0]));
|
|
2417
2169
|
});
|
|
2418
2170
|
const getWait = Effect9.fn("EnvelopeRepository.getWait")(function* (id2) {
|
|
2419
|
-
const
|
|
2420
|
-
const row = yield* getWaitRow(
|
|
2171
|
+
const tenantId = yield* current;
|
|
2172
|
+
const row = yield* getWaitRow(tenantId, id2);
|
|
2421
2173
|
return row === undefined ? undefined : toWaitRecord(row);
|
|
2422
2174
|
});
|
|
2423
2175
|
const createWait = Effect9.fn("EnvelopeRepository.createWait")(function* (input) {
|
|
2424
|
-
const
|
|
2425
|
-
yield*
|
|
2176
|
+
const tenantId = yield* current;
|
|
2177
|
+
yield* sql2`
|
|
2426
2178
|
INSERT INTO relay_waits (tenant_id, id, execution_id, envelope_id, mode, correlation_key, state, metadata_json, created_at)
|
|
2427
|
-
VALUES (${
|
|
2428
|
-
`.pipe(Effect9.mapError(
|
|
2429
|
-
const row = yield* getWaitRow(
|
|
2179
|
+
VALUES (${tenantId}, ${input.waitId}, ${input.executionId}, ${null}, ${input.mode}, ${input.correlationKey ?? null}, 'open', ${encodeJson(metadata3(input.metadata))}, ${ts(input.createdAt)})
|
|
2180
|
+
`.pipe(Effect9.mapError(toRepositoryError6));
|
|
2181
|
+
const row = yield* getWaitRow(tenantId, input.waitId);
|
|
2430
2182
|
if (row === undefined) {
|
|
2431
2183
|
return yield* Effect9.fail(new EnvelopeRepositoryError({ message: `Wait ${input.waitId} was not persisted` }));
|
|
2432
2184
|
}
|
|
2433
2185
|
return toWaitRecord(row);
|
|
2434
2186
|
});
|
|
2435
2187
|
const listWaits = Effect9.fn("EnvelopeRepository.listWaits")(function* (input) {
|
|
2436
|
-
const
|
|
2188
|
+
const tenantId = yield* current;
|
|
2437
2189
|
const conditions = [
|
|
2438
|
-
|
|
2439
|
-
...input.executionId === undefined ? [] : [
|
|
2440
|
-
...input.state === undefined ? [] : [
|
|
2190
|
+
sql2`tenant_id = ${tenantId}`,
|
|
2191
|
+
...input.executionId === undefined ? [] : [sql2`execution_id = ${input.executionId}`],
|
|
2192
|
+
...input.state === undefined ? [] : [sql2`state = ${input.state}`]
|
|
2441
2193
|
];
|
|
2442
|
-
const rows = yield*
|
|
2194
|
+
const rows = yield* sql2`
|
|
2443
2195
|
SELECT ${waitColumns}
|
|
2444
2196
|
FROM relay_waits
|
|
2445
|
-
WHERE ${
|
|
2197
|
+
WHERE ${sql2.and(conditions)}
|
|
2446
2198
|
ORDER BY created_at DESC, id DESC
|
|
2447
|
-
LIMIT ${
|
|
2448
|
-
`.pipe(Effect9.mapError(
|
|
2199
|
+
LIMIT ${sql2.literal(String(listWaitsLimit(input)))}
|
|
2200
|
+
`.pipe(Effect9.mapError(toRepositoryError6));
|
|
2449
2201
|
const records = [];
|
|
2450
2202
|
for (const row of rows) {
|
|
2451
2203
|
records.push(toWaitRecord(yield* decodeWaitRow(row)));
|
|
2452
2204
|
}
|
|
2453
2205
|
return records;
|
|
2454
2206
|
});
|
|
2455
|
-
const claimablePredicate = (input) =>
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2207
|
+
const claimablePredicate = (input) => sql2.or([
|
|
2208
|
+
sql2.and([sql2`state = 'ready'`, sql2`available_at <= ${ts(input.now)}`]),
|
|
2209
|
+
sql2.and([
|
|
2210
|
+
sql2`state = 'claimed'`,
|
|
2211
|
+
sql2`claim_expires_at IS NOT NULL`,
|
|
2212
|
+
sql2`claim_expires_at <= ${ts(input.now)}`
|
|
2461
2213
|
])
|
|
2462
2214
|
]);
|
|
2463
|
-
const claimConditions = (
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
...input.routeKey === undefined ? [] : [
|
|
2215
|
+
const claimConditions = (tenantId, input) => sql2.and([
|
|
2216
|
+
sql2`tenant_id = ${tenantId}`,
|
|
2217
|
+
sql2`route_type = ${input.routeType}`,
|
|
2218
|
+
...input.routeKey === undefined ? [] : [sql2`route_key = ${input.routeKey}`],
|
|
2467
2219
|
claimablePredicate(input)
|
|
2468
2220
|
]);
|
|
2469
|
-
const claimUpdateSet = (input) =>
|
|
2221
|
+
const claimUpdateSet = (input) => sql2`
|
|
2470
2222
|
state = 'claimed',
|
|
2471
2223
|
claim_owner = ${input.workerId},
|
|
2472
2224
|
claim_expires_at = ${ts(input.claimExpiresAt)},
|
|
@@ -2474,11 +2226,11 @@ var layer9 = Layer9.effect(Service9, Effect9.gen(function* () {
|
|
|
2474
2226
|
updated_at = ${ts(input.now)},
|
|
2475
2227
|
attempt = attempt + 1
|
|
2476
2228
|
`;
|
|
2477
|
-
const runClaimReady =
|
|
2478
|
-
mysql: () => (
|
|
2479
|
-
const candidates = yield*
|
|
2229
|
+
const runClaimReady = sql2.onDialectOrElse({
|
|
2230
|
+
mysql: () => (tenantId, input) => sql2.withTransaction(Effect9.gen(function* () {
|
|
2231
|
+
const candidates = yield* sql2`
|
|
2480
2232
|
SELECT id FROM relay_envelope_ready
|
|
2481
|
-
WHERE ${claimConditions(
|
|
2233
|
+
WHERE ${claimConditions(tenantId, input)}
|
|
2482
2234
|
ORDER BY available_at ASC, created_at ASC
|
|
2483
2235
|
LIMIT 1
|
|
2484
2236
|
FOR UPDATE
|
|
@@ -2486,57 +2238,57 @@ var layer9 = Layer9.effect(Service9, Effect9.gen(function* () {
|
|
|
2486
2238
|
const candidate = candidates[0];
|
|
2487
2239
|
if (candidate === undefined)
|
|
2488
2240
|
return [];
|
|
2489
|
-
yield*
|
|
2241
|
+
yield* sql2`
|
|
2490
2242
|
UPDATE relay_envelope_ready
|
|
2491
2243
|
SET ${claimUpdateSet(input)}
|
|
2492
|
-
WHERE tenant_id = ${
|
|
2244
|
+
WHERE tenant_id = ${tenantId} AND id = ${candidate.id} AND ${claimablePredicate(input)}
|
|
2493
2245
|
`;
|
|
2494
|
-
const rows = yield*
|
|
2246
|
+
const rows = yield* sql2`
|
|
2495
2247
|
SELECT ${readyColumns}
|
|
2496
2248
|
FROM relay_envelope_ready
|
|
2497
|
-
WHERE tenant_id = ${
|
|
2249
|
+
WHERE tenant_id = ${tenantId} AND id = ${candidate.id}
|
|
2498
2250
|
`;
|
|
2499
2251
|
const row = rows[0];
|
|
2500
2252
|
if (row === undefined || row.state !== "claimed" || row.claim_owner !== input.workerId)
|
|
2501
2253
|
return [];
|
|
2502
2254
|
return rows;
|
|
2503
2255
|
})),
|
|
2504
|
-
orElse: () => (
|
|
2505
|
-
const candidates = yield*
|
|
2256
|
+
orElse: () => (tenantId, input) => Effect9.gen(function* () {
|
|
2257
|
+
const candidates = yield* sql2`
|
|
2506
2258
|
SELECT id FROM relay_envelope_ready
|
|
2507
|
-
WHERE ${claimConditions(
|
|
2259
|
+
WHERE ${claimConditions(tenantId, input)}
|
|
2508
2260
|
ORDER BY available_at ASC, created_at ASC
|
|
2509
2261
|
LIMIT 1
|
|
2510
2262
|
`;
|
|
2511
2263
|
const candidate = candidates[0];
|
|
2512
2264
|
if (candidate === undefined)
|
|
2513
2265
|
return [];
|
|
2514
|
-
return yield*
|
|
2266
|
+
return yield* sql2`
|
|
2515
2267
|
UPDATE relay_envelope_ready
|
|
2516
2268
|
SET ${claimUpdateSet(input)}
|
|
2517
|
-
WHERE tenant_id = ${
|
|
2269
|
+
WHERE tenant_id = ${tenantId} AND id = ${candidate.id} AND ${claimablePredicate(input)}
|
|
2518
2270
|
RETURNING ${readyColumns}
|
|
2519
2271
|
`;
|
|
2520
2272
|
})
|
|
2521
2273
|
});
|
|
2522
2274
|
const claimReady = Effect9.fn("EnvelopeRepository.claimReady")(function* (input) {
|
|
2523
|
-
const
|
|
2524
|
-
const rows = yield* runClaimReady(
|
|
2275
|
+
const tenantId = yield* current;
|
|
2276
|
+
const rows = yield* runClaimReady(tenantId, input).pipe(Effect9.mapError(toRepositoryError6));
|
|
2525
2277
|
return rows[0] === undefined ? undefined : toReadyRecord(yield* decodeReadyRow(rows[0]));
|
|
2526
2278
|
});
|
|
2527
|
-
const runReleaseReady =
|
|
2528
|
-
mysql: () => (
|
|
2529
|
-
const locked = yield*
|
|
2279
|
+
const runReleaseReady = sql2.onDialectOrElse({
|
|
2280
|
+
mysql: () => (tenantId, input) => sql2.withTransaction(Effect9.gen(function* () {
|
|
2281
|
+
const locked = yield* sql2`
|
|
2530
2282
|
SELECT ${readyColumns}
|
|
2531
2283
|
FROM relay_envelope_ready
|
|
2532
|
-
WHERE tenant_id = ${
|
|
2284
|
+
WHERE tenant_id = ${tenantId} AND id = ${input.id}
|
|
2533
2285
|
FOR UPDATE
|
|
2534
2286
|
`;
|
|
2535
2287
|
const current2 = locked[0];
|
|
2536
2288
|
if (current2 === undefined || current2.state !== "claimed" || current2.claim_owner !== input.workerId) {
|
|
2537
2289
|
return [];
|
|
2538
2290
|
}
|
|
2539
|
-
yield*
|
|
2291
|
+
yield* sql2`
|
|
2540
2292
|
UPDATE relay_envelope_ready
|
|
2541
2293
|
SET state = 'ready',
|
|
2542
2294
|
available_at = ${ts(input.nextAvailableAt)},
|
|
@@ -2544,11 +2296,11 @@ var layer9 = Layer9.effect(Service9, Effect9.gen(function* () {
|
|
|
2544
2296
|
claim_expires_at = NULL,
|
|
2545
2297
|
last_error = ${input.error ?? null},
|
|
2546
2298
|
updated_at = ${ts(input.nextAvailableAt)}
|
|
2547
|
-
WHERE tenant_id = ${
|
|
2299
|
+
WHERE tenant_id = ${tenantId} AND id = ${input.id}
|
|
2548
2300
|
`;
|
|
2549
|
-
return yield* selectReadyById(
|
|
2301
|
+
return yield* selectReadyById(tenantId, input.id);
|
|
2550
2302
|
})),
|
|
2551
|
-
orElse: () => (
|
|
2303
|
+
orElse: () => (tenantId, input) => sql2`
|
|
2552
2304
|
UPDATE relay_envelope_ready
|
|
2553
2305
|
SET state = 'ready',
|
|
2554
2306
|
available_at = ${ts(input.nextAvailableAt)},
|
|
@@ -2556,105 +2308,105 @@ var layer9 = Layer9.effect(Service9, Effect9.gen(function* () {
|
|
|
2556
2308
|
claim_expires_at = NULL,
|
|
2557
2309
|
last_error = ${input.error ?? null},
|
|
2558
2310
|
updated_at = ${ts(input.nextAvailableAt)}
|
|
2559
|
-
WHERE tenant_id = ${
|
|
2311
|
+
WHERE tenant_id = ${tenantId} AND id = ${input.id} AND claim_owner = ${input.workerId} AND state = 'claimed'
|
|
2560
2312
|
RETURNING ${readyColumns}
|
|
2561
2313
|
`
|
|
2562
2314
|
});
|
|
2563
2315
|
const releaseReady = Effect9.fn("EnvelopeRepository.releaseReady")(function* (input) {
|
|
2564
|
-
const
|
|
2565
|
-
const rows = yield* runReleaseReady(
|
|
2316
|
+
const tenantId = yield* current;
|
|
2317
|
+
const rows = yield* runReleaseReady(tenantId, input).pipe(Effect9.mapError(toRepositoryError6));
|
|
2566
2318
|
if (rows[0] !== undefined)
|
|
2567
2319
|
return toReadyRecord(yield* decodeReadyRow(rows[0]));
|
|
2568
|
-
const current2 = yield* getReadyRow(
|
|
2320
|
+
const current2 = yield* getReadyRow(tenantId, input.id);
|
|
2569
2321
|
if (current2 === undefined)
|
|
2570
2322
|
return yield* Effect9.fail(new EnvelopeReadyNotFound({ id: input.id }));
|
|
2571
2323
|
if (current2.state === "acknowledged" && current2.claim_owner === input.workerId)
|
|
2572
2324
|
return toReadyRecord(current2);
|
|
2573
2325
|
return yield* Effect9.fail(new EnvelopeReadyClaimMismatch({ id: input.id, worker_id: input.workerId }));
|
|
2574
2326
|
});
|
|
2575
|
-
const runAckReady =
|
|
2576
|
-
mysql: () => (
|
|
2577
|
-
const locked = yield*
|
|
2327
|
+
const runAckReady = sql2.onDialectOrElse({
|
|
2328
|
+
mysql: () => (tenantId, input) => sql2.withTransaction(Effect9.gen(function* () {
|
|
2329
|
+
const locked = yield* sql2`
|
|
2578
2330
|
SELECT ${readyColumns}
|
|
2579
2331
|
FROM relay_envelope_ready
|
|
2580
|
-
WHERE tenant_id = ${
|
|
2332
|
+
WHERE tenant_id = ${tenantId} AND id = ${input.id}
|
|
2581
2333
|
FOR UPDATE
|
|
2582
2334
|
`;
|
|
2583
2335
|
const current2 = locked[0];
|
|
2584
2336
|
if (current2 === undefined || current2.state !== "claimed" || current2.claim_owner !== input.workerId) {
|
|
2585
2337
|
return [];
|
|
2586
2338
|
}
|
|
2587
|
-
yield*
|
|
2339
|
+
yield* sql2`
|
|
2588
2340
|
UPDATE relay_envelope_ready
|
|
2589
2341
|
SET state = 'acknowledged',
|
|
2590
2342
|
acknowledged_at = ${ts(input.now)},
|
|
2591
2343
|
updated_at = ${ts(input.now)}
|
|
2592
|
-
WHERE tenant_id = ${
|
|
2344
|
+
WHERE tenant_id = ${tenantId} AND id = ${input.id}
|
|
2593
2345
|
`;
|
|
2594
|
-
return yield* selectReadyById(
|
|
2346
|
+
return yield* selectReadyById(tenantId, input.id);
|
|
2595
2347
|
})),
|
|
2596
|
-
orElse: () => (
|
|
2348
|
+
orElse: () => (tenantId, input) => sql2`
|
|
2597
2349
|
UPDATE relay_envelope_ready
|
|
2598
2350
|
SET state = 'acknowledged',
|
|
2599
2351
|
acknowledged_at = ${ts(input.now)},
|
|
2600
2352
|
updated_at = ${ts(input.now)}
|
|
2601
|
-
WHERE tenant_id = ${
|
|
2353
|
+
WHERE tenant_id = ${tenantId} AND id = ${input.id} AND claim_owner = ${input.workerId} AND state = 'claimed'
|
|
2602
2354
|
RETURNING ${readyColumns}
|
|
2603
2355
|
`
|
|
2604
2356
|
});
|
|
2605
2357
|
const ackReady = Effect9.fn("EnvelopeRepository.ackReady")(function* (input) {
|
|
2606
|
-
const
|
|
2607
|
-
const rows = yield* runAckReady(
|
|
2358
|
+
const tenantId = yield* current;
|
|
2359
|
+
const rows = yield* runAckReady(tenantId, input).pipe(Effect9.mapError(toRepositoryError6));
|
|
2608
2360
|
if (rows[0] !== undefined)
|
|
2609
2361
|
return toReadyRecord(yield* decodeReadyRow(rows[0]));
|
|
2610
|
-
const current2 = yield* getReadyRow(
|
|
2362
|
+
const current2 = yield* getReadyRow(tenantId, input.id);
|
|
2611
2363
|
if (current2 === undefined)
|
|
2612
2364
|
return yield* Effect9.fail(new EnvelopeReadyNotFound({ id: input.id }));
|
|
2613
2365
|
if (current2.state === "acknowledged" && current2.claim_owner === input.workerId)
|
|
2614
2366
|
return toReadyRecord(current2);
|
|
2615
2367
|
return yield* Effect9.fail(new EnvelopeReadyClaimMismatch({ id: input.id, worker_id: input.workerId }));
|
|
2616
2368
|
});
|
|
2617
|
-
const runCompleteWait =
|
|
2618
|
-
mysql: () => (
|
|
2619
|
-
const locked = yield*
|
|
2369
|
+
const runCompleteWait = sql2.onDialectOrElse({
|
|
2370
|
+
mysql: () => (tenantId, input, merged) => sql2.withTransaction(Effect9.gen(function* () {
|
|
2371
|
+
const locked = yield* sql2`
|
|
2620
2372
|
SELECT ${waitColumns}
|
|
2621
2373
|
FROM relay_waits
|
|
2622
|
-
WHERE tenant_id = ${
|
|
2374
|
+
WHERE tenant_id = ${tenantId} AND id = ${input.waitId}
|
|
2623
2375
|
FOR UPDATE
|
|
2624
2376
|
`;
|
|
2625
2377
|
const current2 = locked[0];
|
|
2626
2378
|
if (current2 === undefined || current2.state !== "open")
|
|
2627
2379
|
return [];
|
|
2628
|
-
yield*
|
|
2380
|
+
yield* sql2`
|
|
2629
2381
|
UPDATE relay_waits
|
|
2630
2382
|
SET state = ${input.state},
|
|
2631
2383
|
resolved_at = ${ts(input.completedAt)},
|
|
2632
2384
|
metadata_json = ${encodeJson(merged)}
|
|
2633
|
-
WHERE tenant_id = ${
|
|
2385
|
+
WHERE tenant_id = ${tenantId} AND id = ${input.waitId}
|
|
2634
2386
|
`;
|
|
2635
|
-
return yield* selectWaitById(
|
|
2387
|
+
return yield* selectWaitById(tenantId, input.waitId);
|
|
2636
2388
|
})),
|
|
2637
|
-
orElse: () => (
|
|
2389
|
+
orElse: () => (tenantId, input, merged) => sql2`
|
|
2638
2390
|
UPDATE relay_waits
|
|
2639
2391
|
SET state = ${input.state},
|
|
2640
2392
|
resolved_at = ${ts(input.completedAt)},
|
|
2641
2393
|
metadata_json = ${encodeJson(merged)}
|
|
2642
|
-
WHERE tenant_id = ${
|
|
2394
|
+
WHERE tenant_id = ${tenantId} AND id = ${input.waitId} AND state = 'open'
|
|
2643
2395
|
RETURNING ${waitColumns}
|
|
2644
2396
|
`
|
|
2645
2397
|
});
|
|
2646
2398
|
const completeWait = Effect9.fn("EnvelopeRepository.completeWait")(function* (input) {
|
|
2647
|
-
const
|
|
2648
|
-
const current2 = yield* getWaitRow(
|
|
2399
|
+
const tenantId = yield* current;
|
|
2400
|
+
const current2 = yield* getWaitRow(tenantId, input.waitId);
|
|
2649
2401
|
if (current2 === undefined)
|
|
2650
2402
|
return yield* Effect9.fail(new WaitNotFound({ id: input.waitId }));
|
|
2651
2403
|
const currentRecord = toWaitRecord(current2);
|
|
2652
2404
|
if (currentRecord.state !== "open")
|
|
2653
2405
|
return { wait: currentRecord, transitioned: false };
|
|
2654
2406
|
const merged = { ...currentRecord.metadata, ...metadata3(input.metadata) };
|
|
2655
|
-
const rows = yield* runCompleteWait(
|
|
2407
|
+
const rows = yield* runCompleteWait(tenantId, input, merged).pipe(Effect9.mapError(toRepositoryError6));
|
|
2656
2408
|
if (rows[0] === undefined) {
|
|
2657
|
-
const latest = yield* getWaitRow(
|
|
2409
|
+
const latest = yield* getWaitRow(tenantId, input.waitId);
|
|
2658
2410
|
if (latest === undefined)
|
|
2659
2411
|
return yield* Effect9.fail(new WaitNotFound({ id: input.waitId }));
|
|
2660
2412
|
return { wait: toWaitRecord(latest), transitioned: false };
|
|
@@ -2870,30 +2622,482 @@ var resolveWait = Effect9.fn("EnvelopeRepository.resolveWait.call")(function* (i
|
|
|
2870
2622
|
return yield* repository.resolveWait(input);
|
|
2871
2623
|
});
|
|
2872
2624
|
// ../store-sql/src/execution/execution-event-repository.ts
|
|
2873
|
-
var exports_execution_event_repository = {};
|
|
2874
|
-
__export(exports_execution_event_repository, {
|
|
2875
|
-
testLayer: () => testLayer9,
|
|
2876
|
-
sumUsage: () => sumUsage,
|
|
2877
|
-
notifyAppended: () => notifyAppended,
|
|
2878
|
-
memoryLayer: () => memoryLayer8,
|
|
2879
|
-
maxSequence: () => maxSequence,
|
|
2880
|
-
listAfterSequence: () => listAfterSequence,
|
|
2881
|
-
list: () => list4,
|
|
2882
|
-
layer: () => layer10,
|
|
2883
|
-
findFirstByTypeAfterSequence: () => findFirstByTypeAfterSequence,
|
|
2884
|
-
findBySequenceOrCursor: () => findBySequenceOrCursor,
|
|
2885
|
-
findByCursor: () => findByCursor,
|
|
2886
|
-
executionEventsChannel: () => executionEventsChannel,
|
|
2887
|
-
appendedSignals: () => appendedSignals,
|
|
2888
|
-
append: () => append,
|
|
2889
|
-
Service: () => Service10,
|
|
2890
|
-
ExecutionEventRepositoryError: () => ExecutionEventRepositoryError,
|
|
2891
|
-
ExecutionEventOrderViolation: () => ExecutionEventOrderViolation,
|
|
2892
|
-
ExecutionEventCursorNotFound: () => ExecutionEventCursorNotFound,
|
|
2893
|
-
DuplicateExecutionEvent: () => DuplicateExecutionEvent
|
|
2894
|
-
});
|
|
2895
|
-
import { asc
|
|
2896
|
-
import { Context as Context10, Effect as Effect10, Filter, Layer as Layer10, Option as Option2, Schema as Schema20, Stream } from "effect";
|
|
2625
|
+
var exports_execution_event_repository = {};
|
|
2626
|
+
__export(exports_execution_event_repository, {
|
|
2627
|
+
testLayer: () => testLayer9,
|
|
2628
|
+
sumUsage: () => sumUsage,
|
|
2629
|
+
notifyAppended: () => notifyAppended,
|
|
2630
|
+
memoryLayer: () => memoryLayer8,
|
|
2631
|
+
maxSequence: () => maxSequence,
|
|
2632
|
+
listAfterSequence: () => listAfterSequence,
|
|
2633
|
+
list: () => list4,
|
|
2634
|
+
layer: () => layer10,
|
|
2635
|
+
findFirstByTypeAfterSequence: () => findFirstByTypeAfterSequence,
|
|
2636
|
+
findBySequenceOrCursor: () => findBySequenceOrCursor,
|
|
2637
|
+
findByCursor: () => findByCursor,
|
|
2638
|
+
executionEventsChannel: () => executionEventsChannel,
|
|
2639
|
+
appendedSignals: () => appendedSignals,
|
|
2640
|
+
append: () => append,
|
|
2641
|
+
Service: () => Service10,
|
|
2642
|
+
ExecutionEventRepositoryError: () => ExecutionEventRepositoryError,
|
|
2643
|
+
ExecutionEventOrderViolation: () => ExecutionEventOrderViolation,
|
|
2644
|
+
ExecutionEventCursorNotFound: () => ExecutionEventCursorNotFound,
|
|
2645
|
+
DuplicateExecutionEvent: () => DuplicateExecutionEvent
|
|
2646
|
+
});
|
|
2647
|
+
import { asc, desc, eq as eq2, gt, max, or, sql as sql3 } from "drizzle-orm";
|
|
2648
|
+
import { Context as Context10, Effect as Effect10, Filter, Layer as Layer10, Option as Option2, Schema as Schema20, Stream } from "effect";
|
|
2649
|
+
|
|
2650
|
+
// ../store-sql/src/schema/relay-schema.ts
|
|
2651
|
+
var exports_relay_schema = {};
|
|
2652
|
+
__export(exports_relay_schema, {
|
|
2653
|
+
relayWorkspaceSnapshots: () => relayWorkspaceSnapshots,
|
|
2654
|
+
relayWorkspaceLeases: () => relayWorkspaceLeases,
|
|
2655
|
+
relayWaits: () => relayWaits,
|
|
2656
|
+
relayToolResults: () => relayToolResults,
|
|
2657
|
+
relayToolCalls: () => relayToolCalls,
|
|
2658
|
+
relaySteeringMessages: () => relaySteeringMessages,
|
|
2659
|
+
relaySteeringDrains: () => relaySteeringDrains,
|
|
2660
|
+
relaySkillDefinitions: () => relaySkillDefinitions,
|
|
2661
|
+
relaySkillDefinitionRevisions: () => relaySkillDefinitionRevisions,
|
|
2662
|
+
relaySessions: () => relaySessions,
|
|
2663
|
+
relaySessionEntries: () => relaySessionEntries,
|
|
2664
|
+
relaySchedules: () => relaySchedules,
|
|
2665
|
+
relayRouteAttempts: () => relayRouteAttempts,
|
|
2666
|
+
relayPermissionRules: () => relayPermissionRules,
|
|
2667
|
+
relayMemoryRecords: () => relayMemoryRecords,
|
|
2668
|
+
relayIdempotencyKeys: () => relayIdempotencyKeys,
|
|
2669
|
+
relayExecutions: () => relayExecutions,
|
|
2670
|
+
relayExecutionSkillPins: () => relayExecutionSkillPins,
|
|
2671
|
+
relayExecutionEvents: () => relayExecutionEvents,
|
|
2672
|
+
relayExecutionContextEpochs: () => relayExecutionContextEpochs,
|
|
2673
|
+
relayEnvelopes: () => relayEnvelopes,
|
|
2674
|
+
relayEnvelopeReady: () => relayEnvelopeReady,
|
|
2675
|
+
relayChildExecutions: () => relayChildExecutions,
|
|
2676
|
+
relayAgentDefinitions: () => relayAgentDefinitions,
|
|
2677
|
+
relayAgentDefinitionRevisions: () => relayAgentDefinitionRevisions,
|
|
2678
|
+
relayAgentCompactions: () => relayAgentCompactions,
|
|
2679
|
+
relayAgentChats: () => relayAgentChats,
|
|
2680
|
+
relayAddressBookEntries: () => relayAddressBookEntries
|
|
2681
|
+
});
|
|
2682
|
+
import {
|
|
2683
|
+
doublePrecision,
|
|
2684
|
+
index,
|
|
2685
|
+
integer,
|
|
2686
|
+
jsonb,
|
|
2687
|
+
pgTable,
|
|
2688
|
+
primaryKey,
|
|
2689
|
+
text as text2,
|
|
2690
|
+
timestamp,
|
|
2691
|
+
uniqueIndex
|
|
2692
|
+
} from "drizzle-orm/pg-core";
|
|
2693
|
+
import { sql as sql2 } from "drizzle-orm";
|
|
2694
|
+
var tenantId = () => text2("tenant_id").$type().notNull().default(exports_ids_schema.SystemTenantId);
|
|
2695
|
+
var relayAddressBookEntries = pgTable("relay_address_book_entries", {
|
|
2696
|
+
tenantId: tenantId(),
|
|
2697
|
+
id: text2("id").$type().notNull(),
|
|
2698
|
+
addressId: text2("address_id").$type().notNull(),
|
|
2699
|
+
routeKind: text2("route_kind").notNull(),
|
|
2700
|
+
routeKey: text2("route_key").notNull(),
|
|
2701
|
+
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
2702
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
2703
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
|
|
2704
|
+
}, (table) => [
|
|
2705
|
+
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_address_book_entries" }),
|
|
2706
|
+
uniqueIndex("uq_relay_address_book_address").on(table.tenantId, table.addressId)
|
|
2707
|
+
]);
|
|
2708
|
+
var relayAgentDefinitions = pgTable("relay_agent_definitions", {
|
|
2709
|
+
tenantId: tenantId(),
|
|
2710
|
+
id: text2("id").$type().notNull(),
|
|
2711
|
+
name: text2("name").notNull(),
|
|
2712
|
+
currentRevision: integer("current_revision").$type().notNull(),
|
|
2713
|
+
definitionJson: jsonb("definition_json").$type().notNull(),
|
|
2714
|
+
toolInputSchemaDigestsJson: jsonb("tool_input_schema_digests_json").$type().notNull().default({}),
|
|
2715
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
2716
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
|
|
2717
|
+
}, (table) => [
|
|
2718
|
+
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_agent_definitions" }),
|
|
2719
|
+
index("idx_relay_agent_definitions_name").on(table.tenantId, table.name)
|
|
2720
|
+
]);
|
|
2721
|
+
var relayAgentDefinitionRevisions = pgTable("relay_agent_definition_revisions", {
|
|
2722
|
+
tenantId: tenantId(),
|
|
2723
|
+
agentDefinitionId: text2("agent_definition_id").$type().notNull(),
|
|
2724
|
+
revision: integer("revision").$type().notNull(),
|
|
2725
|
+
name: text2("name").notNull(),
|
|
2726
|
+
definitionJson: jsonb("definition_json").$type().notNull(),
|
|
2727
|
+
toolInputSchemaDigestsJson: jsonb("tool_input_schema_digests_json").$type().notNull().default({}),
|
|
2728
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
2729
|
+
}, (table) => [
|
|
2730
|
+
primaryKey({
|
|
2731
|
+
columns: [table.tenantId, table.agentDefinitionId, table.revision],
|
|
2732
|
+
name: "pk_relay_agent_definition_revisions"
|
|
2733
|
+
}),
|
|
2734
|
+
index("idx_relay_agent_definition_revisions_definition").on(table.tenantId, table.agentDefinitionId, table.revision)
|
|
2735
|
+
]);
|
|
2736
|
+
var relaySkillDefinitions = pgTable("relay_skill_definitions", {
|
|
2737
|
+
tenantId: tenantId(),
|
|
2738
|
+
id: text2("id").$type().notNull(),
|
|
2739
|
+
name: text2("name").notNull(),
|
|
2740
|
+
currentRevision: integer("current_revision").$type().notNull(),
|
|
2741
|
+
definitionJson: jsonb("definition_json").$type().notNull(),
|
|
2742
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
2743
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
|
|
2744
|
+
}, (table) => [
|
|
2745
|
+
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_skill_definitions" }),
|
|
2746
|
+
index("idx_relay_skill_definitions_name").on(table.tenantId, table.name)
|
|
2747
|
+
]);
|
|
2748
|
+
var relaySkillDefinitionRevisions = pgTable("relay_skill_definition_revisions", {
|
|
2749
|
+
tenantId: tenantId(),
|
|
2750
|
+
skillDefinitionId: text2("skill_definition_id").notNull().$type(),
|
|
2751
|
+
revision: integer("revision").notNull().$type(),
|
|
2752
|
+
name: text2("name").notNull(),
|
|
2753
|
+
definitionJson: jsonb("definition_json").$type().notNull(),
|
|
2754
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
2755
|
+
}, (table) => [
|
|
2756
|
+
primaryKey({
|
|
2757
|
+
columns: [table.tenantId, table.skillDefinitionId, table.revision],
|
|
2758
|
+
name: "pk_relay_skill_definition_revisions"
|
|
2759
|
+
}),
|
|
2760
|
+
index("idx_relay_skill_definition_revisions_definition").on(table.tenantId, table.skillDefinitionId, table.revision)
|
|
2761
|
+
]);
|
|
2762
|
+
var relayExecutionSkillPins = pgTable("relay_execution_skill_pins", {
|
|
2763
|
+
tenantId: tenantId(),
|
|
2764
|
+
executionId: text2("execution_id").notNull().$type(),
|
|
2765
|
+
skillDefinitionId: text2("skill_definition_id").notNull().$type(),
|
|
2766
|
+
skillDefinitionRevision: integer("skill_definition_revision").notNull().$type(),
|
|
2767
|
+
skillDefinitionSnapshotJson: jsonb("skill_definition_snapshot_json").$type().notNull(),
|
|
2768
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
2769
|
+
}, (table) => [
|
|
2770
|
+
primaryKey({
|
|
2771
|
+
columns: [table.tenantId, table.executionId, table.skillDefinitionId],
|
|
2772
|
+
name: "pk_relay_execution_skill_pins"
|
|
2773
|
+
}),
|
|
2774
|
+
index("idx_relay_execution_skill_pins_execution").on(table.tenantId, table.executionId)
|
|
2775
|
+
]);
|
|
2776
|
+
var relayAgentChats = pgTable("relay_agent_chats", {
|
|
2777
|
+
tenantId: tenantId(),
|
|
2778
|
+
executionId: text2("execution_id").$type().notNull(),
|
|
2779
|
+
exportJson: jsonb("export_json").notNull(),
|
|
2780
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
|
|
2781
|
+
}, (table) => [primaryKey({ columns: [table.tenantId, table.executionId], name: "pk_relay_agent_chats" })]);
|
|
2782
|
+
var relayAgentCompactions = pgTable("relay_agent_compactions", {
|
|
2783
|
+
tenantId: tenantId(),
|
|
2784
|
+
executionId: text2("execution_id").notNull().$type(),
|
|
2785
|
+
checkpointId: text2("checkpoint_id").notNull(),
|
|
2786
|
+
summary: text2("summary").notNull(),
|
|
2787
|
+
firstKeptEntryId: text2("first_kept_entry_id").$type().notNull(),
|
|
2788
|
+
turn: integer("turn").notNull(),
|
|
2789
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
2790
|
+
}, (table) => [
|
|
2791
|
+
primaryKey({
|
|
2792
|
+
columns: [table.tenantId, table.executionId, table.checkpointId],
|
|
2793
|
+
name: "pk_relay_agent_compactions"
|
|
2794
|
+
}),
|
|
2795
|
+
index("idx_relay_agent_compactions_execution_turn").on(table.tenantId, table.executionId, table.turn)
|
|
2796
|
+
]);
|
|
2797
|
+
var relayMemoryRecords = pgTable("relay_memory_records", {
|
|
2798
|
+
tenantId: tenantId(),
|
|
2799
|
+
id: text2("id").notNull(),
|
|
2800
|
+
agent: text2("agent").notNull(),
|
|
2801
|
+
subject: text2("subject").$type().notNull(),
|
|
2802
|
+
embedding: doublePrecision("embedding").array().notNull(),
|
|
2803
|
+
partsJson: jsonb("parts_json").$type().notNull(),
|
|
2804
|
+
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
2805
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
2806
|
+
}, (table) => [
|
|
2807
|
+
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_memory_records" }),
|
|
2808
|
+
index("idx_relay_memory_records_agent_subject").on(table.tenantId, table.agent, table.subject)
|
|
2809
|
+
]);
|
|
2810
|
+
var relayPermissionRules = pgTable("relay_permission_rules", {
|
|
2811
|
+
tenantId: tenantId(),
|
|
2812
|
+
agent: text2("agent").notNull(),
|
|
2813
|
+
scope: text2("scope").notNull(),
|
|
2814
|
+
pattern: text2("pattern").notNull(),
|
|
2815
|
+
ruleJson: jsonb("rule_json").$type().notNull(),
|
|
2816
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
2817
|
+
}, (table) => [
|
|
2818
|
+
primaryKey({
|
|
2819
|
+
columns: [table.tenantId, table.agent, table.scope, table.pattern],
|
|
2820
|
+
name: "pk_relay_permission_rules"
|
|
2821
|
+
}),
|
|
2822
|
+
index("idx_relay_permission_rules_agent_scope").on(table.tenantId, table.agent, table.scope)
|
|
2823
|
+
]);
|
|
2824
|
+
var relaySteeringMessages = pgTable("relay_steering_messages", {
|
|
2825
|
+
tenantId: tenantId(),
|
|
2826
|
+
executionId: text2("execution_id").notNull(),
|
|
2827
|
+
kind: text2("kind").notNull(),
|
|
2828
|
+
sequence: integer("sequence").notNull(),
|
|
2829
|
+
contentJson: jsonb("content_json").$type().notNull(),
|
|
2830
|
+
drainId: text2("drain_id"),
|
|
2831
|
+
consumedAt: timestamp("consumed_at", { withTimezone: true }),
|
|
2832
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
2833
|
+
}, (table) => [
|
|
2834
|
+
primaryKey({
|
|
2835
|
+
columns: [table.tenantId, table.executionId, table.kind, table.sequence],
|
|
2836
|
+
name: "pk_relay_steering_messages"
|
|
2837
|
+
}),
|
|
2838
|
+
index("idx_relay_steering_messages_unconsumed").on(table.tenantId, table.executionId, table.kind, table.consumedAt, table.sequence),
|
|
2839
|
+
index("idx_relay_steering_messages_drain").on(table.tenantId, table.executionId, table.kind, table.drainId, table.sequence)
|
|
2840
|
+
]);
|
|
2841
|
+
var relaySteeringDrains = pgTable("relay_steering_drains", {
|
|
2842
|
+
tenantId: tenantId(),
|
|
2843
|
+
executionId: text2("execution_id").notNull(),
|
|
2844
|
+
kind: text2("kind").notNull(),
|
|
2845
|
+
drainId: text2("drain_id").notNull(),
|
|
2846
|
+
messageSequencesJson: jsonb("message_sequences_json").$type().notNull().default([]),
|
|
2847
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
2848
|
+
}, (table) => [
|
|
2849
|
+
primaryKey({
|
|
2850
|
+
columns: [table.tenantId, table.executionId, table.kind, table.drainId],
|
|
2851
|
+
name: "pk_relay_steering_drains"
|
|
2852
|
+
})
|
|
2853
|
+
]);
|
|
2854
|
+
var relaySessions = pgTable("relay_sessions", {
|
|
2855
|
+
tenantId: tenantId(),
|
|
2856
|
+
id: text2("id").$type().notNull(),
|
|
2857
|
+
rootAddressId: text2("root_address_id").$type().notNull(),
|
|
2858
|
+
leafEntryId: text2("leaf_entry_id").$type(),
|
|
2859
|
+
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
2860
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
2861
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
|
|
2862
|
+
}, (table) => [
|
|
2863
|
+
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_sessions" }),
|
|
2864
|
+
index("idx_relay_sessions_updated_id").on(table.tenantId, table.updatedAt, table.id),
|
|
2865
|
+
index("idx_relay_sessions_root_updated_id").on(table.tenantId, table.rootAddressId, table.updatedAt, table.id)
|
|
2866
|
+
]);
|
|
2867
|
+
var relaySessionEntries = pgTable("relay_session_entries", {
|
|
2868
|
+
tenantId: tenantId(),
|
|
2869
|
+
id: text2("id").$type().notNull(),
|
|
2870
|
+
sessionId: text2("session_id").$type().notNull(),
|
|
2871
|
+
parentId: text2("parent_id").$type(),
|
|
2872
|
+
tag: text2("tag").notNull(),
|
|
2873
|
+
payloadJson: jsonb("payload_json").notNull(),
|
|
2874
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
2875
|
+
}, (table) => [
|
|
2876
|
+
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_session_entries" }),
|
|
2877
|
+
index("idx_relay_session_entries_session_created").on(table.tenantId, table.sessionId, table.createdAt, table.id),
|
|
2878
|
+
index("idx_relay_session_entries_session_parent").on(table.tenantId, table.sessionId, table.parentId)
|
|
2879
|
+
]);
|
|
2880
|
+
var relayExecutionContextEpochs = pgTable("relay_execution_context_epochs", {
|
|
2881
|
+
tenantId: tenantId(),
|
|
2882
|
+
executionId: text2("execution_id").$type().notNull(),
|
|
2883
|
+
baseline: text2("baseline").notNull(),
|
|
2884
|
+
dynamicSourceIdsJson: jsonb("dynamic_source_ids_json").$type().notNull().default([]),
|
|
2885
|
+
openedAt: timestamp("opened_at", { withTimezone: true }).notNull().defaultNow()
|
|
2886
|
+
}, (table) => [primaryKey({ columns: [table.tenantId, table.executionId], name: "pk_relay_execution_context_epochs" })]);
|
|
2887
|
+
var relayExecutions = pgTable("relay_executions", {
|
|
2888
|
+
tenantId: tenantId(),
|
|
2889
|
+
id: text2("id").$type().notNull(),
|
|
2890
|
+
rootAddressId: text2("root_address_id").$type().notNull(),
|
|
2891
|
+
sessionId: text2("session_id").$type(),
|
|
2892
|
+
status: text2("status").$type().notNull(),
|
|
2893
|
+
agentDefinitionId: text2("agent_definition_id").$type(),
|
|
2894
|
+
agentDefinitionRevision: integer("agent_definition_revision").$type(),
|
|
2895
|
+
agentDefinitionSnapshotJson: jsonb("agent_definition_snapshot_json").$type(),
|
|
2896
|
+
agentDefinitionToolInputSchemaDigestsJson: jsonb("agent_definition_tool_input_schema_digests_json").$type().notNull().default({}),
|
|
2897
|
+
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
2898
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
2899
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
|
|
2900
|
+
}, (table) => [
|
|
2901
|
+
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_executions" }),
|
|
2902
|
+
index("idx_relay_executions_root_status").on(table.tenantId, table.rootAddressId, table.status),
|
|
2903
|
+
index("idx_relay_executions_session_updated_id").on(table.tenantId, table.sessionId, table.updatedAt, table.id),
|
|
2904
|
+
index("idx_relay_executions_updated_id").on(table.tenantId, table.updatedAt, table.id),
|
|
2905
|
+
index("idx_relay_executions_root_status_updated_id").on(table.tenantId, table.rootAddressId, table.status, table.updatedAt, table.id)
|
|
2906
|
+
]);
|
|
2907
|
+
var relayChildExecutions = pgTable("relay_child_executions", {
|
|
2908
|
+
tenantId: tenantId(),
|
|
2909
|
+
id: text2("id").$type().notNull(),
|
|
2910
|
+
executionId: text2("execution_id").$type().notNull(),
|
|
2911
|
+
addressId: text2("address_id").$type().notNull(),
|
|
2912
|
+
status: text2("status").$type().notNull(),
|
|
2913
|
+
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
2914
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
2915
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
|
|
2916
|
+
}, (table) => [
|
|
2917
|
+
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_child_executions" }),
|
|
2918
|
+
index("idx_relay_child_executions_parent").on(table.tenantId, table.executionId)
|
|
2919
|
+
]);
|
|
2920
|
+
var relayEnvelopes = pgTable("relay_envelopes", {
|
|
2921
|
+
tenantId: tenantId(),
|
|
2922
|
+
id: text2("id").$type().notNull(),
|
|
2923
|
+
executionId: text2("execution_id").$type().notNull(),
|
|
2924
|
+
fromAddressId: text2("from_address_id").$type().notNull(),
|
|
2925
|
+
toAddressId: text2("to_address_id").$type().notNull(),
|
|
2926
|
+
contentJson: jsonb("content_json").$type().notNull(),
|
|
2927
|
+
waitJson: jsonb("wait_json").$type(),
|
|
2928
|
+
correlationKey: text2("correlation_key"),
|
|
2929
|
+
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
2930
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
2931
|
+
}, (table) => [
|
|
2932
|
+
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_envelopes" }),
|
|
2933
|
+
index("idx_relay_envelopes_execution").on(table.tenantId, table.executionId, table.createdAt),
|
|
2934
|
+
index("idx_relay_envelopes_to_address").on(table.tenantId, table.toAddressId, table.createdAt)
|
|
2935
|
+
]);
|
|
2936
|
+
var relayWaits = pgTable("relay_waits", {
|
|
2937
|
+
tenantId: tenantId(),
|
|
2938
|
+
id: text2("id").$type().notNull(),
|
|
2939
|
+
executionId: text2("execution_id").$type().notNull(),
|
|
2940
|
+
envelopeId: text2("envelope_id").$type(),
|
|
2941
|
+
mode: text2("mode").$type().notNull(),
|
|
2942
|
+
correlationKey: text2("correlation_key"),
|
|
2943
|
+
state: text2("state").notNull().default("open"),
|
|
2944
|
+
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
2945
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
2946
|
+
resolvedAt: timestamp("resolved_at", { withTimezone: true })
|
|
2947
|
+
}, (table) => [
|
|
2948
|
+
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_waits" }),
|
|
2949
|
+
index("idx_relay_waits_execution_state").on(table.tenantId, table.executionId, table.state)
|
|
2950
|
+
]);
|
|
2951
|
+
var relayWorkspaceLeases = pgTable("relay_workspace_leases", {
|
|
2952
|
+
tenantId: tenantId(),
|
|
2953
|
+
id: text2("id").$type().notNull(),
|
|
2954
|
+
executionId: text2("execution_id").$type().notNull(),
|
|
2955
|
+
providerKey: text2("provider_key").$type().notNull(),
|
|
2956
|
+
sandboxRef: text2("sandbox_ref").$type(),
|
|
2957
|
+
latestSnapshotRef: text2("latest_snapshot_ref").$type(),
|
|
2958
|
+
status: text2("status").$type().notNull(),
|
|
2959
|
+
resumeStrategy: text2("resume_strategy").$type().notNull(),
|
|
2960
|
+
region: text2("region"),
|
|
2961
|
+
requestJson: jsonb("request_json").$type(),
|
|
2962
|
+
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
2963
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
2964
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
|
|
2965
|
+
}, (table) => [
|
|
2966
|
+
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_workspace_leases" }),
|
|
2967
|
+
uniqueIndex("uq_relay_workspace_leases_active_execution").on(table.tenantId, table.executionId).where(sql2`${table.status} not in ('released', 'failed')`),
|
|
2968
|
+
index("idx_relay_workspace_leases_execution").on(table.tenantId, table.executionId),
|
|
2969
|
+
index("idx_relay_workspace_leases_status_updated").on(table.tenantId, table.status, table.updatedAt)
|
|
2970
|
+
]);
|
|
2971
|
+
var relayWorkspaceSnapshots = pgTable("relay_workspace_snapshots", {
|
|
2972
|
+
tenantId: tenantId(),
|
|
2973
|
+
id: text2("id").$type().notNull(),
|
|
2974
|
+
leaseId: text2("lease_id").$type().notNull(),
|
|
2975
|
+
executionId: text2("execution_id").$type().notNull(),
|
|
2976
|
+
reason: text2("reason").$type().notNull(),
|
|
2977
|
+
snapshotRef: text2("snapshot_ref").$type().notNull(),
|
|
2978
|
+
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
2979
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
2980
|
+
}, (table) => [
|
|
2981
|
+
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_workspace_snapshots" }),
|
|
2982
|
+
index("idx_relay_workspace_snapshots_lease").on(table.tenantId, table.leaseId, table.createdAt),
|
|
2983
|
+
index("idx_relay_workspace_snapshots_execution").on(table.tenantId, table.executionId, table.createdAt)
|
|
2984
|
+
]);
|
|
2985
|
+
var relayEnvelopeReady = pgTable("relay_envelope_ready", {
|
|
2986
|
+
tenantId: tenantId(),
|
|
2987
|
+
id: text2("id").$type().notNull(),
|
|
2988
|
+
envelopeId: text2("envelope_id").$type().notNull(),
|
|
2989
|
+
routeType: text2("route_type").notNull(),
|
|
2990
|
+
routeKey: text2("route_key").notNull(),
|
|
2991
|
+
state: text2("state").notNull().default("ready"),
|
|
2992
|
+
availableAt: timestamp("available_at", { withTimezone: true }).notNull().defaultNow(),
|
|
2993
|
+
attempt: integer("attempt").notNull().default(0),
|
|
2994
|
+
claimOwner: text2("claim_owner"),
|
|
2995
|
+
claimExpiresAt: timestamp("claim_expires_at", { withTimezone: true }),
|
|
2996
|
+
lastError: text2("last_error"),
|
|
2997
|
+
idempotencyKey: text2("idempotency_key"),
|
|
2998
|
+
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
2999
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
3000
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
3001
|
+
claimedAt: timestamp("claimed_at", { withTimezone: true }),
|
|
3002
|
+
acknowledgedAt: timestamp("acknowledged_at", { withTimezone: true })
|
|
3003
|
+
}, (table) => [
|
|
3004
|
+
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_envelope_ready" }),
|
|
3005
|
+
index("idx_relay_envelope_ready_state_available").on(table.tenantId, table.state, table.availableAt),
|
|
3006
|
+
index("idx_relay_envelope_ready_claim_expires").on(table.tenantId, table.claimExpiresAt),
|
|
3007
|
+
uniqueIndex("uq_relay_envelope_ready_idempotency").on(table.tenantId, table.idempotencyKey)
|
|
3008
|
+
]);
|
|
3009
|
+
var relaySchedules = pgTable("relay_schedules", {
|
|
3010
|
+
tenantId: tenantId(),
|
|
3011
|
+
id: text2("id").$type().notNull(),
|
|
3012
|
+
kind: text2("kind").notNull(),
|
|
3013
|
+
targetKind: text2("target_kind").notNull(),
|
|
3014
|
+
addressId: text2("address_id").$type(),
|
|
3015
|
+
waitId: text2("wait_id").$type(),
|
|
3016
|
+
cronExpr: text2("cron_expr"),
|
|
3017
|
+
inputJson: jsonb("input_json").$type(),
|
|
3018
|
+
state: text2("state").notNull().default("active"),
|
|
3019
|
+
nextRunAt: timestamp("next_run_at", { withTimezone: true }).notNull(),
|
|
3020
|
+
attempt: integer("attempt").notNull().default(0),
|
|
3021
|
+
claimOwner: text2("claim_owner"),
|
|
3022
|
+
claimExpiresAt: timestamp("claim_expires_at", { withTimezone: true }),
|
|
3023
|
+
lastError: text2("last_error"),
|
|
3024
|
+
idempotencyKey: text2("idempotency_key"),
|
|
3025
|
+
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
3026
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
3027
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
|
|
3028
|
+
}, (table) => [
|
|
3029
|
+
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_schedules" }),
|
|
3030
|
+
index("idx_relay_schedules_state_next_run").on(table.tenantId, table.state, table.nextRunAt),
|
|
3031
|
+
index("idx_relay_schedules_claim_expires").on(table.tenantId, table.claimExpiresAt),
|
|
3032
|
+
index("idx_relay_schedules_wait").on(table.tenantId, table.waitId),
|
|
3033
|
+
uniqueIndex("uq_relay_schedules_idempotency").on(table.tenantId, table.idempotencyKey)
|
|
3034
|
+
]);
|
|
3035
|
+
var relayExecutionEvents = pgTable("relay_execution_events", {
|
|
3036
|
+
tenantId: tenantId(),
|
|
3037
|
+
id: text2("id").$type().notNull(),
|
|
3038
|
+
executionId: text2("execution_id").$type().notNull(),
|
|
3039
|
+
childExecutionId: text2("child_execution_id").$type(),
|
|
3040
|
+
type: text2("type").notNull(),
|
|
3041
|
+
sequence: integer("sequence").notNull(),
|
|
3042
|
+
cursor: text2("cursor").notNull(),
|
|
3043
|
+
contentJson: jsonb("content_json").$type(),
|
|
3044
|
+
dataJson: jsonb("data_json").$type().notNull().default({}),
|
|
3045
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
3046
|
+
}, (table) => [
|
|
3047
|
+
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_execution_events" }),
|
|
3048
|
+
index("idx_relay_execution_events_execution").on(table.tenantId, table.executionId, table.createdAt),
|
|
3049
|
+
uniqueIndex("uq_relay_execution_events_sequence").on(table.tenantId, table.executionId, table.sequence),
|
|
3050
|
+
uniqueIndex("uq_relay_execution_events_cursor").on(table.tenantId, table.cursor)
|
|
3051
|
+
]);
|
|
3052
|
+
var relayToolCalls = pgTable("relay_tool_calls", {
|
|
3053
|
+
tenantId: tenantId(),
|
|
3054
|
+
id: text2("id").$type().notNull(),
|
|
3055
|
+
executionId: text2("execution_id").$type().notNull(),
|
|
3056
|
+
name: text2("name").notNull(),
|
|
3057
|
+
inputJson: jsonb("input_json").notNull(),
|
|
3058
|
+
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
3059
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
3060
|
+
}, (table) => [
|
|
3061
|
+
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_tool_calls" }),
|
|
3062
|
+
index("idx_relay_tool_calls_execution").on(table.tenantId, table.executionId, table.createdAt)
|
|
3063
|
+
]);
|
|
3064
|
+
var relayToolResults = pgTable("relay_tool_results", {
|
|
3065
|
+
tenantId: tenantId(),
|
|
3066
|
+
toolCallId: text2("tool_call_id").$type().notNull(),
|
|
3067
|
+
outputJson: jsonb("output_json").notNull(),
|
|
3068
|
+
error: text2("error"),
|
|
3069
|
+
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
3070
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
3071
|
+
}, (table) => [primaryKey({ columns: [table.tenantId, table.toolCallId], name: "pk_relay_tool_results" })]);
|
|
3072
|
+
var relayRouteAttempts = pgTable("relay_route_attempts", {
|
|
3073
|
+
tenantId: tenantId(),
|
|
3074
|
+
id: text2("id").notNull(),
|
|
3075
|
+
envelopeReadyId: text2("envelope_ready_id").$type().notNull(),
|
|
3076
|
+
routeKey: text2("route_key").notNull(),
|
|
3077
|
+
state: text2("state").notNull(),
|
|
3078
|
+
detail: text2("detail"),
|
|
3079
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
|
|
3080
|
+
}, (table) => [
|
|
3081
|
+
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_route_attempts" }),
|
|
3082
|
+
index("idx_relay_route_attempts_ready").on(table.tenantId, table.envelopeReadyId, table.createdAt)
|
|
3083
|
+
]);
|
|
3084
|
+
var relayIdempotencyKeys = pgTable("relay_idempotency_keys", {
|
|
3085
|
+
tenantId: tenantId(),
|
|
3086
|
+
id: text2("id").notNull(),
|
|
3087
|
+
scope: text2("scope").notNull(),
|
|
3088
|
+
operation: text2("operation").notNull(),
|
|
3089
|
+
key: text2("key").notNull(),
|
|
3090
|
+
resultJson: jsonb("result_json").$type(),
|
|
3091
|
+
metadataJson: jsonb("metadata_json").$type().notNull().default({}),
|
|
3092
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
3093
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
3094
|
+
expiresAt: timestamp("expires_at", { withTimezone: true })
|
|
3095
|
+
}, (table) => [
|
|
3096
|
+
primaryKey({ columns: [table.tenantId, table.id], name: "pk_relay_idempotency_keys" }),
|
|
3097
|
+
uniqueIndex("uq_relay_idempotency_scope_operation_key").on(table.tenantId, table.scope, table.operation, table.key)
|
|
3098
|
+
]);
|
|
3099
|
+
|
|
3100
|
+
// ../store-sql/src/execution/execution-event-repository.ts
|
|
2897
3101
|
var executionEventsChannel = "relay_execution_events";
|
|
2898
3102
|
|
|
2899
3103
|
class DuplicateExecutionEvent extends Schema20.TaggedErrorClass()("DuplicateExecutionEvent", {
|
|
@@ -2956,7 +3160,7 @@ var toEvent = (row) => ({
|
|
|
2956
3160
|
data: row.dataJson,
|
|
2957
3161
|
created_at: fromPgDate(row.createdAt)
|
|
2958
3162
|
});
|
|
2959
|
-
var
|
|
3163
|
+
var mapDatabaseError = (effect) => effect.pipe(Effect10.mapError((error) => new ExecutionEventRepositoryError({ message: String(error) })));
|
|
2960
3164
|
var mapSqlError = (error) => new ExecutionEventRepositoryError({ message: String(error) });
|
|
2961
3165
|
var appendedSignalPayload = (tenantId2, event) => JSON.stringify({ tenantId: tenantId2, executionId: event.execution_id, sequence: event.sequence });
|
|
2962
3166
|
var parseAppendedSignal = (tenantId2, executionId, payload) => {
|
|
@@ -3002,7 +3206,7 @@ var layer10 = Layer10.effect(Service10, Effect10.gen(function* () {
|
|
|
3002
3206
|
const db = yield* Service;
|
|
3003
3207
|
const append = Effect10.fn("ExecutionEventRepository.append")(function* (input) {
|
|
3004
3208
|
const tenantId2 = yield* current;
|
|
3005
|
-
const previousRows = yield*
|
|
3209
|
+
const previousRows = yield* mapDatabaseError(db.select().from(relayExecutionEvents).where(predicate(tenantId2, relayExecutionEvents.tenantId, eq2(relayExecutionEvents.executionId, input.execution_id))).orderBy(desc(relayExecutionEvents.sequence)).limit(1));
|
|
3006
3210
|
const previous = previousRows[0];
|
|
3007
3211
|
if (previous !== undefined && input.sequence === previous.sequence) {
|
|
3008
3212
|
return yield* Effect10.fail(duplicateError(input));
|
|
@@ -3014,11 +3218,11 @@ var layer10 = Layer10.effect(Service10, Effect10.gen(function* () {
|
|
|
3014
3218
|
previous_sequence: previous.sequence
|
|
3015
3219
|
}));
|
|
3016
3220
|
}
|
|
3017
|
-
const duplicateCursorRows = yield*
|
|
3221
|
+
const duplicateCursorRows = yield* mapDatabaseError(db.select().from(relayExecutionEvents).where(predicate(tenantId2, relayExecutionEvents.tenantId, eq2(relayExecutionEvents.cursor, input.cursor))).limit(1));
|
|
3018
3222
|
if (duplicateCursorRows[0] !== undefined) {
|
|
3019
3223
|
return yield* Effect10.fail(duplicateError(input));
|
|
3020
3224
|
}
|
|
3021
|
-
const rows = yield*
|
|
3225
|
+
const rows = yield* mapDatabaseError(db.insert(relayExecutionEvents).values(toRow(tenantId2, input)).returning());
|
|
3022
3226
|
const row = rows[0];
|
|
3023
3227
|
if (row === undefined) {
|
|
3024
3228
|
return yield* Effect10.fail(new ExecutionEventRepositoryError({ message: "Execution event append returned no row" }));
|
|
@@ -3028,49 +3232,49 @@ var layer10 = Layer10.effect(Service10, Effect10.gen(function* () {
|
|
|
3028
3232
|
const list4 = Effect10.fn("ExecutionEventRepository.list")(function* (input) {
|
|
3029
3233
|
const tenantId2 = yield* current;
|
|
3030
3234
|
if (input.afterCursor === undefined) {
|
|
3031
|
-
const rows2 = yield*
|
|
3235
|
+
const rows2 = yield* mapDatabaseError(db.select().from(relayExecutionEvents).where(predicate(tenantId2, relayExecutionEvents.tenantId, eq2(relayExecutionEvents.executionId, input.executionId))).orderBy(asc(relayExecutionEvents.sequence)).limit(listLimit(input)));
|
|
3032
3236
|
return rows2.map(toEvent);
|
|
3033
3237
|
}
|
|
3034
|
-
const cursorRows = yield*
|
|
3238
|
+
const cursorRows = yield* mapDatabaseError(db.select().from(relayExecutionEvents).where(predicate(tenantId2, relayExecutionEvents.tenantId, eq2(relayExecutionEvents.executionId, input.executionId), eq2(relayExecutionEvents.cursor, input.afterCursor))).limit(1));
|
|
3035
3239
|
const cursorRow = cursorRows[0];
|
|
3036
3240
|
if (cursorRow === undefined) {
|
|
3037
3241
|
return yield* Effect10.fail(new ExecutionEventCursorNotFound({ execution_id: input.executionId, cursor: input.afterCursor }));
|
|
3038
3242
|
}
|
|
3039
|
-
const rows = yield*
|
|
3243
|
+
const rows = yield* mapDatabaseError(db.select().from(relayExecutionEvents).where(predicate(tenantId2, relayExecutionEvents.tenantId, eq2(relayExecutionEvents.executionId, input.executionId), gt(relayExecutionEvents.sequence, cursorRow.sequence))).orderBy(asc(relayExecutionEvents.sequence)).limit(listLimit(input)));
|
|
3040
3244
|
return rows.map(toEvent);
|
|
3041
3245
|
});
|
|
3042
3246
|
const findBySequenceOrCursor = Effect10.fn("ExecutionEventRepository.findBySequenceOrCursor")(function* (input) {
|
|
3043
3247
|
const tenantId2 = yield* current;
|
|
3044
|
-
const rows = yield*
|
|
3248
|
+
const rows = yield* mapDatabaseError(db.select().from(relayExecutionEvents).where(predicate(tenantId2, relayExecutionEvents.tenantId, eq2(relayExecutionEvents.executionId, input.executionId), or(eq2(relayExecutionEvents.sequence, input.sequence), eq2(relayExecutionEvents.cursor, input.cursor)))).orderBy(asc(relayExecutionEvents.sequence)).limit(1));
|
|
3045
3249
|
const row = rows[0];
|
|
3046
3250
|
return row === undefined ? Option2.none() : Option2.some(toEvent(row));
|
|
3047
3251
|
});
|
|
3048
3252
|
const findByCursor = Effect10.fn("ExecutionEventRepository.findByCursor")(function* (input) {
|
|
3049
3253
|
const tenantId2 = yield* current;
|
|
3050
|
-
const rows = yield*
|
|
3254
|
+
const rows = yield* mapDatabaseError(db.select().from(relayExecutionEvents).where(predicate(tenantId2, relayExecutionEvents.tenantId, eq2(relayExecutionEvents.executionId, input.executionId), eq2(relayExecutionEvents.cursor, input.cursor))).limit(1));
|
|
3051
3255
|
const row = rows[0];
|
|
3052
3256
|
return row === undefined ? Option2.none() : Option2.some(toEvent(row));
|
|
3053
3257
|
});
|
|
3054
3258
|
const findFirstByTypeAfterSequence = Effect10.fn("ExecutionEventRepository.findFirstByTypeAfterSequence")(function* (input) {
|
|
3055
3259
|
const tenantId2 = yield* current;
|
|
3056
|
-
const rows = yield*
|
|
3260
|
+
const rows = yield* mapDatabaseError(db.select().from(relayExecutionEvents).where(predicate(tenantId2, relayExecutionEvents.tenantId, eq2(relayExecutionEvents.executionId, input.executionId), eq2(relayExecutionEvents.type, input.type), gt(relayExecutionEvents.sequence, input.afterSequence))).orderBy(asc(relayExecutionEvents.sequence)).limit(1));
|
|
3057
3261
|
const row = rows[0];
|
|
3058
3262
|
return row === undefined ? Option2.none() : Option2.some(toEvent(row));
|
|
3059
3263
|
});
|
|
3060
3264
|
const maxSequence = Effect10.fn("ExecutionEventRepository.maxSequence")(function* (executionId) {
|
|
3061
3265
|
const tenantId2 = yield* current;
|
|
3062
|
-
const rows = yield*
|
|
3266
|
+
const rows = yield* mapDatabaseError(db.select({ value: max(relayExecutionEvents.sequence) }).from(relayExecutionEvents).where(predicate(tenantId2, relayExecutionEvents.tenantId, eq2(relayExecutionEvents.executionId, executionId))));
|
|
3063
3267
|
const value = rows[0]?.value;
|
|
3064
3268
|
return value === null || value === undefined ? undefined : value;
|
|
3065
3269
|
});
|
|
3066
3270
|
const sumUsage = Effect10.fn("ExecutionEventRepository.sumUsage")(function* (executionId) {
|
|
3067
3271
|
const tenantId2 = yield* current;
|
|
3068
|
-
const rows = yield*
|
|
3069
|
-
value:
|
|
3272
|
+
const rows = yield* mapDatabaseError(db.select({
|
|
3273
|
+
value: sql3`sum(
|
|
3070
3274
|
coalesce((${relayExecutionEvents.dataJson} ->> 'input_tokens')::bigint, 0)
|
|
3071
3275
|
+ coalesce((${relayExecutionEvents.dataJson} ->> 'output_tokens')::bigint, 0)
|
|
3072
3276
|
)`
|
|
3073
|
-
}).from(relayExecutionEvents).where(predicate(tenantId2, relayExecutionEvents.tenantId,
|
|
3277
|
+
}).from(relayExecutionEvents).where(predicate(tenantId2, relayExecutionEvents.tenantId, eq2(relayExecutionEvents.executionId, executionId), eq2(relayExecutionEvents.type, usageReportedEventType))));
|
|
3074
3278
|
const value = rows[0]?.value;
|
|
3075
3279
|
return value === null || value === undefined ? 0 : Number(value);
|
|
3076
3280
|
});
|
|
@@ -3081,7 +3285,7 @@ var layer10 = Layer10.effect(Service10, Effect10.gen(function* () {
|
|
|
3081
3285
|
const appendedSignals = (executionId) => Stream.unwrap(current.pipe(Effect10.map((tenantId2) => db.$client.listen(executionEventsChannel).pipe(Stream.mapError(mapSqlError), Stream.filterMap(Filter.fromPredicateOption((payload) => parseAppendedSignal(tenantId2, executionId, payload)))))));
|
|
3082
3286
|
const listAfterSequence = Effect10.fn("ExecutionEventRepository.listAfterSequence")(function* (input) {
|
|
3083
3287
|
const tenantId2 = yield* current;
|
|
3084
|
-
const rows = yield*
|
|
3288
|
+
const rows = yield* mapDatabaseError(db.select().from(relayExecutionEvents).where(input.afterSequence === undefined ? predicate(tenantId2, relayExecutionEvents.tenantId, eq2(relayExecutionEvents.executionId, input.executionId)) : predicate(tenantId2, relayExecutionEvents.tenantId, eq2(relayExecutionEvents.executionId, input.executionId), gt(relayExecutionEvents.sequence, input.afterSequence))).orderBy(asc(relayExecutionEvents.sequence)).limit(input.limit));
|
|
3085
3289
|
return rows.map(toEvent);
|
|
3086
3290
|
});
|
|
3087
3291
|
return Service10.of({
|
|
@@ -3203,7 +3407,7 @@ __export(exports_execution_repository, {
|
|
|
3203
3407
|
DuplicateExecution: () => DuplicateExecution
|
|
3204
3408
|
});
|
|
3205
3409
|
import { Context as Context11, Effect as Effect11, Layer as Layer11, Schema as Schema21 } from "effect";
|
|
3206
|
-
import * as
|
|
3410
|
+
import * as SqlClient17 from "effect/unstable/sql/SqlClient";
|
|
3207
3411
|
class ExecutionRepositoryError extends Schema21.TaggedErrorClass()("ExecutionRepositoryError", {
|
|
3208
3412
|
message: Schema21.String
|
|
3209
3413
|
}) {
|
|
@@ -3283,8 +3487,8 @@ var toRecord5 = (row) => {
|
|
|
3283
3487
|
updatedAt: fromDbTimestamp(row.updated_at)
|
|
3284
3488
|
};
|
|
3285
3489
|
};
|
|
3286
|
-
var
|
|
3287
|
-
var
|
|
3490
|
+
var toRepositoryError7 = (error) => new ExecutionRepositoryError({ message: String(error) });
|
|
3491
|
+
var decodeRow6 = (row) => Schema21.decodeUnknownEffect(ExecutionRow)(row).pipe(Effect11.mapError(toRepositoryError7));
|
|
3288
3492
|
var maxListLimit2 = 100;
|
|
3289
3493
|
var defaultListLimit = 50;
|
|
3290
3494
|
var listLimit2 = (input) => Math.min(Math.max(input.limit ?? defaultListLimit, 1), maxListLimit2);
|
|
@@ -3295,8 +3499,8 @@ var nextCursorOf = (records, fetched, limit) => {
|
|
|
3295
3499
|
var compareDesc = (left, right) => right.updatedAt - left.updatedAt || (left.id < right.id ? 1 : left.id > right.id ? -1 : 0);
|
|
3296
3500
|
var afterCursor = (record2, cursor) => cursor === undefined || record2.updatedAt < cursor.updatedAt || record2.updatedAt === cursor.updatedAt && record2.id < cursor.id;
|
|
3297
3501
|
var layer11 = Layer11.effect(Service11, Effect11.gen(function* () {
|
|
3298
|
-
const
|
|
3299
|
-
const columns =
|
|
3502
|
+
const sql4 = yield* SqlClient17.SqlClient;
|
|
3503
|
+
const columns = sql4.literal([
|
|
3300
3504
|
"id",
|
|
3301
3505
|
"root_address_id",
|
|
3302
3506
|
"session_id",
|
|
@@ -3309,12 +3513,12 @@ var layer11 = Layer11.effect(Service11, Effect11.gen(function* () {
|
|
|
3309
3513
|
"created_at",
|
|
3310
3514
|
"updated_at"
|
|
3311
3515
|
].join(", "));
|
|
3312
|
-
const selectByKey = (tenantId2, id2) =>
|
|
3516
|
+
const selectByKey = (tenantId2, id2) => sql4`
|
|
3313
3517
|
SELECT ${columns}
|
|
3314
3518
|
FROM relay_executions
|
|
3315
3519
|
WHERE tenant_id = ${tenantId2} AND id = ${id2}
|
|
3316
3520
|
`;
|
|
3317
|
-
const insertStatement = (tenantId2, input) =>
|
|
3521
|
+
const insertStatement = (tenantId2, input) => sql4`
|
|
3318
3522
|
INSERT INTO relay_executions (
|
|
3319
3523
|
tenant_id, ${columns}
|
|
3320
3524
|
)
|
|
@@ -3329,48 +3533,48 @@ var layer11 = Layer11.effect(Service11, Effect11.gen(function* () {
|
|
|
3329
3533
|
${input.agentDefinitionSnapshot === undefined ? null : encodeJson(input.agentDefinitionSnapshot)},
|
|
3330
3534
|
${encodeJson(input.agentDefinitionToolInputSchemaDigests ?? {})},
|
|
3331
3535
|
${encodeJson(metadata4(input.metadata))},
|
|
3332
|
-
${timestampParam(
|
|
3333
|
-
${timestampParam(
|
|
3536
|
+
${timestampParam(sql4, input.createdAt)},
|
|
3537
|
+
${timestampParam(sql4, input.createdAt)}
|
|
3334
3538
|
)
|
|
3335
3539
|
`;
|
|
3336
|
-
const insertExecution =
|
|
3337
|
-
mysql: () => (tenantId2, input) =>
|
|
3540
|
+
const insertExecution = sql4.onDialectOrElse({
|
|
3541
|
+
mysql: () => (tenantId2, input) => sql4.withTransaction(Effect11.gen(function* () {
|
|
3338
3542
|
yield* insertStatement(tenantId2, input);
|
|
3339
3543
|
return yield* selectByKey(tenantId2, input.id);
|
|
3340
3544
|
})),
|
|
3341
|
-
orElse: () => (tenantId2, input) =>
|
|
3545
|
+
orElse: () => (tenantId2, input) => sql4`
|
|
3342
3546
|
${insertStatement(tenantId2, input)}
|
|
3343
3547
|
RETURNING ${columns}
|
|
3344
3548
|
`
|
|
3345
3549
|
});
|
|
3346
|
-
const updateStatement = (tenantId2, input) =>
|
|
3550
|
+
const updateStatement = (tenantId2, input) => sql4`
|
|
3347
3551
|
UPDATE relay_executions
|
|
3348
3552
|
SET status = ${input.status},
|
|
3349
3553
|
metadata_json = ${encodeJson(metadata4(input.metadata))},
|
|
3350
|
-
updated_at = ${timestampParam(
|
|
3554
|
+
updated_at = ${timestampParam(sql4, input.updatedAt)}
|
|
3351
3555
|
WHERE tenant_id = ${tenantId2} AND id = ${input.id}
|
|
3352
3556
|
`;
|
|
3353
|
-
const updateExecution =
|
|
3354
|
-
mysql: () => (tenantId2, input) =>
|
|
3557
|
+
const updateExecution = sql4.onDialectOrElse({
|
|
3558
|
+
mysql: () => (tenantId2, input) => sql4.withTransaction(Effect11.gen(function* () {
|
|
3355
3559
|
yield* updateStatement(tenantId2, input);
|
|
3356
3560
|
return yield* selectByKey(tenantId2, input.id);
|
|
3357
3561
|
})),
|
|
3358
|
-
orElse: () => (tenantId2, input) =>
|
|
3562
|
+
orElse: () => (tenantId2, input) => sql4`
|
|
3359
3563
|
${updateStatement(tenantId2, input)}
|
|
3360
3564
|
RETURNING ${columns}
|
|
3361
3565
|
`
|
|
3362
3566
|
});
|
|
3363
3567
|
const listConditions = (tenantId2, input) => [
|
|
3364
|
-
|
|
3365
|
-
...input.rootAddressId === undefined ? [] : [
|
|
3366
|
-
...input.sessionId === undefined ? [] : [
|
|
3367
|
-
...input.status === undefined ? [] : [
|
|
3568
|
+
sql4`tenant_id = ${tenantId2}`,
|
|
3569
|
+
...input.rootAddressId === undefined ? [] : [sql4`root_address_id = ${input.rootAddressId}`],
|
|
3570
|
+
...input.sessionId === undefined ? [] : [sql4`session_id = ${input.sessionId}`],
|
|
3571
|
+
...input.status === undefined ? [] : [sql4`status = ${input.status}`],
|
|
3368
3572
|
...input.cursor === undefined ? [] : [
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3573
|
+
sql4.or([
|
|
3574
|
+
sql4`updated_at < ${timestampParam(sql4, input.cursor.updatedAt)}`,
|
|
3575
|
+
sql4.and([
|
|
3576
|
+
sql4`updated_at = ${timestampParam(sql4, input.cursor.updatedAt)}`,
|
|
3577
|
+
sql4`id < ${input.cursor.id}`
|
|
3374
3578
|
])
|
|
3375
3579
|
])
|
|
3376
3580
|
]
|
|
@@ -3378,43 +3582,43 @@ var layer11 = Layer11.effect(Service11, Effect11.gen(function* () {
|
|
|
3378
3582
|
const create2 = Effect11.fn("ExecutionRepository.create")(function* (input) {
|
|
3379
3583
|
const tenantId2 = yield* current;
|
|
3380
3584
|
yield* validateCreateInput(input);
|
|
3381
|
-
const existing = yield* selectByKey(tenantId2, input.id).pipe(Effect11.mapError(
|
|
3585
|
+
const existing = yield* selectByKey(tenantId2, input.id).pipe(Effect11.mapError(toRepositoryError7));
|
|
3382
3586
|
if (existing[0] !== undefined)
|
|
3383
3587
|
return yield* Effect11.fail(new DuplicateExecution({ id: input.id }));
|
|
3384
|
-
const rows = yield* insertExecution(tenantId2, input).pipe(Effect11.mapError(
|
|
3588
|
+
const rows = yield* insertExecution(tenantId2, input).pipe(Effect11.mapError(toRepositoryError7));
|
|
3385
3589
|
const row = rows[0];
|
|
3386
3590
|
if (row === undefined) {
|
|
3387
3591
|
return yield* Effect11.fail(new ExecutionRepositoryError({ message: "Execution insert returned no row" }));
|
|
3388
3592
|
}
|
|
3389
|
-
return toRecord5(yield*
|
|
3593
|
+
return toRecord5(yield* decodeRow6(row));
|
|
3390
3594
|
});
|
|
3391
3595
|
const get5 = Effect11.fn("ExecutionRepository.get")(function* (id2) {
|
|
3392
3596
|
const tenantId2 = yield* current;
|
|
3393
|
-
const rows = yield* selectByKey(tenantId2, id2).pipe(Effect11.mapError(
|
|
3394
|
-
return rows[0] === undefined ? undefined : toRecord5(yield*
|
|
3597
|
+
const rows = yield* selectByKey(tenantId2, id2).pipe(Effect11.mapError(toRepositoryError7));
|
|
3598
|
+
return rows[0] === undefined ? undefined : toRecord5(yield* decodeRow6(rows[0]));
|
|
3395
3599
|
});
|
|
3396
3600
|
const list5 = Effect11.fn("ExecutionRepository.list")(function* (input) {
|
|
3397
3601
|
const tenantId2 = yield* current;
|
|
3398
3602
|
const limit = listLimit2(input);
|
|
3399
|
-
const rows = yield*
|
|
3603
|
+
const rows = yield* sql4`
|
|
3400
3604
|
SELECT ${columns}
|
|
3401
3605
|
FROM relay_executions
|
|
3402
|
-
WHERE ${
|
|
3606
|
+
WHERE ${sql4.and(listConditions(tenantId2, input))}
|
|
3403
3607
|
ORDER BY updated_at DESC, id DESC
|
|
3404
|
-
LIMIT ${
|
|
3405
|
-
`.pipe(Effect11.mapError(
|
|
3406
|
-
const decoded = yield* Effect11.forEach(rows.slice(0, limit),
|
|
3608
|
+
LIMIT ${sql4.literal(String(limit + 1))}
|
|
3609
|
+
`.pipe(Effect11.mapError(toRepositoryError7));
|
|
3610
|
+
const decoded = yield* Effect11.forEach(rows.slice(0, limit), decodeRow6);
|
|
3407
3611
|
const records = decoded.map(toRecord5);
|
|
3408
3612
|
const nextCursor = nextCursorOf(records, rows.length, limit);
|
|
3409
3613
|
return nextCursor === undefined ? { records } : { records, nextCursor };
|
|
3410
3614
|
});
|
|
3411
3615
|
const transition = Effect11.fn("ExecutionRepository.transition")(function* (input) {
|
|
3412
3616
|
const tenantId2 = yield* current;
|
|
3413
|
-
const rows = yield* updateExecution(tenantId2, input).pipe(Effect11.mapError(
|
|
3617
|
+
const rows = yield* updateExecution(tenantId2, input).pipe(Effect11.mapError(toRepositoryError7));
|
|
3414
3618
|
const row = rows[0];
|
|
3415
3619
|
if (row === undefined)
|
|
3416
3620
|
return yield* Effect11.fail(new ExecutionNotFound({ id: input.id }));
|
|
3417
|
-
return toRecord5(yield*
|
|
3621
|
+
return toRecord5(yield* decodeRow6(row));
|
|
3418
3622
|
});
|
|
3419
3623
|
return Service11.of({ create: create2, get: get5, list: list5, transition });
|
|
3420
3624
|
}));
|
|
@@ -3489,7 +3693,7 @@ var transition = Effect11.fn("ExecutionRepository.transition.call")(function* (i
|
|
|
3489
3693
|
return yield* repository.transition(input);
|
|
3490
3694
|
});
|
|
3491
3695
|
// ../store-sql/src/idempotency/idempotency-repository.ts
|
|
3492
|
-
import { eq as
|
|
3696
|
+
import { eq as eq3, sql as sql4 } from "drizzle-orm";
|
|
3493
3697
|
import { Context as Context12, Effect as Effect12, HashMap, Layer as Layer12, Option as Option3, Ref, Schema as Schema22, Semaphore } from "effect";
|
|
3494
3698
|
class IdempotencyRepositoryError extends Schema22.TaggedErrorClass()("IdempotencyRepositoryError", {
|
|
3495
3699
|
message: Schema22.String
|
|
@@ -3512,7 +3716,7 @@ var toRecord6 = (row) => {
|
|
|
3512
3716
|
...expiresAt === undefined ? {} : { expiresAt }
|
|
3513
3717
|
};
|
|
3514
3718
|
};
|
|
3515
|
-
var
|
|
3719
|
+
var toInsert = (tenantId2, input, result) => ({
|
|
3516
3720
|
tenantId: tenantId2,
|
|
3517
3721
|
id: operationId(input),
|
|
3518
3722
|
scope: input.scope,
|
|
@@ -3529,17 +3733,17 @@ var layer12 = Layer12.effect(Service12, Effect12.gen(function* () {
|
|
|
3529
3733
|
const runOnce = (input, create3) => Effect12.gen(function* () {
|
|
3530
3734
|
const tenantId2 = yield* current;
|
|
3531
3735
|
return yield* db.transaction((tx) => Effect12.gen(function* () {
|
|
3532
|
-
yield* tx.execute(
|
|
3533
|
-
const existingRows = yield* tx.select().from(relayIdempotencyKeys).where(predicate(tenantId2, relayIdempotencyKeys.tenantId,
|
|
3736
|
+
yield* tx.execute(sql4`select pg_advisory_xact_lock(hashtextextended(${`${tenantId2}:${operationId(input)}`}, 0))`);
|
|
3737
|
+
const existingRows = yield* tx.select().from(relayIdempotencyKeys).where(predicate(tenantId2, relayIdempotencyKeys.tenantId, eq3(relayIdempotencyKeys.scope, input.scope), eq3(relayIdempotencyKeys.operation, input.operation), eq3(relayIdempotencyKeys.key, input.key))).limit(1);
|
|
3534
3738
|
const existing = existingRows[0];
|
|
3535
3739
|
if (existing !== undefined)
|
|
3536
3740
|
return { replayed: true, record: toRecord6(existing) };
|
|
3537
3741
|
const result = yield* create3;
|
|
3538
|
-
const rows = yield* tx.insert(relayIdempotencyKeys).values(
|
|
3742
|
+
const rows = yield* tx.insert(relayIdempotencyKeys).values(toInsert(tenantId2, input, result)).onConflictDoNothing().returning();
|
|
3539
3743
|
const row = rows[0];
|
|
3540
3744
|
if (row !== undefined)
|
|
3541
3745
|
return { replayed: false, record: toRecord6(row) };
|
|
3542
|
-
const winnerRows = yield* tx.select().from(relayIdempotencyKeys).where(predicate(tenantId2, relayIdempotencyKeys.tenantId,
|
|
3746
|
+
const winnerRows = yield* tx.select().from(relayIdempotencyKeys).where(predicate(tenantId2, relayIdempotencyKeys.tenantId, eq3(relayIdempotencyKeys.scope, input.scope), eq3(relayIdempotencyKeys.operation, input.operation), eq3(relayIdempotencyKeys.key, input.key))).limit(1);
|
|
3543
3747
|
const winner = winnerRows[0];
|
|
3544
3748
|
if (winner === undefined) {
|
|
3545
3749
|
return yield* Effect12.fail(new IdempotencyRepositoryError({ message: "Idempotency insert returned no row" }));
|
|
@@ -3589,7 +3793,7 @@ __export(exports_memory_repository, {
|
|
|
3589
3793
|
Service: () => Service13,
|
|
3590
3794
|
MemoryRepositoryError: () => MemoryRepositoryError
|
|
3591
3795
|
});
|
|
3592
|
-
import { sql as
|
|
3796
|
+
import { sql as sql5 } from "drizzle-orm";
|
|
3593
3797
|
import { Context as Context13, Effect as Effect13, Layer as Layer13, Ref as Ref2, Schema as Schema23 } from "effect";
|
|
3594
3798
|
class MemoryRepositoryError extends Schema23.TaggedErrorClass()("MemoryRepositoryError", {
|
|
3595
3799
|
message: Schema23.String
|
|
@@ -3616,7 +3820,7 @@ var queryRowToRecord = (row) => ({
|
|
|
3616
3820
|
metadata: row.metadataJson,
|
|
3617
3821
|
createdAt: fromPgDate(row.createdAt)
|
|
3618
3822
|
});
|
|
3619
|
-
var
|
|
3823
|
+
var mapDatabaseError2 = (effect) => effect.pipe(Effect13.mapError((error) => new MemoryRepositoryError({ message: String(error) })));
|
|
3620
3824
|
var parsePgFloatArray = (value) => {
|
|
3621
3825
|
const body = value.startsWith("{") && value.endsWith("}") ? value.slice(1, -1) : value;
|
|
3622
3826
|
if (body.length === 0)
|
|
@@ -3660,7 +3864,7 @@ var layer13 = Layer13.effect(Service13, Effect13.gen(function* () {
|
|
|
3660
3864
|
const upsert2 = Effect13.fn("MemoryRepository.upsert")(function* (input) {
|
|
3661
3865
|
const tenantId2 = yield* current;
|
|
3662
3866
|
yield* validateVector("embedding", input.embedding);
|
|
3663
|
-
const rows = yield*
|
|
3867
|
+
const rows = yield* mapDatabaseError2(db.insert(relayMemoryRecords).values({
|
|
3664
3868
|
tenantId: tenantId2,
|
|
3665
3869
|
id: input.id,
|
|
3666
3870
|
agent: input.agent,
|
|
@@ -3690,8 +3894,8 @@ var layer13 = Layer13.effect(Service13, Effect13.gen(function* () {
|
|
|
3690
3894
|
yield* validateVector("query embedding", input.embedding);
|
|
3691
3895
|
if (input.topK <= 0)
|
|
3692
3896
|
return [];
|
|
3693
|
-
const queryEmbeddingSql =
|
|
3694
|
-
const rows = yield*
|
|
3897
|
+
const queryEmbeddingSql = sql5`array[${sql5.join(input.embedding.map((value) => sql5`${value}`), sql5`, `)}]::double precision[]`;
|
|
3898
|
+
const rows = yield* mapDatabaseError2(db.execute(sql5`
|
|
3695
3899
|
with query_embedding as (
|
|
3696
3900
|
select ${queryEmbeddingSql} as embedding
|
|
3697
3901
|
),
|
|
@@ -3829,10 +4033,11 @@ __export(exports_permission_rule_repository, {
|
|
|
3829
4033
|
list: () => list6,
|
|
3830
4034
|
layer: () => layer14,
|
|
3831
4035
|
Service: () => Service14,
|
|
4036
|
+
PermissionRuleRow: () => PermissionRuleRow,
|
|
3832
4037
|
PermissionRuleRepositoryError: () => PermissionRuleRepositoryError
|
|
3833
4038
|
});
|
|
3834
|
-
import { asc as asc6, eq as eq8 } from "drizzle-orm";
|
|
3835
4039
|
import { Context as Context14, Effect as Effect14, Layer as Layer14, Schema as Schema24 } from "effect";
|
|
4040
|
+
import * as SqlClient19 from "effect/unstable/sql/SqlClient";
|
|
3836
4041
|
class PermissionRuleRepositoryError extends Schema24.TaggedErrorClass()("PermissionRuleRepositoryError", {
|
|
3837
4042
|
message: Schema24.String
|
|
3838
4043
|
}) {
|
|
@@ -3840,47 +4045,71 @@ class PermissionRuleRepositoryError extends Schema24.TaggedErrorClass()("Permiss
|
|
|
3840
4045
|
|
|
3841
4046
|
class Service14 extends Context14.Service()("@relayfx/store-sql/PermissionRuleRepository") {
|
|
3842
4047
|
}
|
|
4048
|
+
var PermissionRuleRow = Schema24.Struct({
|
|
4049
|
+
agent: Schema24.String,
|
|
4050
|
+
scope: Schema24.String,
|
|
4051
|
+
rule_json: Schema24.Unknown,
|
|
4052
|
+
created_at: Schema24.Union([Schema24.Date, Schema24.String, Schema24.Number])
|
|
4053
|
+
}).annotate({ identifier: "Relay.PermissionRule.Row" });
|
|
3843
4054
|
var toRecord8 = (row) => ({
|
|
3844
4055
|
agent: row.agent,
|
|
3845
4056
|
scope: row.scope,
|
|
3846
|
-
rule: row.
|
|
3847
|
-
createdAt:
|
|
4057
|
+
rule: decodeJson(row.rule_json),
|
|
4058
|
+
createdAt: fromDbTimestamp(row.created_at)
|
|
3848
4059
|
});
|
|
3849
|
-
var
|
|
4060
|
+
var toRepositoryError8 = (error) => new PermissionRuleRepositoryError({ message: String(error) });
|
|
4061
|
+
var decodeRow7 = (row) => Schema24.decodeUnknownEffect(PermissionRuleRow)(row).pipe(Effect14.mapError(toRepositoryError8));
|
|
3850
4062
|
var memoryKey = (agent, scope, pattern) => `${agent}\x00${scope}\x00${pattern}`;
|
|
3851
4063
|
var layer14 = Layer14.effect(Service14, Effect14.gen(function* () {
|
|
3852
|
-
const
|
|
4064
|
+
const sql6 = yield* SqlClient19.SqlClient;
|
|
4065
|
+
const selectByKey = (tenantId2, input) => sql6`
|
|
4066
|
+
SELECT agent, scope, rule_json, created_at
|
|
4067
|
+
FROM relay_permission_rules
|
|
4068
|
+
WHERE tenant_id = ${tenantId2}
|
|
4069
|
+
AND agent = ${input.agent}
|
|
4070
|
+
AND scope = ${input.scope}
|
|
4071
|
+
AND pattern = ${input.rule.pattern}
|
|
4072
|
+
`;
|
|
4073
|
+
const upsert3 = sql6.onDialectOrElse({
|
|
4074
|
+
mysql: () => (tenantId2, input) => sql6.withTransaction(Effect14.gen(function* () {
|
|
4075
|
+
yield* sql6`
|
|
4076
|
+
INSERT INTO relay_permission_rules (tenant_id, agent, scope, pattern, rule_json, created_at)
|
|
4077
|
+
VALUES (${tenantId2}, ${input.agent}, ${input.scope}, ${input.rule.pattern}, ${encodeJson(input.rule)}, ${timestampParam(sql6, input.createdAt)})
|
|
4078
|
+
ON DUPLICATE KEY UPDATE
|
|
4079
|
+
rule_json = VALUES(rule_json),
|
|
4080
|
+
created_at = VALUES(created_at)
|
|
4081
|
+
`;
|
|
4082
|
+
return yield* selectByKey(tenantId2, input);
|
|
4083
|
+
})),
|
|
4084
|
+
orElse: () => (tenantId2, input) => sql6`
|
|
4085
|
+
INSERT INTO relay_permission_rules (tenant_id, agent, scope, pattern, rule_json, created_at)
|
|
4086
|
+
VALUES (${tenantId2}, ${input.agent}, ${input.scope}, ${input.rule.pattern}, ${encodeJson(input.rule)}, ${timestampParam(sql6, input.createdAt)})
|
|
4087
|
+
ON CONFLICT (tenant_id, agent, scope, pattern) DO UPDATE SET
|
|
4088
|
+
rule_json = excluded.rule_json,
|
|
4089
|
+
created_at = excluded.created_at
|
|
4090
|
+
RETURNING agent, scope, rule_json, created_at
|
|
4091
|
+
`
|
|
4092
|
+
});
|
|
3853
4093
|
const remember = Effect14.fn("PermissionRuleRepository.remember")(function* (input) {
|
|
3854
4094
|
const tenantId2 = yield* current;
|
|
3855
|
-
const rows = yield*
|
|
3856
|
-
tenantId: tenantId2,
|
|
3857
|
-
agent: input.agent,
|
|
3858
|
-
scope: input.scope,
|
|
3859
|
-
pattern: input.rule.pattern,
|
|
3860
|
-
ruleJson: input.rule,
|
|
3861
|
-
createdAt: toPgDate(input.createdAt)
|
|
3862
|
-
}).onConflictDoUpdate({
|
|
3863
|
-
target: [
|
|
3864
|
-
relayPermissionRules.tenantId,
|
|
3865
|
-
relayPermissionRules.agent,
|
|
3866
|
-
relayPermissionRules.scope,
|
|
3867
|
-
relayPermissionRules.pattern
|
|
3868
|
-
],
|
|
3869
|
-
set: {
|
|
3870
|
-
ruleJson: input.rule,
|
|
3871
|
-
createdAt: toPgDate(input.createdAt)
|
|
3872
|
-
}
|
|
3873
|
-
}).returning());
|
|
4095
|
+
const rows = yield* upsert3(tenantId2, input).pipe(Effect14.mapError(toRepositoryError8));
|
|
3874
4096
|
const row = rows[0];
|
|
3875
4097
|
if (row === undefined) {
|
|
3876
4098
|
return yield* Effect14.fail(new PermissionRuleRepositoryError({ message: "Permission rule upsert returned no row" }));
|
|
3877
4099
|
}
|
|
3878
|
-
return toRecord8(row);
|
|
4100
|
+
return toRecord8(yield* decodeRow7(row));
|
|
3879
4101
|
});
|
|
3880
4102
|
const list6 = Effect14.fn("PermissionRuleRepository.list")(function* (input) {
|
|
3881
4103
|
const tenantId2 = yield* current;
|
|
3882
|
-
const rows = yield*
|
|
3883
|
-
|
|
4104
|
+
const rows = yield* sql6`
|
|
4105
|
+
SELECT agent, scope, rule_json, created_at
|
|
4106
|
+
FROM relay_permission_rules
|
|
4107
|
+
WHERE tenant_id = ${tenantId2}
|
|
4108
|
+
AND agent = ${input.agent}
|
|
4109
|
+
AND scope = ${input.scope}
|
|
4110
|
+
ORDER BY created_at ASC, pattern ASC
|
|
4111
|
+
`.pipe(Effect14.mapError(toRepositoryError8));
|
|
4112
|
+
return yield* Effect14.forEach(rows, (row) => decodeRow7(row).pipe(Effect14.map(toRecord8)));
|
|
3884
4113
|
});
|
|
3885
4114
|
return Service14.of({ remember, list: list6 });
|
|
3886
4115
|
}));
|
|
@@ -3920,10 +4149,11 @@ __export(exports_context_epoch_repository, {
|
|
|
3920
4149
|
layer: () => layer15,
|
|
3921
4150
|
get: () => get6,
|
|
3922
4151
|
Service: () => Service15,
|
|
4152
|
+
ContextEpochRow: () => ContextEpochRow,
|
|
3923
4153
|
ContextEpochRepositoryError: () => ContextEpochRepositoryError
|
|
3924
4154
|
});
|
|
3925
|
-
import { eq as eq9 } from "drizzle-orm";
|
|
3926
4155
|
import { Context as Context15, Effect as Effect15, Layer as Layer15, Schema as Schema25 } from "effect";
|
|
4156
|
+
import * as SqlClient21 from "effect/unstable/sql/SqlClient";
|
|
3927
4157
|
class ContextEpochRepositoryError extends Schema25.TaggedErrorClass()("ContextEpochRepositoryError", {
|
|
3928
4158
|
message: Schema25.String
|
|
3929
4159
|
}) {
|
|
@@ -3931,37 +4161,60 @@ class ContextEpochRepositoryError extends Schema25.TaggedErrorClass()("ContextEp
|
|
|
3931
4161
|
|
|
3932
4162
|
class Service15 extends Context15.Service()("@relayfx/store-sql/ContextEpochRepository") {
|
|
3933
4163
|
}
|
|
4164
|
+
var ContextEpochRow = Schema25.Struct({
|
|
4165
|
+
execution_id: Schema25.String,
|
|
4166
|
+
baseline: Schema25.String,
|
|
4167
|
+
dynamic_source_ids_json: Schema25.Unknown,
|
|
4168
|
+
opened_at: Schema25.Union([Schema25.Date, Schema25.String, Schema25.Number])
|
|
4169
|
+
}).annotate({ identifier: "Relay.ContextEpoch.Row" });
|
|
3934
4170
|
var toRecord9 = (row) => ({
|
|
3935
|
-
executionId: row.
|
|
4171
|
+
executionId: exports_ids_schema.ExecutionId.make(row.execution_id),
|
|
3936
4172
|
baseline: row.baseline,
|
|
3937
|
-
dynamicSourceIds: row.
|
|
3938
|
-
openedAt:
|
|
4173
|
+
dynamicSourceIds: decodeJson(row.dynamic_source_ids_json),
|
|
4174
|
+
openedAt: fromDbTimestamp(row.opened_at)
|
|
3939
4175
|
});
|
|
3940
|
-
var
|
|
4176
|
+
var toRepositoryError9 = (error) => new ContextEpochRepositoryError({ message: String(error) });
|
|
4177
|
+
var decodeRow8 = (row) => Schema25.decodeUnknownEffect(ContextEpochRow)(row).pipe(Effect15.mapError(toRepositoryError9));
|
|
3941
4178
|
var sameEpoch = (record2, input) => record2.baseline === input.baseline && JSON.stringify(record2.dynamicSourceIds) === JSON.stringify(input.dynamicSourceIds);
|
|
3942
4179
|
var conflict2 = (executionId) => new ContextEpochRepositoryError({ message: `Context epoch already exists with different payload: ${executionId}` });
|
|
3943
4180
|
var cloneRecord5 = (record2) => structuredClone(record2);
|
|
3944
4181
|
var layer15 = Layer15.effect(Service15, Effect15.gen(function* () {
|
|
3945
|
-
const
|
|
4182
|
+
const sql6 = yield* SqlClient21.SqlClient;
|
|
4183
|
+
const selectByKey = (tenantId2, executionId) => sql6`
|
|
4184
|
+
SELECT execution_id, baseline, dynamic_source_ids_json, opened_at
|
|
4185
|
+
FROM relay_execution_context_epochs
|
|
4186
|
+
WHERE tenant_id = ${tenantId2} AND execution_id = ${executionId}
|
|
4187
|
+
`;
|
|
4188
|
+
const insertIfAbsent = sql6.onDialectOrElse({
|
|
4189
|
+
mysql: () => (tenantId2, input) => sql6.withTransaction(Effect15.gen(function* () {
|
|
4190
|
+
yield* sql6`
|
|
4191
|
+
INSERT IGNORE INTO relay_execution_context_epochs (tenant_id, execution_id, baseline, dynamic_source_ids_json, opened_at)
|
|
4192
|
+
VALUES (${tenantId2}, ${input.executionId}, ${input.baseline}, ${encodeJson([...input.dynamicSourceIds])}, ${timestampParam(sql6, input.openedAt)})
|
|
4193
|
+
`;
|
|
4194
|
+
return yield* selectByKey(tenantId2, input.executionId);
|
|
4195
|
+
})),
|
|
4196
|
+
orElse: () => (tenantId2, input) => sql6`
|
|
4197
|
+
INSERT INTO relay_execution_context_epochs (tenant_id, execution_id, baseline, dynamic_source_ids_json, opened_at)
|
|
4198
|
+
VALUES (${tenantId2}, ${input.executionId}, ${input.baseline}, ${encodeJson([...input.dynamicSourceIds])}, ${timestampParam(sql6, input.openedAt)})
|
|
4199
|
+
ON CONFLICT (tenant_id, execution_id) DO NOTHING
|
|
4200
|
+
RETURNING execution_id, baseline, dynamic_source_ids_json, opened_at
|
|
4201
|
+
`
|
|
4202
|
+
});
|
|
3946
4203
|
const get6 = Effect15.fn("ContextEpochRepository.get")(function* (executionId) {
|
|
3947
4204
|
const tenantId2 = yield* current;
|
|
3948
|
-
const rows = yield*
|
|
3949
|
-
return rows[0] === undefined ? undefined : toRecord9(rows[0]);
|
|
4205
|
+
const rows = yield* selectByKey(tenantId2, executionId).pipe(Effect15.mapError(toRepositoryError9));
|
|
4206
|
+
return rows[0] === undefined ? undefined : toRecord9(yield* decodeRow8(rows[0]));
|
|
3950
4207
|
});
|
|
3951
4208
|
const save2 = Effect15.fn("ContextEpochRepository.save")(function* (input) {
|
|
3952
4209
|
const tenantId2 = yield* current;
|
|
3953
|
-
const rows = yield*
|
|
3954
|
-
tenantId: tenantId2,
|
|
3955
|
-
executionId: input.executionId,
|
|
3956
|
-
baseline: input.baseline,
|
|
3957
|
-
dynamicSourceIdsJson: [...input.dynamicSourceIds],
|
|
3958
|
-
openedAt: toPgDate(input.openedAt)
|
|
3959
|
-
}).onConflictDoNothing({
|
|
3960
|
-
target: [relayExecutionContextEpochs.tenantId, relayExecutionContextEpochs.executionId]
|
|
3961
|
-
}).returning());
|
|
4210
|
+
const rows = yield* insertIfAbsent(tenantId2, input).pipe(Effect15.mapError(toRepositoryError9));
|
|
3962
4211
|
const row = rows[0];
|
|
3963
|
-
if (row !== undefined)
|
|
3964
|
-
|
|
4212
|
+
if (row !== undefined) {
|
|
4213
|
+
const record2 = toRecord9(yield* decodeRow8(row));
|
|
4214
|
+
if (!sameEpoch(record2, input))
|
|
4215
|
+
return yield* Effect15.fail(conflict2(input.executionId));
|
|
4216
|
+
return record2;
|
|
4217
|
+
}
|
|
3965
4218
|
const existing = yield* get6(input.executionId);
|
|
3966
4219
|
if (existing === undefined) {
|
|
3967
4220
|
return yield* Effect15.fail(new ContextEpochRepositoryError({ message: "Context epoch insert returned no row" }));
|
|
@@ -4024,7 +4277,7 @@ __export(exports_schedule_repository, {
|
|
|
4024
4277
|
ScheduleNotFound: () => ScheduleNotFound,
|
|
4025
4278
|
ScheduleClaimMismatch: () => ScheduleClaimMismatch
|
|
4026
4279
|
});
|
|
4027
|
-
import { and as and2, asc as
|
|
4280
|
+
import { and as and2, asc as asc2, eq as eq4, inArray, lte, or as or2, sql as sql6 } from "drizzle-orm";
|
|
4028
4281
|
import { Context as Context16, Effect as Effect16, Layer as Layer16, Schema as Schema26 } from "effect";
|
|
4029
4282
|
class ScheduleRepositoryError extends Schema26.TaggedErrorClass()("ScheduleRepositoryError", {
|
|
4030
4283
|
message: Schema26.String
|
|
@@ -4060,7 +4313,7 @@ var validationError = (input) => {
|
|
|
4060
4313
|
}
|
|
4061
4314
|
return;
|
|
4062
4315
|
};
|
|
4063
|
-
var
|
|
4316
|
+
var toInsert2 = (tenantId2, input) => ({
|
|
4064
4317
|
tenantId: tenantId2,
|
|
4065
4318
|
id: input.id,
|
|
4066
4319
|
kind: input.kind,
|
|
@@ -4091,12 +4344,12 @@ var toRecord10 = (row) => ({
|
|
|
4091
4344
|
created_at: fromPgDate(row.createdAt),
|
|
4092
4345
|
updated_at: fromPgDate(row.updatedAt)
|
|
4093
4346
|
});
|
|
4094
|
-
var
|
|
4347
|
+
var mapDatabaseError3 = (effect) => effect.pipe(Effect16.mapError((error) => new ScheduleRepositoryError({ message: String(error) })));
|
|
4095
4348
|
var cancellableStates = new Set(["active", "claimed"]);
|
|
4096
4349
|
var layer16 = Layer16.effect(Service16, Effect16.gen(function* () {
|
|
4097
4350
|
const db = yield* Service;
|
|
4098
|
-
const getRow = (tenantId2, id2) =>
|
|
4099
|
-
const getByIdempotencyKey = (tenantId2, key2) =>
|
|
4351
|
+
const getRow = (tenantId2, id2) => mapDatabaseError3(db.select().from(relaySchedules).where(predicate(tenantId2, relaySchedules.tenantId, eq4(relaySchedules.id, id2))).limit(1)).pipe(Effect16.map((rows) => rows[0]));
|
|
4352
|
+
const getByIdempotencyKey = (tenantId2, key2) => mapDatabaseError3(db.select().from(relaySchedules).where(predicate(tenantId2, relaySchedules.tenantId, eq4(relaySchedules.idempotencyKey, key2))).limit(1)).pipe(Effect16.map((rows) => rows[0]));
|
|
4100
4353
|
const create3 = Effect16.fn("ScheduleRepository.create")(function* (input) {
|
|
4101
4354
|
const tenantId2 = yield* current;
|
|
4102
4355
|
const invalid = validationError(input);
|
|
@@ -4107,7 +4360,7 @@ var layer16 = Layer16.effect(Service16, Effect16.gen(function* () {
|
|
|
4107
4360
|
if (existing !== undefined)
|
|
4108
4361
|
return toRecord10(existing);
|
|
4109
4362
|
}
|
|
4110
|
-
const rows = yield*
|
|
4363
|
+
const rows = yield* mapDatabaseError3(db.insert(relaySchedules).values(toInsert2(tenantId2, input)).returning());
|
|
4111
4364
|
const row = rows[0];
|
|
4112
4365
|
if (row === undefined) {
|
|
4113
4366
|
return yield* Effect16.fail(new ScheduleRepositoryError({ message: `Schedule ${input.id} was not persisted` }));
|
|
@@ -4121,17 +4374,17 @@ var layer16 = Layer16.effect(Service16, Effect16.gen(function* () {
|
|
|
4121
4374
|
});
|
|
4122
4375
|
const list7 = Effect16.fn("ScheduleRepository.list")(function* (input) {
|
|
4123
4376
|
const tenantId2 = yield* current;
|
|
4124
|
-
const rows = yield*
|
|
4377
|
+
const rows = yield* mapDatabaseError3(db.select().from(relaySchedules).where(predicate(tenantId2, relaySchedules.tenantId, input.state === undefined ? undefined : eq4(relaySchedules.state, input.state))).orderBy(asc2(relaySchedules.nextRunAt), asc2(relaySchedules.createdAt)));
|
|
4125
4378
|
return rows.map(toRecord10);
|
|
4126
4379
|
});
|
|
4127
4380
|
const cancel = Effect16.fn("ScheduleRepository.cancel")(function* (input) {
|
|
4128
4381
|
const tenantId2 = yield* current;
|
|
4129
|
-
const rows = yield*
|
|
4382
|
+
const rows = yield* mapDatabaseError3(db.update(relaySchedules).set({
|
|
4130
4383
|
state: "cancelled",
|
|
4131
4384
|
claimOwner: null,
|
|
4132
4385
|
claimExpiresAt: null,
|
|
4133
4386
|
updatedAt: toPgDate(input.cancelledAt)
|
|
4134
|
-
}).where(predicate(tenantId2, relaySchedules.tenantId,
|
|
4387
|
+
}).where(predicate(tenantId2, relaySchedules.tenantId, eq4(relaySchedules.id, input.id), inArray(relaySchedules.state, [...cancellableStates]))).returning());
|
|
4135
4388
|
const row = rows[0];
|
|
4136
4389
|
if (row !== undefined)
|
|
4137
4390
|
return toRecord10(row);
|
|
@@ -4144,23 +4397,23 @@ var layer16 = Layer16.effect(Service16, Effect16.gen(function* () {
|
|
|
4144
4397
|
});
|
|
4145
4398
|
const claimDue = Effect16.fn("ScheduleRepository.claimDue")(function* (input) {
|
|
4146
4399
|
const tenantId2 = yield* current;
|
|
4147
|
-
const candidate = db.select({ id: relaySchedules.id }).from(relaySchedules).where(predicate(tenantId2, relaySchedules.tenantId, or2(and2(
|
|
4148
|
-
const rows = yield*
|
|
4400
|
+
const candidate = db.select({ id: relaySchedules.id }).from(relaySchedules).where(predicate(tenantId2, relaySchedules.tenantId, or2(and2(eq4(relaySchedules.state, "active"), lte(relaySchedules.nextRunAt, toPgDate(input.now))), and2(eq4(relaySchedules.state, "claimed"), lte(relaySchedules.claimExpiresAt, toPgDate(input.now)))))).orderBy(asc2(relaySchedules.nextRunAt), asc2(relaySchedules.createdAt)).limit(1).for("update", { skipLocked: true });
|
|
4401
|
+
const rows = yield* mapDatabaseError3(db.update(relaySchedules).set({
|
|
4149
4402
|
state: "claimed",
|
|
4150
4403
|
claimOwner: input.workerId,
|
|
4151
4404
|
claimExpiresAt: toPgDate(input.claimExpiresAt),
|
|
4152
4405
|
updatedAt: toPgDate(input.now),
|
|
4153
|
-
attempt:
|
|
4406
|
+
attempt: sql6`${relaySchedules.attempt} + 1`
|
|
4154
4407
|
}).where(predicate(tenantId2, relaySchedules.tenantId, inArray(relaySchedules.id, candidate))).returning());
|
|
4155
4408
|
return rows[0] === undefined ? undefined : toRecord10(rows[0]);
|
|
4156
4409
|
});
|
|
4157
4410
|
const ack = Effect16.fn("ScheduleRepository.ack")(function* (input) {
|
|
4158
4411
|
const tenantId2 = yield* current;
|
|
4159
|
-
const rows = yield*
|
|
4412
|
+
const rows = yield* mapDatabaseError3(db.update(relaySchedules).set({
|
|
4160
4413
|
...input.nextRunAt === undefined ? { state: "completed" } : { state: "active", nextRunAt: toPgDate(input.nextRunAt), claimOwner: null },
|
|
4161
4414
|
claimExpiresAt: null,
|
|
4162
4415
|
updatedAt: toPgDate(input.now)
|
|
4163
|
-
}).where(predicate(tenantId2, relaySchedules.tenantId,
|
|
4416
|
+
}).where(predicate(tenantId2, relaySchedules.tenantId, eq4(relaySchedules.id, input.id), eq4(relaySchedules.claimOwner, input.workerId), eq4(relaySchedules.state, "claimed"))).returning());
|
|
4164
4417
|
const row = rows[0];
|
|
4165
4418
|
if (row !== undefined)
|
|
4166
4419
|
return toRecord10(row);
|
|
@@ -4173,14 +4426,14 @@ var layer16 = Layer16.effect(Service16, Effect16.gen(function* () {
|
|
|
4173
4426
|
});
|
|
4174
4427
|
const release = Effect16.fn("ScheduleRepository.release")(function* (input) {
|
|
4175
4428
|
const tenantId2 = yield* current;
|
|
4176
|
-
const rows = yield*
|
|
4429
|
+
const rows = yield* mapDatabaseError3(db.update(relaySchedules).set({
|
|
4177
4430
|
state: "active",
|
|
4178
4431
|
nextRunAt: toPgDate(input.nextAvailableAt),
|
|
4179
4432
|
claimOwner: null,
|
|
4180
4433
|
claimExpiresAt: null,
|
|
4181
4434
|
lastError: input.error,
|
|
4182
4435
|
updatedAt: toPgDate(input.nextAvailableAt)
|
|
4183
|
-
}).where(predicate(tenantId2, relaySchedules.tenantId,
|
|
4436
|
+
}).where(predicate(tenantId2, relaySchedules.tenantId, eq4(relaySchedules.id, input.id), eq4(relaySchedules.claimOwner, input.workerId), eq4(relaySchedules.state, "claimed"))).returning());
|
|
4184
4437
|
const row = rows[0];
|
|
4185
4438
|
if (row !== undefined)
|
|
4186
4439
|
return toRecord10(row);
|
|
@@ -4364,7 +4617,7 @@ __export(exports_session_repository, {
|
|
|
4364
4617
|
DuplicateSession: () => DuplicateSession
|
|
4365
4618
|
});
|
|
4366
4619
|
import { Context as Context17, Effect as Effect17, Layer as Layer17, Schema as Schema27 } from "effect";
|
|
4367
|
-
import * as
|
|
4620
|
+
import * as SqlClient23 from "effect/unstable/sql/SqlClient";
|
|
4368
4621
|
class SessionRepositoryError extends Schema27.TaggedErrorClass()("SessionRepositoryError", {
|
|
4369
4622
|
message: Schema27.String
|
|
4370
4623
|
}) {
|
|
@@ -4458,11 +4711,11 @@ var toEntryRecord = (row) => {
|
|
|
4458
4711
|
return Effect17.fail(new SessionRepositoryError({ message: `Unknown session entry tag: ${row.tag}` }));
|
|
4459
4712
|
}
|
|
4460
4713
|
};
|
|
4461
|
-
var
|
|
4462
|
-
var mapRepositoryError = (effect) => effect.pipe(Effect17.mapError(
|
|
4463
|
-
var decodeSessionRow = (row) => Schema27.decodeUnknownEffect(SessionRow)(row).pipe(Effect17.mapError(
|
|
4464
|
-
var decodeEntryRow = (row) => Schema27.decodeUnknownEffect(SessionEntryRow)(row).pipe(Effect17.mapError(
|
|
4465
|
-
var decodeCountRow = (row) => Schema27.decodeUnknownEffect(CountRow)(row).pipe(Effect17.mapError(
|
|
4714
|
+
var toRepositoryError10 = (error) => error instanceof SessionRepositoryError ? error : new SessionRepositoryError({ message: String(error) });
|
|
4715
|
+
var mapRepositoryError = (effect) => effect.pipe(Effect17.mapError(toRepositoryError10));
|
|
4716
|
+
var decodeSessionRow = (row) => Schema27.decodeUnknownEffect(SessionRow)(row).pipe(Effect17.mapError(toRepositoryError10));
|
|
4717
|
+
var decodeEntryRow = (row) => Schema27.decodeUnknownEffect(SessionEntryRow)(row).pipe(Effect17.mapError(toRepositoryError10));
|
|
4718
|
+
var decodeCountRow = (row) => Schema27.decodeUnknownEffect(CountRow)(row).pipe(Effect17.mapError(toRepositoryError10));
|
|
4466
4719
|
var maxListLimit3 = 100;
|
|
4467
4720
|
var defaultListLimit2 = 50;
|
|
4468
4721
|
var listLimit3 = (input) => Math.min(Math.max(input.limit ?? defaultListLimit2, 1), maxListLimit3);
|
|
@@ -4512,39 +4765,39 @@ var validateCompaction = (currentPath, input) => {
|
|
|
4512
4765
|
return currentPath.some((item) => item.id === entry.firstKeptEntryId) ? Effect17.void : Effect17.fail(missingEntry(entry.firstKeptEntryId));
|
|
4513
4766
|
};
|
|
4514
4767
|
var layer17 = Layer17.effect(Service17, Effect17.gen(function* () {
|
|
4515
|
-
const
|
|
4516
|
-
const selectSessionByKey = (tenantId2, id2) =>
|
|
4768
|
+
const sql7 = yield* SqlClient23.SqlClient;
|
|
4769
|
+
const selectSessionByKey = (tenantId2, id2) => sql7`
|
|
4517
4770
|
SELECT id, root_address_id, leaf_entry_id, metadata_json, created_at, updated_at
|
|
4518
4771
|
FROM relay_sessions
|
|
4519
4772
|
WHERE tenant_id = ${tenantId2} AND id = ${id2}
|
|
4520
4773
|
`;
|
|
4521
|
-
const selectEntryByKey = (tenantId2, sessionId, id2) =>
|
|
4774
|
+
const selectEntryByKey = (tenantId2, sessionId, id2) => sql7`
|
|
4522
4775
|
SELECT id, session_id, parent_id, tag, payload_json, created_at
|
|
4523
4776
|
FROM relay_session_entries
|
|
4524
4777
|
WHERE tenant_id = ${tenantId2} AND id = ${id2} AND session_id = ${sessionId}
|
|
4525
4778
|
`;
|
|
4526
|
-
const insertSession = (tenantId2, input) =>
|
|
4779
|
+
const insertSession = (tenantId2, input) => sql7`
|
|
4527
4780
|
INSERT INTO relay_sessions (tenant_id, id, root_address_id, metadata_json, created_at, updated_at)
|
|
4528
|
-
VALUES (${tenantId2}, ${input.id}, ${input.rootAddressId}, ${encodeJson(metadata7(input.metadata))}, ${timestampParam(
|
|
4781
|
+
VALUES (${tenantId2}, ${input.id}, ${input.rootAddressId}, ${encodeJson(metadata7(input.metadata))}, ${timestampParam(sql7, input.timestamp)}, ${timestampParam(sql7, input.timestamp)})
|
|
4529
4782
|
`;
|
|
4530
|
-
const touchSession = (tenantId2, id2, updatedAt) =>
|
|
4783
|
+
const touchSession = (tenantId2, id2, updatedAt) => sql7`
|
|
4531
4784
|
UPDATE relay_sessions
|
|
4532
|
-
SET updated_at = ${timestampParam(
|
|
4785
|
+
SET updated_at = ${timestampParam(sql7, updatedAt)}
|
|
4533
4786
|
WHERE tenant_id = ${tenantId2} AND id = ${id2}
|
|
4534
4787
|
`;
|
|
4535
|
-
const updateLeaf = (tenantId2, input) =>
|
|
4788
|
+
const updateLeaf = (tenantId2, input) => sql7`
|
|
4536
4789
|
UPDATE relay_sessions
|
|
4537
|
-
SET leaf_entry_id = ${input.id}, updated_at = ${timestampParam(
|
|
4790
|
+
SET leaf_entry_id = ${input.id}, updated_at = ${timestampParam(sql7, input.updatedAt)}
|
|
4538
4791
|
WHERE tenant_id = ${tenantId2} AND id = ${input.sessionId}
|
|
4539
4792
|
`;
|
|
4540
|
-
const insertEntryIfAbsent =
|
|
4541
|
-
mysql: () => (tenantId2, input) =>
|
|
4793
|
+
const insertEntryIfAbsent = sql7.onDialectOrElse({
|
|
4794
|
+
mysql: () => (tenantId2, input) => sql7`
|
|
4542
4795
|
INSERT IGNORE INTO relay_session_entries (tenant_id, id, session_id, parent_id, tag, payload_json, created_at)
|
|
4543
|
-
VALUES (${tenantId2}, ${input.id}, ${input.sessionId}, ${input.parentId}, ${input.input._tag}, ${encodeJson(payloadFromInput(input.input))}, ${timestampParam(
|
|
4796
|
+
VALUES (${tenantId2}, ${input.id}, ${input.sessionId}, ${input.parentId}, ${input.input._tag}, ${encodeJson(payloadFromInput(input.input))}, ${timestampParam(sql7, input.createdAt)})
|
|
4544
4797
|
`,
|
|
4545
|
-
orElse: () => (tenantId2, input) =>
|
|
4798
|
+
orElse: () => (tenantId2, input) => sql7`
|
|
4546
4799
|
INSERT INTO relay_session_entries (tenant_id, id, session_id, parent_id, tag, payload_json, created_at)
|
|
4547
|
-
VALUES (${tenantId2}, ${input.id}, ${input.sessionId}, ${input.parentId}, ${input.input._tag}, ${encodeJson(payloadFromInput(input.input))}, ${timestampParam(
|
|
4800
|
+
VALUES (${tenantId2}, ${input.id}, ${input.sessionId}, ${input.parentId}, ${input.input._tag}, ${encodeJson(payloadFromInput(input.input))}, ${timestampParam(sql7, input.createdAt)})
|
|
4548
4801
|
ON CONFLICT (tenant_id, id) DO NOTHING
|
|
4549
4802
|
`
|
|
4550
4803
|
});
|
|
@@ -4630,23 +4883,23 @@ var layer17 = Layer17.effect(Service17, Effect17.gen(function* () {
|
|
|
4630
4883
|
const list8 = Effect17.fn("SessionRepository.list")(function* (input) {
|
|
4631
4884
|
const tenantId2 = yield* current;
|
|
4632
4885
|
const limit = listLimit3(input);
|
|
4633
|
-
const conditions = [
|
|
4886
|
+
const conditions = [sql7`tenant_id = ${tenantId2}`];
|
|
4634
4887
|
if (input.rootAddressId !== undefined) {
|
|
4635
|
-
conditions.push(
|
|
4888
|
+
conditions.push(sql7`root_address_id = ${input.rootAddressId}`);
|
|
4636
4889
|
}
|
|
4637
4890
|
if (input.cursor !== undefined) {
|
|
4638
|
-
const cursorTimestamp = timestampParam(
|
|
4639
|
-
conditions.push(
|
|
4640
|
-
|
|
4641
|
-
|
|
4891
|
+
const cursorTimestamp = timestampParam(sql7, input.cursor.updatedAt);
|
|
4892
|
+
conditions.push(sql7.or([
|
|
4893
|
+
sql7`updated_at < ${cursorTimestamp}`,
|
|
4894
|
+
sql7.and([sql7`updated_at = ${cursorTimestamp}`, sql7`id < ${input.cursor.id}`])
|
|
4642
4895
|
]));
|
|
4643
4896
|
}
|
|
4644
|
-
const rows = yield* mapRepositoryError(
|
|
4897
|
+
const rows = yield* mapRepositoryError(sql7`
|
|
4645
4898
|
SELECT id, root_address_id, leaf_entry_id, metadata_json, created_at, updated_at
|
|
4646
4899
|
FROM relay_sessions
|
|
4647
|
-
WHERE ${
|
|
4900
|
+
WHERE ${sql7.and(conditions)}
|
|
4648
4901
|
ORDER BY updated_at DESC, id DESC
|
|
4649
|
-
LIMIT ${
|
|
4902
|
+
LIMIT ${sql7.literal(String(limit + 1))}
|
|
4650
4903
|
`);
|
|
4651
4904
|
const records = yield* Effect17.forEach(rows.slice(0, limit), (row) => decodeSessionRow(row).pipe(Effect17.map(toSessionRecord)));
|
|
4652
4905
|
const nextCursor = nextCursorOf2(records, rows.length, limit);
|
|
@@ -4693,7 +4946,7 @@ var layer17 = Layer17.effect(Service17, Effect17.gen(function* () {
|
|
|
4693
4946
|
}
|
|
4694
4947
|
const currentPath = session.leafEntryId === undefined ? [] : yield* pathForTenant(tenantId2, { sessionId: input.sessionId });
|
|
4695
4948
|
yield* validateCompaction(currentPath, input);
|
|
4696
|
-
return yield* mapRepositoryError(
|
|
4949
|
+
return yield* mapRepositoryError(sql7.withTransaction(Effect17.gen(function* () {
|
|
4697
4950
|
yield* insertEntryIfAbsent(tenantId2, input);
|
|
4698
4951
|
const entryRows = yield* selectEntryByKey(tenantId2, input.sessionId, input.id);
|
|
4699
4952
|
const entryRow = entryRows[0];
|
|
@@ -4712,7 +4965,7 @@ var layer17 = Layer17.effect(Service17, Effect17.gen(function* () {
|
|
|
4712
4965
|
});
|
|
4713
4966
|
const countEntries = Effect17.fn("SessionRepository.countEntries")(function* (sessionId) {
|
|
4714
4967
|
const tenantId2 = yield* current;
|
|
4715
|
-
const rows = yield* mapRepositoryError(
|
|
4968
|
+
const rows = yield* mapRepositoryError(sql7`
|
|
4716
4969
|
SELECT COUNT(*) AS value
|
|
4717
4970
|
FROM relay_session_entries
|
|
4718
4971
|
WHERE tenant_id = ${tenantId2} AND session_id = ${sessionId}
|
|
@@ -4908,7 +5161,7 @@ __export(exports_skill_definition_repository, {
|
|
|
4908
5161
|
SkillDefinitionRepositoryError: () => SkillDefinitionRepositoryError,
|
|
4909
5162
|
Service: () => Service18
|
|
4910
5163
|
});
|
|
4911
|
-
import { asc as
|
|
5164
|
+
import { asc as asc3, desc as desc2, eq as eq5, inArray as inArray2, sql as sql7 } from "drizzle-orm";
|
|
4912
5165
|
import { Context as Context18, Effect as Effect18, HashSet, Layer as Layer18, Schema as Schema28, Semaphore as Semaphore2 } from "effect";
|
|
4913
5166
|
class SkillDefinitionRepositoryError extends Schema28.TaggedErrorClass()("SkillDefinitionRepositoryError", {
|
|
4914
5167
|
message: Schema28.String
|
|
@@ -4971,10 +5224,10 @@ var missingSkillMessage = (requested, records) => {
|
|
|
4971
5224
|
const found = HashSet.fromIterable(records.map((record2) => record2.id));
|
|
4972
5225
|
return `Skill definition not found: ${requested.find((id2) => !HashSet.has(found, id2)) ?? requested[0]}`;
|
|
4973
5226
|
};
|
|
4974
|
-
var
|
|
5227
|
+
var mapDatabaseError4 = (effect) => effect.pipe(Effect18.mapError((error) => new SkillDefinitionRepositoryError({ message: String(error) })));
|
|
4975
5228
|
var mapPutError2 = (effect) => effect.pipe(Effect18.mapError((error) => error instanceof SkillDefinitionRepositoryError ? error : new SkillDefinitionRepositoryError({ message: String(error) })));
|
|
4976
5229
|
var skillPinLockKey = (tenantId2, executionId) => `skill-pins:${tenantId2}:${executionId}`;
|
|
4977
|
-
var lockExecutionPins = (db, tenantId2, executionId) =>
|
|
5230
|
+
var lockExecutionPins = (db, tenantId2, executionId) => mapDatabaseError4(db.execute(sql7`select pg_advisory_xact_lock(hashtext(${skillPinLockKey(tenantId2, executionId)}))`)).pipe(Effect18.asVoid);
|
|
4978
5231
|
var layer18 = Layer18.effect(Service18, Effect18.gen(function* () {
|
|
4979
5232
|
const db = yield* Service;
|
|
4980
5233
|
const put2 = Effect18.fn("SkillDefinitionRepository.put")(function* (input) {
|
|
@@ -4992,7 +5245,7 @@ var layer18 = Layer18.effect(Service18, Effect18.gen(function* () {
|
|
|
4992
5245
|
target: [relaySkillDefinitions.tenantId, relaySkillDefinitions.id],
|
|
4993
5246
|
set: {
|
|
4994
5247
|
name: input.definition.frontmatter.name,
|
|
4995
|
-
currentRevision:
|
|
5248
|
+
currentRevision: sql7`${relaySkillDefinitions.currentRevision} + 1`,
|
|
4996
5249
|
definitionJson: input.definition,
|
|
4997
5250
|
updatedAt: toPgDate(input.now)
|
|
4998
5251
|
}
|
|
@@ -5017,32 +5270,32 @@ var layer18 = Layer18.effect(Service18, Effect18.gen(function* () {
|
|
|
5017
5270
|
});
|
|
5018
5271
|
const get9 = Effect18.fn("SkillDefinitionRepository.get")(function* (id2) {
|
|
5019
5272
|
const tenantId2 = yield* current;
|
|
5020
|
-
const rows = yield*
|
|
5273
|
+
const rows = yield* mapDatabaseError4(db.select().from(relaySkillDefinitions).where(predicate(tenantId2, relaySkillDefinitions.tenantId, eq5(relaySkillDefinitions.id, id2))).limit(1));
|
|
5021
5274
|
return rows[0] === undefined ? undefined : toRecord11(rows[0]);
|
|
5022
5275
|
});
|
|
5023
5276
|
const getRevision2 = Effect18.fn("SkillDefinitionRepository.getRevision")(function* (input) {
|
|
5024
5277
|
const tenantId2 = yield* current;
|
|
5025
|
-
const rows = yield*
|
|
5278
|
+
const rows = yield* mapDatabaseError4(db.select().from(relaySkillDefinitionRevisions).where(predicate(tenantId2, relaySkillDefinitionRevisions.tenantId, eq5(relaySkillDefinitionRevisions.skillDefinitionId, input.id), eq5(relaySkillDefinitionRevisions.revision, input.revision))).limit(1));
|
|
5026
5279
|
return rows[0] === undefined ? undefined : toRevisionRecord2(rows[0]);
|
|
5027
5280
|
});
|
|
5028
5281
|
const list9 = Effect18.fn("SkillDefinitionRepository.list")(function* () {
|
|
5029
5282
|
const tenantId2 = yield* current;
|
|
5030
|
-
const rows = yield*
|
|
5283
|
+
const rows = yield* mapDatabaseError4(db.select().from(relaySkillDefinitions).where(predicate(tenantId2, relaySkillDefinitions.tenantId)).orderBy(desc2(relaySkillDefinitions.createdAt), asc3(relaySkillDefinitions.id)));
|
|
5031
5284
|
return rows.map(toRecord11);
|
|
5032
5285
|
});
|
|
5033
5286
|
const listRevisions2 = Effect18.fn("SkillDefinitionRepository.listRevisions")(function* (id2) {
|
|
5034
5287
|
const tenantId2 = yield* current;
|
|
5035
|
-
const rows = yield*
|
|
5288
|
+
const rows = yield* mapDatabaseError4(db.select().from(relaySkillDefinitionRevisions).where(predicate(tenantId2, relaySkillDefinitionRevisions.tenantId, eq5(relaySkillDefinitionRevisions.skillDefinitionId, id2))).orderBy(desc2(relaySkillDefinitionRevisions.revision)));
|
|
5036
5289
|
return rows.map(toRevisionRecord2);
|
|
5037
5290
|
});
|
|
5038
5291
|
const listPins = Effect18.fn("SkillDefinitionRepository.listPins")(function* (executionId) {
|
|
5039
5292
|
const tenantId2 = yield* current;
|
|
5040
|
-
const rows = yield*
|
|
5293
|
+
const rows = yield* mapDatabaseError4(db.select().from(relayExecutionSkillPins).where(predicate(tenantId2, relayExecutionSkillPins.tenantId, eq5(relayExecutionSkillPins.executionId, executionId))).orderBy(asc3(relayExecutionSkillPins.skillDefinitionId)));
|
|
5041
5294
|
return rows.map(toPinRecord);
|
|
5042
5295
|
});
|
|
5043
5296
|
const getPinned = Effect18.fn("SkillDefinitionRepository.getPinned")(function* (input) {
|
|
5044
5297
|
const tenantId2 = yield* current;
|
|
5045
|
-
const rows = yield*
|
|
5298
|
+
const rows = yield* mapDatabaseError4(db.select().from(relayExecutionSkillPins).where(predicate(tenantId2, relayExecutionSkillPins.tenantId, eq5(relayExecutionSkillPins.executionId, input.executionId), eq5(relayExecutionSkillPins.skillDefinitionId, input.skillDefinitionId))).limit(1));
|
|
5046
5299
|
return rows[0] === undefined ? undefined : toPinRecord(rows[0]);
|
|
5047
5300
|
});
|
|
5048
5301
|
const pinExecution = Effect18.fn("SkillDefinitionRepository.pinExecution")(function* (input) {
|
|
@@ -5052,7 +5305,7 @@ var layer18 = Layer18.effect(Service18, Effect18.gen(function* () {
|
|
|
5052
5305
|
return [];
|
|
5053
5306
|
return yield* mapPutError2(db.transaction((tx) => Effect18.gen(function* () {
|
|
5054
5307
|
yield* lockExecutionPins(tx, tenantId2, input.executionId);
|
|
5055
|
-
const existingRows = yield* tx.select().from(relayExecutionSkillPins).where(predicate(tenantId2, relayExecutionSkillPins.tenantId,
|
|
5308
|
+
const existingRows = yield* tx.select().from(relayExecutionSkillPins).where(predicate(tenantId2, relayExecutionSkillPins.tenantId, eq5(relayExecutionSkillPins.executionId, input.executionId))).orderBy(asc3(relayExecutionSkillPins.skillDefinitionId));
|
|
5056
5309
|
if (existingRows.length > 0) {
|
|
5057
5310
|
const existing = existingRows.map(toPinRecord);
|
|
5058
5311
|
if (!sameIdSet(existing.map((record2) => record2.skillDefinitionId), requestedIds)) {
|
|
@@ -5214,7 +5467,7 @@ __export(exports_steering_repository, {
|
|
|
5214
5467
|
Service: () => Service19
|
|
5215
5468
|
});
|
|
5216
5469
|
import { Context as Context19, Effect as Effect19, Layer as Layer19, Ref as Ref3, Schema as Schema29 } from "effect";
|
|
5217
|
-
import * as
|
|
5470
|
+
import * as SqlClient25 from "effect/unstable/sql/SqlClient";
|
|
5218
5471
|
class SteeringRepositoryError extends Schema29.TaggedErrorClass()("SteeringRepositoryError", {
|
|
5219
5472
|
message: Schema29.String
|
|
5220
5473
|
}) {
|
|
@@ -5240,10 +5493,10 @@ var SteeringDrainRow = Schema29.Struct({
|
|
|
5240
5493
|
message_sequences_json: Schema29.Unknown,
|
|
5241
5494
|
created_at: DbTimestamp2
|
|
5242
5495
|
}).annotate({ identifier: "Relay.SteeringDrain.Row" });
|
|
5243
|
-
var
|
|
5244
|
-
var mapTransactionError = (effect) => effect.pipe(Effect19.mapError((error) => error instanceof SteeringRepositoryError ? error :
|
|
5245
|
-
var decodeMessageRow = (row) => Schema29.decodeUnknownEffect(SteeringMessageRow)(row).pipe(Effect19.mapError(
|
|
5246
|
-
var decodeDrainRow = (row) => Schema29.decodeUnknownEffect(SteeringDrainRow)(row).pipe(Effect19.mapError(
|
|
5496
|
+
var toRepositoryError11 = (error) => new SteeringRepositoryError({ message: String(error) });
|
|
5497
|
+
var mapTransactionError = (effect) => effect.pipe(Effect19.mapError((error) => error instanceof SteeringRepositoryError ? error : toRepositoryError11(error)));
|
|
5498
|
+
var decodeMessageRow = (row) => Schema29.decodeUnknownEffect(SteeringMessageRow)(row).pipe(Effect19.mapError(toRepositoryError11));
|
|
5499
|
+
var decodeDrainRow = (row) => Schema29.decodeUnknownEffect(SteeringDrainRow)(row).pipe(Effect19.mapError(toRepositoryError11));
|
|
5247
5500
|
var toMessageRecord = (row) => {
|
|
5248
5501
|
const consumedAt = fromNullableDbTimestamp(row.consumed_at);
|
|
5249
5502
|
return {
|
|
@@ -5281,21 +5534,21 @@ var consumedMessage = (message, input) => ({
|
|
|
5281
5534
|
createdAt: message.createdAt
|
|
5282
5535
|
});
|
|
5283
5536
|
var layer19 = Layer19.effect(Service19, Effect19.gen(function* () {
|
|
5284
|
-
const
|
|
5285
|
-
const lockQueue =
|
|
5286
|
-
pg: () => (tenantId2, executionId, kind) =>
|
|
5537
|
+
const sql8 = yield* SqlClient25.SqlClient;
|
|
5538
|
+
const lockQueue = sql8.onDialectOrElse({
|
|
5539
|
+
pg: () => (tenantId2, executionId, kind) => sql8`SELECT pg_advisory_xact_lock(hashtext(${queueKey(tenantId2, executionId, kind)}))`.pipe(Effect19.asVoid),
|
|
5287
5540
|
orElse: () => () => Effect19.void
|
|
5288
5541
|
});
|
|
5289
|
-
const selectMessagesBySequences = (tenantId2, executionId, kind, sequences) =>
|
|
5542
|
+
const selectMessagesBySequences = (tenantId2, executionId, kind, sequences) => sql8`
|
|
5290
5543
|
SELECT execution_id, kind, sequence, content_json, drain_id, consumed_at, created_at
|
|
5291
5544
|
FROM relay_steering_messages
|
|
5292
5545
|
WHERE tenant_id = ${tenantId2}
|
|
5293
5546
|
AND execution_id = ${executionId}
|
|
5294
5547
|
AND kind = ${kind}
|
|
5295
|
-
AND ${
|
|
5548
|
+
AND ${sql8.in("sequence", sequences)}
|
|
5296
5549
|
ORDER BY sequence ASC
|
|
5297
5550
|
`;
|
|
5298
|
-
const selectDrain = (tenantId2, input) =>
|
|
5551
|
+
const selectDrain = (tenantId2, input) => sql8`
|
|
5299
5552
|
SELECT execution_id, kind, drain_id, message_sequences_json, created_at
|
|
5300
5553
|
FROM relay_steering_drains
|
|
5301
5554
|
WHERE tenant_id = ${tenantId2}
|
|
@@ -5304,7 +5557,7 @@ var layer19 = Layer19.effect(Service19, Effect19.gen(function* () {
|
|
|
5304
5557
|
AND drain_id = ${input.drainId}
|
|
5305
5558
|
`;
|
|
5306
5559
|
const findDrain = Effect19.fn("SteeringRepository.findDrain")(function* (tenantId2, input) {
|
|
5307
|
-
const rows = yield* selectDrain(tenantId2, input).pipe(Effect19.mapError(
|
|
5560
|
+
const rows = yield* selectDrain(tenantId2, input).pipe(Effect19.mapError(toRepositoryError11));
|
|
5308
5561
|
return rows[0] === undefined ? undefined : toDrainRecord(yield* decodeDrainRow(rows[0]));
|
|
5309
5562
|
});
|
|
5310
5563
|
const messagesForDrain = Effect19.fn("SteeringRepository.messagesForDrain")(function* (tenantId2, drain) {
|
|
@@ -5312,46 +5565,46 @@ var layer19 = Layer19.effect(Service19, Effect19.gen(function* () {
|
|
|
5312
5565
|
return { drain, messages: [] };
|
|
5313
5566
|
const rows = yield* selectMessagesBySequences(tenantId2, drain.executionId, drain.kind, [
|
|
5314
5567
|
...drain.messageSequences
|
|
5315
|
-
]).pipe(Effect19.mapError(
|
|
5568
|
+
]).pipe(Effect19.mapError(toRepositoryError11));
|
|
5316
5569
|
const messages = yield* Effect19.forEach(rows, (row) => decodeMessageRow(row).pipe(Effect19.map(toMessageRecord)));
|
|
5317
5570
|
return { drain, messages };
|
|
5318
5571
|
});
|
|
5319
|
-
const insertMessage =
|
|
5572
|
+
const insertMessage = sql8.onDialectOrElse({
|
|
5320
5573
|
mysql: () => (tenantId2, input, sequence) => Effect19.gen(function* () {
|
|
5321
|
-
yield*
|
|
5574
|
+
yield* sql8`
|
|
5322
5575
|
INSERT INTO relay_steering_messages (tenant_id, execution_id, kind, sequence, content_json, created_at)
|
|
5323
|
-
VALUES (${tenantId2}, ${input.executionId}, ${input.kind}, ${sequence}, ${encodeJson(input.content)}, ${timestampParam(
|
|
5576
|
+
VALUES (${tenantId2}, ${input.executionId}, ${input.kind}, ${sequence}, ${encodeJson(input.content)}, ${timestampParam(sql8, input.createdAt)})
|
|
5324
5577
|
`;
|
|
5325
5578
|
return yield* selectMessagesBySequences(tenantId2, input.executionId, input.kind, [sequence]);
|
|
5326
5579
|
}),
|
|
5327
|
-
orElse: () => (tenantId2, input, sequence) =>
|
|
5580
|
+
orElse: () => (tenantId2, input, sequence) => sql8`
|
|
5328
5581
|
INSERT INTO relay_steering_messages (tenant_id, execution_id, kind, sequence, content_json, created_at)
|
|
5329
|
-
VALUES (${tenantId2}, ${input.executionId}, ${input.kind}, ${sequence}, ${encodeJson(input.content)}, ${timestampParam(
|
|
5582
|
+
VALUES (${tenantId2}, ${input.executionId}, ${input.kind}, ${sequence}, ${encodeJson(input.content)}, ${timestampParam(sql8, input.createdAt)})
|
|
5330
5583
|
RETURNING execution_id, kind, sequence, content_json, drain_id, consumed_at, created_at
|
|
5331
5584
|
`
|
|
5332
5585
|
});
|
|
5333
|
-
const insertDrain =
|
|
5586
|
+
const insertDrain = sql8.onDialectOrElse({
|
|
5334
5587
|
mysql: () => (tenantId2, input, sequences) => Effect19.gen(function* () {
|
|
5335
|
-
yield*
|
|
5588
|
+
yield* sql8`
|
|
5336
5589
|
INSERT INTO relay_steering_drains (tenant_id, execution_id, kind, drain_id, message_sequences_json, created_at)
|
|
5337
|
-
VALUES (${tenantId2}, ${input.executionId}, ${input.kind}, ${input.drainId}, ${encodeJson(sequences)}, ${timestampParam(
|
|
5590
|
+
VALUES (${tenantId2}, ${input.executionId}, ${input.kind}, ${input.drainId}, ${encodeJson(sequences)}, ${timestampParam(sql8, input.createdAt)})
|
|
5338
5591
|
`;
|
|
5339
5592
|
return yield* selectDrain(tenantId2, input);
|
|
5340
5593
|
}),
|
|
5341
|
-
orElse: () => (tenantId2, input, sequences) =>
|
|
5594
|
+
orElse: () => (tenantId2, input, sequences) => sql8`
|
|
5342
5595
|
INSERT INTO relay_steering_drains (tenant_id, execution_id, kind, drain_id, message_sequences_json, created_at)
|
|
5343
|
-
VALUES (${tenantId2}, ${input.executionId}, ${input.kind}, ${input.drainId}, ${encodeJson(sequences)}, ${timestampParam(
|
|
5596
|
+
VALUES (${tenantId2}, ${input.executionId}, ${input.kind}, ${input.drainId}, ${encodeJson(sequences)}, ${timestampParam(sql8, input.createdAt)})
|
|
5344
5597
|
RETURNING execution_id, kind, drain_id, message_sequences_json, created_at
|
|
5345
5598
|
`
|
|
5346
5599
|
});
|
|
5347
|
-
const selectExecutionStatus =
|
|
5348
|
-
sqlite: () => (tenantId2, executionId) =>
|
|
5600
|
+
const selectExecutionStatus = sql8.onDialectOrElse({
|
|
5601
|
+
sqlite: () => (tenantId2, executionId) => sql8`
|
|
5349
5602
|
SELECT status
|
|
5350
5603
|
FROM relay_executions
|
|
5351
5604
|
WHERE tenant_id = ${tenantId2} AND id = ${executionId}
|
|
5352
5605
|
LIMIT 1
|
|
5353
5606
|
`,
|
|
5354
|
-
orElse: () => (tenantId2, executionId) =>
|
|
5607
|
+
orElse: () => (tenantId2, executionId) => sql8`
|
|
5355
5608
|
SELECT status
|
|
5356
5609
|
FROM relay_executions
|
|
5357
5610
|
WHERE tenant_id = ${tenantId2} AND id = ${executionId}
|
|
@@ -5361,7 +5614,7 @@ var layer19 = Layer19.effect(Service19, Effect19.gen(function* () {
|
|
|
5361
5614
|
});
|
|
5362
5615
|
const appendInTransaction = Effect19.fn("SteeringRepository.appendInTransaction")(function* (tenantId2, input) {
|
|
5363
5616
|
yield* lockQueue(tenantId2, input.executionId, input.kind);
|
|
5364
|
-
const sequenceRows = yield*
|
|
5617
|
+
const sequenceRows = yield* sql8`
|
|
5365
5618
|
SELECT COALESCE(MAX(sequence), -1) + 1 AS next_sequence
|
|
5366
5619
|
FROM relay_steering_messages
|
|
5367
5620
|
WHERE tenant_id = ${tenantId2}
|
|
@@ -5378,11 +5631,11 @@ var layer19 = Layer19.effect(Service19, Effect19.gen(function* () {
|
|
|
5378
5631
|
});
|
|
5379
5632
|
const append2 = Effect19.fn("SteeringRepository.append")(function* (input) {
|
|
5380
5633
|
const tenantId2 = yield* current;
|
|
5381
|
-
return yield*
|
|
5634
|
+
return yield* sql8.withTransaction(appendInTransaction(tenantId2, input)).pipe(mapTransactionError);
|
|
5382
5635
|
});
|
|
5383
5636
|
const appendForRunning = Effect19.fn("SteeringRepository.appendForRunning")(function* (input) {
|
|
5384
5637
|
const tenantId2 = yield* current;
|
|
5385
|
-
return yield*
|
|
5638
|
+
return yield* sql8.withTransaction(Effect19.gen(function* () {
|
|
5386
5639
|
const statusRows = yield* selectExecutionStatus(tenantId2, input.executionId);
|
|
5387
5640
|
const status = statusRows[0]?.status;
|
|
5388
5641
|
if (status === undefined) {
|
|
@@ -5399,12 +5652,12 @@ var layer19 = Layer19.effect(Service19, Effect19.gen(function* () {
|
|
|
5399
5652
|
const existing = yield* findDrain(tenantId2, input);
|
|
5400
5653
|
if (existing !== undefined)
|
|
5401
5654
|
return yield* messagesForDrain(tenantId2, existing);
|
|
5402
|
-
return yield*
|
|
5655
|
+
return yield* sql8.withTransaction(Effect19.gen(function* () {
|
|
5403
5656
|
yield* lockQueue(tenantId2, input.executionId, input.kind);
|
|
5404
5657
|
const existingAfterLock = yield* findDrain(tenantId2, input);
|
|
5405
5658
|
if (existingAfterLock !== undefined)
|
|
5406
5659
|
return yield* messagesForDrain(tenantId2, existingAfterLock);
|
|
5407
|
-
const unconsumedRows = yield*
|
|
5660
|
+
const unconsumedRows = yield* sql8`
|
|
5408
5661
|
SELECT execution_id, kind, sequence, content_json, drain_id, consumed_at, created_at
|
|
5409
5662
|
FROM relay_steering_messages
|
|
5410
5663
|
WHERE tenant_id = ${tenantId2}
|
|
@@ -5412,18 +5665,18 @@ var layer19 = Layer19.effect(Service19, Effect19.gen(function* () {
|
|
|
5412
5665
|
AND kind = ${input.kind}
|
|
5413
5666
|
AND consumed_at IS NULL
|
|
5414
5667
|
ORDER BY sequence ASC
|
|
5415
|
-
${input.mode === "one-at-a-time" ?
|
|
5668
|
+
${input.mode === "one-at-a-time" ? sql8.literal("LIMIT 1") : sql8.literal("")}
|
|
5416
5669
|
`;
|
|
5417
5670
|
const unconsumed = yield* Effect19.forEach(unconsumedRows, decodeMessageRow);
|
|
5418
5671
|
const sequences = unconsumed.map((row) => Number(row.sequence));
|
|
5419
5672
|
if (sequences.length > 0) {
|
|
5420
|
-
yield*
|
|
5673
|
+
yield* sql8`
|
|
5421
5674
|
UPDATE relay_steering_messages
|
|
5422
|
-
SET drain_id = ${input.drainId}, consumed_at = ${timestampParam(
|
|
5675
|
+
SET drain_id = ${input.drainId}, consumed_at = ${timestampParam(sql8, input.consumedAt)}
|
|
5423
5676
|
WHERE tenant_id = ${tenantId2}
|
|
5424
5677
|
AND execution_id = ${input.executionId}
|
|
5425
5678
|
AND kind = ${input.kind}
|
|
5426
|
-
AND ${
|
|
5679
|
+
AND ${sql8.in("sequence", sequences)}
|
|
5427
5680
|
`;
|
|
5428
5681
|
}
|
|
5429
5682
|
const messageRows = sequences.length === 0 ? [] : yield* selectMessagesBySequences(tenantId2, input.executionId, input.kind, sequences);
|
|
@@ -5529,14 +5782,16 @@ __export(exports_tool_call_repository, {
|
|
|
5529
5782
|
layer: () => layer20,
|
|
5530
5783
|
getResult: () => getResult,
|
|
5531
5784
|
getCall: () => getCall,
|
|
5785
|
+
ToolResultRow: () => ToolResultRow,
|
|
5786
|
+
ToolCallRow: () => ToolCallRow,
|
|
5532
5787
|
ToolCallRepositoryError: () => ToolCallRepositoryError,
|
|
5533
5788
|
ToolCallNotFound: () => ToolCallNotFound,
|
|
5534
5789
|
Service: () => Service20,
|
|
5535
5790
|
DuplicateToolResult: () => DuplicateToolResult,
|
|
5536
5791
|
DuplicateToolCall: () => DuplicateToolCall
|
|
5537
5792
|
});
|
|
5538
|
-
import { asc as asc9, eq as eq12 } from "drizzle-orm";
|
|
5539
5793
|
import { Context as Context20, Effect as Effect20, Layer as Layer20, Schema as Schema30 } from "effect";
|
|
5794
|
+
import * as SqlClient27 from "effect/unstable/sql/SqlClient";
|
|
5540
5795
|
class ToolCallRepositoryError extends Schema30.TaggedErrorClass()("ToolCallRepositoryError", {
|
|
5541
5796
|
message: Schema30.String
|
|
5542
5797
|
}) {
|
|
@@ -5559,88 +5814,153 @@ class DuplicateToolResult extends Schema30.TaggedErrorClass()("DuplicateToolResu
|
|
|
5559
5814
|
|
|
5560
5815
|
class Service20 extends Context20.Service()("@relayfx/store-sql/ToolCallRepository") {
|
|
5561
5816
|
}
|
|
5817
|
+
var ToolCallRow = Schema30.Struct({
|
|
5818
|
+
id: Schema30.String,
|
|
5819
|
+
execution_id: Schema30.String,
|
|
5820
|
+
name: Schema30.String,
|
|
5821
|
+
input_json: Schema30.Unknown,
|
|
5822
|
+
metadata_json: Schema30.Unknown,
|
|
5823
|
+
created_at: Schema30.Union([Schema30.Date, Schema30.String, Schema30.Number])
|
|
5824
|
+
}).annotate({ identifier: "Relay.ToolCall.Row" });
|
|
5825
|
+
var ToolResultRow = Schema30.Struct({
|
|
5826
|
+
tool_call_id: Schema30.String,
|
|
5827
|
+
output_json: Schema30.Unknown,
|
|
5828
|
+
error: Schema30.NullishOr(Schema30.String),
|
|
5829
|
+
metadata_json: Schema30.Unknown,
|
|
5830
|
+
created_at: Schema30.Union([Schema30.Date, Schema30.String, Schema30.Number])
|
|
5831
|
+
}).annotate({ identifier: "Relay.ToolResult.Row" });
|
|
5562
5832
|
var metadata8 = (input) => input ?? {};
|
|
5563
|
-
var toCallInsert = (tenantId2, input) => ({
|
|
5564
|
-
tenantId: tenantId2,
|
|
5565
|
-
id: input.call.id,
|
|
5566
|
-
executionId: input.executionId,
|
|
5567
|
-
name: input.call.name,
|
|
5568
|
-
inputJson: input.call.input,
|
|
5569
|
-
metadataJson: metadata8(input.call.metadata),
|
|
5570
|
-
createdAt: toPgDate(input.createdAt)
|
|
5571
|
-
});
|
|
5572
5833
|
var toCallRecord = (row) => ({
|
|
5573
|
-
executionId: row.
|
|
5834
|
+
executionId: exports_ids_schema.ExecutionId.make(row.execution_id),
|
|
5574
5835
|
call: {
|
|
5575
|
-
id: row.id,
|
|
5836
|
+
id: exports_ids_schema.ToolCallId.make(row.id),
|
|
5576
5837
|
name: row.name,
|
|
5577
|
-
input: row.
|
|
5578
|
-
metadata: row.
|
|
5838
|
+
input: decodeJson(row.input_json),
|
|
5839
|
+
metadata: decodeJson(row.metadata_json)
|
|
5579
5840
|
},
|
|
5580
|
-
createdAt:
|
|
5581
|
-
});
|
|
5582
|
-
var toResultInsert = (tenantId2, input) => ({
|
|
5583
|
-
tenantId: tenantId2,
|
|
5584
|
-
toolCallId: input.result.call_id,
|
|
5585
|
-
outputJson: input.result.output,
|
|
5586
|
-
metadataJson: metadata8(input.result.metadata),
|
|
5587
|
-
createdAt: toPgDate(input.createdAt),
|
|
5588
|
-
...input.result.error === undefined ? {} : { error: input.result.error }
|
|
5841
|
+
createdAt: fromDbTimestamp(row.created_at)
|
|
5589
5842
|
});
|
|
5590
5843
|
var toResultRecord = (row) => ({
|
|
5591
5844
|
result: {
|
|
5592
|
-
call_id: row.
|
|
5593
|
-
output: row.
|
|
5594
|
-
...row.error === null ? {} : { error: row.error },
|
|
5595
|
-
metadata: row.
|
|
5845
|
+
call_id: exports_ids_schema.ToolCallId.make(row.tool_call_id),
|
|
5846
|
+
output: decodeJson(row.output_json),
|
|
5847
|
+
...row.error === null || row.error === undefined ? {} : { error: row.error },
|
|
5848
|
+
metadata: decodeJson(row.metadata_json)
|
|
5596
5849
|
},
|
|
5597
|
-
createdAt:
|
|
5850
|
+
createdAt: fromDbTimestamp(row.created_at)
|
|
5598
5851
|
});
|
|
5599
|
-
var
|
|
5852
|
+
var toRepositoryError12 = (error) => new ToolCallRepositoryError({ message: String(error) });
|
|
5853
|
+
var decodeCallRow = (row) => Schema30.decodeUnknownEffect(ToolCallRow)(row).pipe(Effect20.mapError(toRepositoryError12));
|
|
5854
|
+
var decodeResultRow = (row) => Schema30.decodeUnknownEffect(ToolResultRow)(row).pipe(Effect20.mapError(toRepositoryError12));
|
|
5600
5855
|
var layer20 = Layer20.effect(Service20, Effect20.gen(function* () {
|
|
5601
|
-
const
|
|
5856
|
+
const sql8 = yield* SqlClient27.SqlClient;
|
|
5857
|
+
const callColumns = sql8.literal(["id", "execution_id", "name", "input_json", "metadata_json", "created_at"].join(", "));
|
|
5858
|
+
const resultColumns = sql8.literal(["tool_call_id", "output_json", "error", "metadata_json", "created_at"].join(", "));
|
|
5859
|
+
const selectCallByKey = (tenantId2, id2) => sql8`
|
|
5860
|
+
SELECT ${callColumns}
|
|
5861
|
+
FROM relay_tool_calls
|
|
5862
|
+
WHERE tenant_id = ${tenantId2} AND id = ${id2}
|
|
5863
|
+
`;
|
|
5864
|
+
const selectResultByKey = (tenantId2, callId) => sql8`
|
|
5865
|
+
SELECT ${resultColumns}
|
|
5866
|
+
FROM relay_tool_results
|
|
5867
|
+
WHERE tenant_id = ${tenantId2} AND tool_call_id = ${callId}
|
|
5868
|
+
`;
|
|
5869
|
+
const insertCallStatement = (tenantId2, input) => sql8`
|
|
5870
|
+
INSERT INTO relay_tool_calls (
|
|
5871
|
+
tenant_id, ${callColumns}
|
|
5872
|
+
)
|
|
5873
|
+
VALUES (
|
|
5874
|
+
${tenantId2},
|
|
5875
|
+
${input.call.id},
|
|
5876
|
+
${input.executionId},
|
|
5877
|
+
${input.call.name},
|
|
5878
|
+
${encodeJson(input.call.input)},
|
|
5879
|
+
${encodeJson(metadata8(input.call.metadata))},
|
|
5880
|
+
${timestampParam(sql8, input.createdAt)}
|
|
5881
|
+
)
|
|
5882
|
+
`;
|
|
5883
|
+
const insertCall = sql8.onDialectOrElse({
|
|
5884
|
+
mysql: () => (tenantId2, input) => sql8.withTransaction(Effect20.gen(function* () {
|
|
5885
|
+
yield* insertCallStatement(tenantId2, input);
|
|
5886
|
+
return yield* selectCallByKey(tenantId2, input.call.id);
|
|
5887
|
+
})),
|
|
5888
|
+
orElse: () => (tenantId2, input) => sql8`
|
|
5889
|
+
${insertCallStatement(tenantId2, input)}
|
|
5890
|
+
RETURNING ${callColumns}
|
|
5891
|
+
`
|
|
5892
|
+
});
|
|
5893
|
+
const insertResultStatement = (tenantId2, input) => sql8`
|
|
5894
|
+
INSERT INTO relay_tool_results (
|
|
5895
|
+
tenant_id, ${resultColumns}
|
|
5896
|
+
)
|
|
5897
|
+
VALUES (
|
|
5898
|
+
${tenantId2},
|
|
5899
|
+
${input.result.call_id},
|
|
5900
|
+
${encodeJson(input.result.output)},
|
|
5901
|
+
${input.result.error ?? null},
|
|
5902
|
+
${encodeJson(metadata8(input.result.metadata))},
|
|
5903
|
+
${timestampParam(sql8, input.createdAt)}
|
|
5904
|
+
)
|
|
5905
|
+
`;
|
|
5906
|
+
const insertResult = sql8.onDialectOrElse({
|
|
5907
|
+
mysql: () => (tenantId2, input) => sql8.withTransaction(Effect20.gen(function* () {
|
|
5908
|
+
yield* insertResultStatement(tenantId2, input);
|
|
5909
|
+
return yield* selectResultByKey(tenantId2, input.result.call_id);
|
|
5910
|
+
})),
|
|
5911
|
+
orElse: () => (tenantId2, input) => sql8`
|
|
5912
|
+
${insertResultStatement(tenantId2, input)}
|
|
5913
|
+
RETURNING ${resultColumns}
|
|
5914
|
+
`
|
|
5915
|
+
});
|
|
5602
5916
|
const recordCall = Effect20.fn("ToolCallRepository.recordCall")(function* (input) {
|
|
5603
5917
|
const tenantId2 = yield* current;
|
|
5604
|
-
const
|
|
5605
|
-
if (
|
|
5918
|
+
const existing = yield* selectCallByKey(tenantId2, input.call.id).pipe(Effect20.mapError(toRepositoryError12));
|
|
5919
|
+
if (existing[0] !== undefined)
|
|
5606
5920
|
return yield* Effect20.fail(new DuplicateToolCall({ id: input.call.id }));
|
|
5607
|
-
const rows = yield*
|
|
5921
|
+
const rows = yield* insertCall(tenantId2, input).pipe(Effect20.mapError(toRepositoryError12));
|
|
5608
5922
|
const row = rows[0];
|
|
5609
5923
|
if (row === undefined) {
|
|
5610
5924
|
return yield* Effect20.fail(new ToolCallRepositoryError({ message: "Tool call insert returned no row" }));
|
|
5611
5925
|
}
|
|
5612
|
-
return toCallRecord(row);
|
|
5926
|
+
return toCallRecord(yield* decodeCallRow(row));
|
|
5613
5927
|
});
|
|
5614
5928
|
const getCall = Effect20.fn("ToolCallRepository.getCall")(function* (id2) {
|
|
5615
5929
|
const tenantId2 = yield* current;
|
|
5616
|
-
const rows = yield*
|
|
5617
|
-
return rows[0] === undefined ? undefined : toCallRecord(rows[0]);
|
|
5930
|
+
const rows = yield* selectCallByKey(tenantId2, id2).pipe(Effect20.mapError(toRepositoryError12));
|
|
5931
|
+
return rows[0] === undefined ? undefined : toCallRecord(yield* decodeCallRow(rows[0]));
|
|
5618
5932
|
});
|
|
5619
5933
|
const listCalls = Effect20.fn("ToolCallRepository.listCalls")(function* (executionId) {
|
|
5620
5934
|
const tenantId2 = yield* current;
|
|
5621
|
-
const rows = yield*
|
|
5622
|
-
|
|
5935
|
+
const rows = yield* sql8`
|
|
5936
|
+
SELECT ${callColumns}
|
|
5937
|
+
FROM relay_tool_calls
|
|
5938
|
+
WHERE tenant_id = ${tenantId2} AND execution_id = ${executionId}
|
|
5939
|
+
ORDER BY created_at ASC
|
|
5940
|
+
`.pipe(Effect20.mapError(toRepositoryError12));
|
|
5941
|
+
const decoded = yield* Effect20.forEach(rows, decodeCallRow);
|
|
5942
|
+
return decoded.map(toCallRecord);
|
|
5623
5943
|
});
|
|
5624
5944
|
const recordResult = Effect20.fn("ToolCallRepository.recordResult")(function* (input) {
|
|
5625
5945
|
const tenantId2 = yield* current;
|
|
5626
|
-
const callRows = yield*
|
|
5946
|
+
const callRows = yield* selectCallByKey(tenantId2, input.result.call_id).pipe(Effect20.mapError(toRepositoryError12));
|
|
5627
5947
|
if (callRows[0] === undefined)
|
|
5628
5948
|
return yield* Effect20.fail(new ToolCallNotFound({ id: input.result.call_id }));
|
|
5629
|
-
const
|
|
5630
|
-
if (
|
|
5949
|
+
const existing = yield* selectResultByKey(tenantId2, input.result.call_id).pipe(Effect20.mapError(toRepositoryError12));
|
|
5950
|
+
if (existing[0] !== undefined) {
|
|
5631
5951
|
return yield* Effect20.fail(new DuplicateToolResult({ call_id: input.result.call_id }));
|
|
5632
5952
|
}
|
|
5633
|
-
const rows = yield*
|
|
5953
|
+
const rows = yield* insertResult(tenantId2, input).pipe(Effect20.mapError(toRepositoryError12));
|
|
5634
5954
|
const row = rows[0];
|
|
5635
5955
|
if (row === undefined) {
|
|
5636
5956
|
return yield* Effect20.fail(new ToolCallRepositoryError({ message: "Tool result insert returned no row" }));
|
|
5637
5957
|
}
|
|
5638
|
-
return toResultRecord(row);
|
|
5958
|
+
return toResultRecord(yield* decodeResultRow(row));
|
|
5639
5959
|
});
|
|
5640
5960
|
const getResult = Effect20.fn("ToolCallRepository.getResult")(function* (callId) {
|
|
5641
5961
|
const tenantId2 = yield* current;
|
|
5642
|
-
const rows = yield*
|
|
5643
|
-
return rows[0] === undefined ? undefined : toResultRecord(rows[0]);
|
|
5962
|
+
const rows = yield* selectResultByKey(tenantId2, callId).pipe(Effect20.mapError(toRepositoryError12));
|
|
5963
|
+
return rows[0] === undefined ? undefined : toResultRecord(yield* decodeResultRow(rows[0]));
|
|
5644
5964
|
});
|
|
5645
5965
|
return Service20.of({ recordCall, getCall, listCalls, recordResult, getResult });
|
|
5646
5966
|
}));
|
|
@@ -5720,7 +6040,7 @@ __export(exports_workspace_lease_repository, {
|
|
|
5720
6040
|
Service: () => Service21,
|
|
5721
6041
|
DuplicateWorkspaceLease: () => DuplicateWorkspaceLease
|
|
5722
6042
|
});
|
|
5723
|
-
import { eq as
|
|
6043
|
+
import { eq as eq6, notInArray } from "drizzle-orm";
|
|
5724
6044
|
import { Context as Context21, Effect as Effect21, Layer as Layer21, Schema as Schema31 } from "effect";
|
|
5725
6045
|
class WorkspaceLeaseRepositoryError extends Schema31.TaggedErrorClass()("WorkspaceLeaseRepositoryError", {
|
|
5726
6046
|
message: Schema31.String
|
|
@@ -5790,8 +6110,8 @@ var toSnapshotRecord = (row) => ({
|
|
|
5790
6110
|
metadata: row.metadataJson,
|
|
5791
6111
|
created_at: fromPgDate(row.createdAt)
|
|
5792
6112
|
});
|
|
5793
|
-
var
|
|
5794
|
-
var updateLease = (db, tenantId2, executionId, values) =>
|
|
6113
|
+
var mapDatabaseError5 = (effect) => effect.pipe(Effect21.mapError((error) => new WorkspaceLeaseRepositoryError({ message: String(error) })));
|
|
6114
|
+
var updateLease = (db, tenantId2, executionId, values) => mapDatabaseError5(db.update(relayWorkspaceLeases).set(values).where(predicate(tenantId2, relayWorkspaceLeases.tenantId, eq6(relayWorkspaceLeases.executionId, executionId))).returning()).pipe(Effect21.flatMap((rows) => {
|
|
5795
6115
|
const row = rows[0];
|
|
5796
6116
|
if (row === undefined)
|
|
5797
6117
|
return Effect21.fail(new WorkspaceLeaseNotFound({ execution_id: executionId }));
|
|
@@ -5801,16 +6121,16 @@ var layer21 = Layer21.effect(Service21, Effect21.gen(function* () {
|
|
|
5801
6121
|
const db = yield* Service;
|
|
5802
6122
|
const getByExecution = Effect21.fn("WorkspaceLeaseRepository.getByExecution")(function* (id2) {
|
|
5803
6123
|
const tenantId2 = yield* current;
|
|
5804
|
-
const rows = yield*
|
|
6124
|
+
const rows = yield* mapDatabaseError5(db.select().from(relayWorkspaceLeases).where(predicate(tenantId2, relayWorkspaceLeases.tenantId, eq6(relayWorkspaceLeases.executionId, id2))).limit(1));
|
|
5805
6125
|
return rows[0] === undefined ? undefined : toLeaseRecord(rows[0]);
|
|
5806
6126
|
});
|
|
5807
6127
|
const plan = Effect21.fn("WorkspaceLeaseRepository.plan")(function* (input) {
|
|
5808
6128
|
const tenantId2 = yield* current;
|
|
5809
|
-
const existing = yield*
|
|
6129
|
+
const existing = yield* mapDatabaseError5(db.select().from(relayWorkspaceLeases).where(predicate(tenantId2, relayWorkspaceLeases.tenantId, eq6(relayWorkspaceLeases.executionId, input.executionId), notInArray(relayWorkspaceLeases.status, [...terminalStatuses]))).limit(1));
|
|
5810
6130
|
if (existing[0] !== undefined) {
|
|
5811
6131
|
return yield* Effect21.fail(new DuplicateWorkspaceLease({ execution_id: input.executionId }));
|
|
5812
6132
|
}
|
|
5813
|
-
const rows = yield*
|
|
6133
|
+
const rows = yield* mapDatabaseError5(db.insert(relayWorkspaceLeases).values(toPlanInsert(tenantId2, input)).returning());
|
|
5814
6134
|
const row = rows[0];
|
|
5815
6135
|
if (row === undefined) {
|
|
5816
6136
|
return yield* Effect21.fail(new WorkspaceLeaseRepositoryError({ message: "Workspace lease insert returned no row" }));
|
|
@@ -5842,11 +6162,11 @@ var layer21 = Layer21.effect(Service21, Effect21.gen(function* () {
|
|
|
5842
6162
|
});
|
|
5843
6163
|
const recordSnapshot = Effect21.fn("WorkspaceLeaseRepository.recordSnapshot")(function* (input) {
|
|
5844
6164
|
const tenantId2 = yield* current;
|
|
5845
|
-
const leaseRows = yield*
|
|
6165
|
+
const leaseRows = yield* mapDatabaseError5(db.select().from(relayWorkspaceLeases).where(predicate(tenantId2, relayWorkspaceLeases.tenantId, eq6(relayWorkspaceLeases.executionId, input.executionId))).limit(1));
|
|
5846
6166
|
if (leaseRows[0] === undefined) {
|
|
5847
6167
|
return yield* Effect21.fail(new WorkspaceLeaseNotFound({ execution_id: input.executionId }));
|
|
5848
6168
|
}
|
|
5849
|
-
const rows = yield*
|
|
6169
|
+
const rows = yield* mapDatabaseError5(db.insert(relayWorkspaceSnapshots).values(toSnapshotInsert(tenantId2, input)).returning());
|
|
5850
6170
|
const row = rows[0];
|
|
5851
6171
|
if (row === undefined) {
|
|
5852
6172
|
return yield* Effect21.fail(new WorkspaceLeaseRepositoryError({ message: "Workspace snapshot insert returned no row" }));
|
|
@@ -6253,7 +6573,7 @@ __export(exports_agent_registry_service, {
|
|
|
6253
6573
|
AgentRegistryError: () => AgentRegistryError,
|
|
6254
6574
|
AgentDefinitionInvalid: () => AgentDefinitionInvalid
|
|
6255
6575
|
});
|
|
6256
|
-
import { Clock, Context as Context26, Crypto as Crypto2, Effect as Effect28, HashSet as HashSet4, Layer as Layer26, Option as Option7, Schema as Schema36 } from "effect";
|
|
6576
|
+
import { Clock as Clock2, Context as Context26, Crypto as Crypto2, Effect as Effect28, HashSet as HashSet4, Layer as Layer26, Option as Option7, Schema as Schema36 } from "effect";
|
|
6257
6577
|
|
|
6258
6578
|
// ../runtime/src/tool/tool-input-schema-digest.ts
|
|
6259
6579
|
import { Crypto, Effect as Effect24 } from "effect";
|
|
@@ -7210,7 +7530,7 @@ var layer24 = Layer26.effect(Service26, Effect28.gen(function* () {
|
|
|
7210
7530
|
return Service26.of({
|
|
7211
7531
|
register: Effect28.fn("AgentRegistry.register")(function* (input) {
|
|
7212
7532
|
yield* validateDefinition(input.definition);
|
|
7213
|
-
const now = yield*
|
|
7533
|
+
const now = yield* Clock2.currentTimeMillis;
|
|
7214
7534
|
const toolDefinitions = Option7.isNone(toolRuntime) ? [] : yield* toolRuntime.value.definitions;
|
|
7215
7535
|
const selectedToolNames = input.definition.tool_names.filter((toolName) => toolDefinitions.some((definition) => definition.name === toolName));
|
|
7216
7536
|
const crypto = yield* Effect28.serviceOption(Crypto2.Crypto);
|
|
@@ -9498,7 +9818,7 @@ var transferTools = (config) => (config.agent.handoff_targets ?? []).map((target
|
|
|
9498
9818
|
});
|
|
9499
9819
|
|
|
9500
9820
|
// ../runtime/src/memory/memory-service.ts
|
|
9501
|
-
import { Clock as
|
|
9821
|
+
import { Clock as Clock3, Context as Context45, Effect as Effect53, Layer as Layer46, Schema as Schema52 } from "effect";
|
|
9502
9822
|
import * as Ai13 from "effect/unstable/ai";
|
|
9503
9823
|
|
|
9504
9824
|
// ../runtime/src/model/embedding-model-service.ts
|
|
@@ -9734,7 +10054,7 @@ var make6 = (options = {}) => Effect53.gen(function* () {
|
|
|
9734
10054
|
return;
|
|
9735
10055
|
const subject = yield* decodeSubject(input.key.subject);
|
|
9736
10056
|
const embedding = yield* embed(models, text3, options);
|
|
9737
|
-
const createdAt = yield*
|
|
10057
|
+
const createdAt = yield* Clock3.currentTimeMillis;
|
|
9738
10058
|
yield* repository.upsert({
|
|
9739
10059
|
id: memoryId(input, text3),
|
|
9740
10060
|
agent: input.key.agent,
|
|
@@ -9901,7 +10221,7 @@ var resolve4 = Effect55.fn("SchemaRegistry.resolve.call")(function* (ref) {
|
|
|
9901
10221
|
});
|
|
9902
10222
|
|
|
9903
10223
|
// ../runtime/src/session/session-store-service.ts
|
|
9904
|
-
import { Clock as
|
|
10224
|
+
import { Clock as Clock4, Context as Context49, Effect as Effect56, Layer as Layer50, Ref as Ref15 } from "effect";
|
|
9905
10225
|
|
|
9906
10226
|
class Service36 extends Context49.Service()("@relayfx/runtime/RelaySessionStore") {
|
|
9907
10227
|
}
|
|
@@ -9948,7 +10268,7 @@ var make8 = Effect56.fn("RelaySessionStore.make")(function* (sessionId, entrySco
|
|
|
9948
10268
|
});
|
|
9949
10269
|
const append4 = Effect56.fn("RelaySessionStore.append")(function* (input) {
|
|
9950
10270
|
const current2 = yield* initialState2();
|
|
9951
|
-
const now = yield*
|
|
10271
|
+
const now = yield* Clock4.currentTimeMillis;
|
|
9952
10272
|
const entry = yield* repository.appendEntry({
|
|
9953
10273
|
id: exports_ids_schema.SessionEntryId.make(`${entryPrefix}${current2.next}`),
|
|
9954
10274
|
sessionId,
|
|
@@ -9964,7 +10284,7 @@ var make8 = Effect56.fn("RelaySessionStore.make")(function* (sessionId, entrySco
|
|
|
9964
10284
|
...leaf2 === undefined ? {} : { leafId: entryId(leaf2) }
|
|
9965
10285
|
}).pipe(Effect56.mapError(mapError)));
|
|
9966
10286
|
const setLeaf2 = Effect56.fn("RelaySessionStore.setLeaf")(function* (id2) {
|
|
9967
|
-
const now = yield*
|
|
10287
|
+
const now = yield* Clock4.currentTimeMillis;
|
|
9968
10288
|
return yield* repository.setLeaf({
|
|
9969
10289
|
sessionId,
|
|
9970
10290
|
id: id2 === null ? null : entryId(id2),
|
|
@@ -10236,7 +10556,7 @@ var assemble = Effect59.fn("PromptAssembler.assemble.call")(function* (input) {
|
|
|
10236
10556
|
var layer39 = exports_approvals.autoApprove;
|
|
10237
10557
|
|
|
10238
10558
|
// ../runtime/src/agent/relay-compaction.ts
|
|
10239
|
-
import { Clock as
|
|
10559
|
+
import { Clock as Clock5, Effect as Effect60, Layer as Layer54 } from "effect";
|
|
10240
10560
|
var checkpointId = (input) => `compaction:${input.executionId}:turn:${input.turn}:keep:${input.firstKeptEntryId}`;
|
|
10241
10561
|
var mapRepositoryError7 = (error) => new exports_compaction.CompactionError({ message: error.message, cause: error });
|
|
10242
10562
|
var sameCheckpointBoundary = (record2, input) => record2.firstKeptEntryId === input.firstKeptEntryId && record2.turn === input.turn;
|
|
@@ -10261,7 +10581,7 @@ var strategy = (config) => {
|
|
|
10261
10581
|
if (existing !== undefined)
|
|
10262
10582
|
return existing.summary;
|
|
10263
10583
|
const summary = yield* base.summarize(plan2, request);
|
|
10264
|
-
const createdAt = yield*
|
|
10584
|
+
const createdAt = yield* Clock5.currentTimeMillis;
|
|
10265
10585
|
const input = {
|
|
10266
10586
|
executionId: config.executionId,
|
|
10267
10587
|
checkpointId: id2,
|
|
@@ -10285,7 +10605,7 @@ var make9 = (config) => exports_compaction.make(strategy(config), defaultOptions
|
|
|
10285
10605
|
var layerFromEpoch = (epoch) => exports_instructions.layer(epoch.baseline.length === 0 ? [] : [exports_instructions.staticSource("relay:context-epoch", epoch.baseline)]);
|
|
10286
10606
|
|
|
10287
10607
|
// ../runtime/src/agent/relay-permissions.ts
|
|
10288
|
-
import { Clock as
|
|
10608
|
+
import { Clock as Clock6, Effect as Effect61, Equal as Equal2, Layer as Layer55, Option as Option19, Schema as Schema57 } from "effect";
|
|
10289
10609
|
var jsonValue4 = (value) => Schema57.decodeUnknownSync(exports_shared_schema.JsonValue)(value === undefined ? null : value);
|
|
10290
10610
|
var waitIdForToolCall = (toolCallId) => exports_ids_schema.WaitId.make(`wait:permission:${toolCallId}`);
|
|
10291
10611
|
var fallbackToolCallId = (request) => `${request.agentName}:${request.turn}:${request.tool}`;
|
|
@@ -10451,7 +10771,7 @@ var awaitAnswer = Effect61.fn("RelayPermissions.awaitAnswer")(function* (config,
|
|
|
10451
10771
|
return Option19.some(answer);
|
|
10452
10772
|
});
|
|
10453
10773
|
var rememberRule = Effect61.fn("RelayPermissions.rememberRule")(function* (config, rule) {
|
|
10454
|
-
const createdAt = yield*
|
|
10774
|
+
const createdAt = yield* Clock6.currentTimeMillis;
|
|
10455
10775
|
const decodedRule = yield* Schema57.decodeUnknownEffect(exports_agent_schema.PermissionRule)(rule).pipe(Effect61.mapError((error) => permissionError(error.message)));
|
|
10456
10776
|
yield* config.repository.remember({
|
|
10457
10777
|
agent: config.agentName,
|
|
@@ -10468,7 +10788,7 @@ var layer40 = (config) => Layer55.mergeAll(Layer55.succeed(exports_permissions.P
|
|
|
10468
10788
|
})));
|
|
10469
10789
|
|
|
10470
10790
|
// ../runtime/src/agent/relay-steering.ts
|
|
10471
|
-
import { Clock as
|
|
10791
|
+
import { Clock as Clock7, Effect as Effect62, Layer as Layer56, Schema as Schema58 } from "effect";
|
|
10472
10792
|
import * as Ai16 from "effect/unstable/ai";
|
|
10473
10793
|
var jsonValue5 = (value) => Schema58.decodeUnknownSync(exports_shared_schema.JsonValue)(value);
|
|
10474
10794
|
var stringifyJson2 = (value) => JSON.stringify(jsonValue5(value));
|
|
@@ -10534,7 +10854,7 @@ var drain2 = Effect62.fn("RelaySteering.drain")(function* (config, kind, mode) {
|
|
|
10534
10854
|
yield* appendIdempotentTo(config.eventLog, steeringReceivedEvent(config, kind, result.drain, result.messages, sequence));
|
|
10535
10855
|
return result.messages.map((message) => ({ prompt: promptForContent(message.content) }));
|
|
10536
10856
|
});
|
|
10537
|
-
var append4 = (config, kind, message) =>
|
|
10857
|
+
var append4 = (config, kind, message) => Clock7.currentTimeMillis.pipe(Effect62.flatMap((createdAt) => config.repository.append({
|
|
10538
10858
|
executionId: config.executionId,
|
|
10539
10859
|
kind,
|
|
10540
10860
|
content: contentFromMessage(message),
|
|
@@ -11378,7 +11698,7 @@ __export(exports_skill_registry_service, {
|
|
|
11378
11698
|
SkillDefinitionInvalid: () => SkillDefinitionInvalid,
|
|
11379
11699
|
Service: () => Service42
|
|
11380
11700
|
});
|
|
11381
|
-
import { Clock as
|
|
11701
|
+
import { Clock as Clock8, Context as Context55, Effect as Effect68, Layer as Layer61, Schema as Schema62 } from "effect";
|
|
11382
11702
|
|
|
11383
11703
|
class SkillDefinitionInvalid extends Schema62.TaggedErrorClass()("SkillDefinitionInvalid", {
|
|
11384
11704
|
message: Schema62.String
|
|
@@ -11456,7 +11776,7 @@ var layer45 = Layer61.effect(Service42, Effect68.gen(function* () {
|
|
|
11456
11776
|
return Service42.of({
|
|
11457
11777
|
register: Effect68.fn("SkillRegistry.register")(function* (input) {
|
|
11458
11778
|
yield* validateDefinition2(input.definition);
|
|
11459
|
-
const now = yield*
|
|
11779
|
+
const now = yield* Clock8.currentTimeMillis;
|
|
11460
11780
|
const record2 = yield* repository.put({ id: input.id, definition: input.definition, now }).pipe(Effect68.mapError(mapRepositoryError8));
|
|
11461
11781
|
return { record: toPublicRecord2(record2) };
|
|
11462
11782
|
}),
|
|
@@ -11477,7 +11797,7 @@ var layer45 = Layer61.effect(Service42, Effect68.gen(function* () {
|
|
|
11477
11797
|
return { records: records.map(toPublicRevisionRecord2) };
|
|
11478
11798
|
}),
|
|
11479
11799
|
pinExecution: Effect68.fn("SkillRegistry.pinExecution")(function* (input) {
|
|
11480
|
-
const now = yield*
|
|
11800
|
+
const now = yield* Clock8.currentTimeMillis;
|
|
11481
11801
|
const records = yield* repository.pinExecution({
|
|
11482
11802
|
executionId: input.execution_id,
|
|
11483
11803
|
skillDefinitionIds: input.skill_definition_ids,
|
|
@@ -11555,7 +11875,7 @@ __export(exports_execution_service, {
|
|
|
11555
11875
|
Service: () => Service43,
|
|
11556
11876
|
ExecutionServiceError: () => ExecutionServiceError
|
|
11557
11877
|
});
|
|
11558
|
-
import { Clock as
|
|
11878
|
+
import { Clock as Clock9, Context as Context56, Effect as Effect69, Layer as Layer62, Option as Option24, Schema as Schema63, Stream as Stream8 } from "effect";
|
|
11559
11879
|
import { ShardingConfig } from "effect/unstable/cluster";
|
|
11560
11880
|
class ExecutionServiceError extends Schema63.TaggedErrorClass()("ExecutionServiceError", {
|
|
11561
11881
|
message: Schema63.String,
|
|
@@ -11636,7 +11956,7 @@ var nextEventSequence2 = Effect69.fn("ExecutionService.nextEventSequence")(funct
|
|
|
11636
11956
|
});
|
|
11637
11957
|
var childRunBaseInput = Effect69.fn("ExecutionService.childRunBaseInput")(function* (eventLog, input) {
|
|
11638
11958
|
const eventSequence = yield* nextEventSequence2(eventLog, input);
|
|
11639
|
-
const createdAt = input.created_at ?? (yield*
|
|
11959
|
+
const createdAt = input.created_at ?? (yield* Clock9.currentTimeMillis);
|
|
11640
11960
|
return {
|
|
11641
11961
|
childExecutionId: childExecutionId2(input),
|
|
11642
11962
|
executionId: input.execution_id,
|
|
@@ -13154,7 +13474,7 @@ __export(exports_scheduler_service, {
|
|
|
13154
13474
|
SchedulerError: () => SchedulerError,
|
|
13155
13475
|
ScheduleCronInvalid: () => ScheduleCronInvalid
|
|
13156
13476
|
});
|
|
13157
|
-
import { Clock as
|
|
13477
|
+
import { Clock as Clock10, Config as Config4, Context as Context60, Cron, Duration as Duration4, Effect as Effect75, Layer as Layer67, Random, Result as Result3, Schema as Schema69 } from "effect";
|
|
13158
13478
|
|
|
13159
13479
|
// ../runtime/src/wait/wait-signal.ts
|
|
13160
13480
|
var exports_wait_signal = {};
|
|
@@ -13293,7 +13613,7 @@ var make14 = Effect75.gen(function* () {
|
|
|
13293
13613
|
const runOnce = Effect75.gen(function* () {
|
|
13294
13614
|
let dispatched = 0;
|
|
13295
13615
|
while (true) {
|
|
13296
|
-
const now = yield*
|
|
13616
|
+
const now = yield* Clock10.currentTimeMillis;
|
|
13297
13617
|
const claimed = yield* schedules.claimDue({ workerId, now, claimExpiresAt: now + claimTtlMillis }).pipe(Effect75.mapError(toSchedulerError));
|
|
13298
13618
|
if (claimed === undefined)
|
|
13299
13619
|
return dispatched;
|
|
@@ -13907,7 +14227,7 @@ var guard = Effect77.fn("ActivityVersionRegistry.guard")(function* (input) {
|
|
|
13907
14227
|
}));
|
|
13908
14228
|
});
|
|
13909
14229
|
// src/client.ts
|
|
13910
|
-
import { Clock as
|
|
14230
|
+
import { Clock as Clock11, Context as Context62, Effect as Effect78, Layer as Layer69, Option as Option28, Schema as Schema72, SchemaGetter, SchemaIssue, Stream as Stream10 } from "effect";
|
|
13911
14231
|
import { EntityId, ShardId, Sharding as Sharding2, ShardingConfig as ShardingConfig3 } from "effect/unstable/cluster";
|
|
13912
14232
|
|
|
13913
14233
|
class ClientError extends Schema72.TaggedErrorClass()("ClientError", {
|
|
@@ -14375,7 +14695,7 @@ var layerFromRuntime = Layer69.effect(Service49, Effect78.gen(function* () {
|
|
|
14375
14695
|
const context = yield* exports_child_run_service.resolveForDispatch(input).pipe(Effect78.mapError((error) => new ClientError({ message: error._tag })));
|
|
14376
14696
|
const pin = yield* parentDefinitionPin(executionRepository, input.execution_id);
|
|
14377
14697
|
const definition = yield* exports_child_run_service.childDefinition(pin.agentDefinitionSnapshot, context).pipe(Effect78.mapError((error) => new ClientError({ message: error._tag })));
|
|
14378
|
-
const createdAt = input.created_at ?? (yield*
|
|
14698
|
+
const createdAt = input.created_at ?? (yield* Clock11.currentTimeMillis);
|
|
14379
14699
|
const parentWaitId = input.wait === true ? yield* createChildJoinWait(waits, eventLog, input, accepted2, createdAt) : undefined;
|
|
14380
14700
|
const startPayload = childStartInput(input, accepted2, pin, definition, createdAt, parentWaitId);
|
|
14381
14701
|
const client2 = makeExecutionClient(startPayload.execution_id);
|
|
@@ -14418,7 +14738,7 @@ var layerFromRuntime = Layer69.effect(Service49, Effect78.gen(function* () {
|
|
|
14418
14738
|
if (input.cron_expr !== undefined) {
|
|
14419
14739
|
yield* exports_scheduler_service.parseCron(input.cron_expr).pipe(Effect78.mapError(toClientError));
|
|
14420
14740
|
}
|
|
14421
|
-
const createdAt = yield*
|
|
14741
|
+
const createdAt = yield* Clock11.currentTimeMillis;
|
|
14422
14742
|
const schedule = yield* schedules.create({
|
|
14423
14743
|
id: input.schedule_id,
|
|
14424
14744
|
kind: input.kind,
|