@byok-sdk/cloud-dataplane 0.8.0 → 0.9.0-rc.1
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 +341 -7
- package/dist/index.js.map +1 -1
- package/dist/runtime.d.ts +2 -2
- package/dist/runtime.js +338 -7
- package/dist/runtime.js.map +1 -1
- package/dist/sql/0014_agent_memory_projection.sql +134 -0
- package/dist/stores/agent-memory-projection.d.ts +34 -0
- package/dist/stores/index.d.ts +2 -0
- package/dist/tenant-erasure.d.ts +2 -2
- package/package.json +4 -4
package/dist/runtime.d.ts
CHANGED
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
*/
|
|
27
27
|
export { createByokPool } from './pool';
|
|
28
28
|
export type { ByokPoolOptions } from './pool';
|
|
29
|
-
export { PostgresDeviceDirectory, PostgresInboundDedupStore, PostgresNonceStore, PostgresPairingCodeStore, PostgresProofRequestReceiptStore, PostgresRequestReceiptStore, PostgresTaskAttemptStore, PostgresTaskCancellationStore, PostgresActivityStore, PostgresApprovalTimelineStore, PostgresDeviceAssertionReplayAuthority, createPostgresCloudStores, } from './stores/index';
|
|
30
|
-
export type { PostgresCloudStoreOptions, PostgresCloudStores, PostgresObjectStorageOptions, } from './stores/index';
|
|
29
|
+
export { PostgresDeviceDirectory, PostgresInboundDedupStore, PostgresNonceStore, PostgresPairingCodeStore, PostgresProofRequestReceiptStore, PostgresRequestReceiptStore, PostgresTaskAttemptStore, PostgresTaskCancellationStore, PostgresActivityStore, PostgresApprovalTimelineStore, PostgresDeviceAssertionReplayAuthority, PostgresAgentMemoryProjectionStore, createPostgresAgentMemoryProjectionStore, createPostgresCloudStores, } from './stores/index';
|
|
30
|
+
export type { PostgresCloudStoreOptions, PostgresCloudStores, PostgresObjectStorageOptions, PostgresAgentMemoryProjectionStoreOptions, } from './stores/index';
|
|
31
31
|
export { DEFAULT_MAX_ATTEMPTS, DEFAULT_PRESIGN_TTL_SECONDS, DEFAULT_RETRY_DELAY_MS, MAX_PRESIGN_TTL_SECONDS, MIN_PRESIGN_TTL_SECONDS, ObjectStoreRequestError, R2_BLOB_ERROR_CODES, R2BlobStoreError, R2CloudBlobStore, R2ObjectMaintenanceStore, } from './stores/index';
|
|
32
32
|
export type { ObjectStoreFetch, R2BlobErrorCode, R2BlobStoreOptions } from './stores/index';
|
|
33
33
|
export type { R2DeleteResult, R2ListedObject, R2ObjectMaintenance, R2ObjectMaintenanceOptions, R2ObjectPage, } from './stores/index';
|
package/dist/runtime.js
CHANGED
|
@@ -3,7 +3,7 @@ import { DEDUP_RING_CAPACITY, NONCE_TTL_MS, validateActivityAppend, projectTimel
|
|
|
3
3
|
import { contentHash, ByokCoreError, assertCanonicalTimestamp, isContentHash, tenantObjectKey, objectKeyPrefix, CoreConflictError, isLegalBoardTransition, checkSkillPackManifest, checkSkillPackEntry, SKILL_PACK_ENTRY_PATH, SKILL_PACK_MANIFEST_SCHEMA_ID } from '@byok-sdk/core';
|
|
4
4
|
import { AwsClient } from 'aws4fetch';
|
|
5
5
|
import { XMLParser } from 'fast-xml-parser';
|
|
6
|
-
import { AgentEgressReliablePayloadSchema } from '@byok-sdk/protocol';
|
|
6
|
+
import { AgentMemoryProjectionMutationSchema, AgentMemoryProjectionReceiptSchema, AGENT_MEMORY_PROJECTION_MAX_ORDERING_VALUE, AgentMemoryProjectionEraseResultSchema, AGENT_MEMORY_PROJECTION_MAX_REDACTED_BYTES, AgentEgressReliablePayloadSchema } from '@byok-sdk/protocol';
|
|
7
7
|
|
|
8
8
|
// src/pool.ts
|
|
9
9
|
var defaultTypeParser = pg.types.getTypeParser;
|
|
@@ -1928,6 +1928,337 @@ var PostgresAgentEgressStore = class {
|
|
|
1928
1928
|
return row === void 0 ? void 0 : toRecord2(row);
|
|
1929
1929
|
}
|
|
1930
1930
|
};
|
|
1931
|
+
var RECEIPT_COLUMNS = [
|
|
1932
|
+
"tenant_id",
|
|
1933
|
+
"agent_id",
|
|
1934
|
+
"writer_epoch",
|
|
1935
|
+
"source_seq",
|
|
1936
|
+
"mutation_id",
|
|
1937
|
+
"device_id",
|
|
1938
|
+
"task_id",
|
|
1939
|
+
"agent_profile_revision",
|
|
1940
|
+
"session_ref",
|
|
1941
|
+
"runtime_id",
|
|
1942
|
+
"grant_ref",
|
|
1943
|
+
"policy_revision",
|
|
1944
|
+
"redacted_hash",
|
|
1945
|
+
"redacted_byte_count",
|
|
1946
|
+
"metering_receipt_id",
|
|
1947
|
+
"recorded_at"
|
|
1948
|
+
].join(", ");
|
|
1949
|
+
var PostgresAgentMemoryProjectionStore = class {
|
|
1950
|
+
#pool;
|
|
1951
|
+
#clock;
|
|
1952
|
+
#crypto;
|
|
1953
|
+
constructor(options) {
|
|
1954
|
+
this.#pool = options.pool;
|
|
1955
|
+
this.#clock = options.clock;
|
|
1956
|
+
this.#crypto = options.crypto;
|
|
1957
|
+
}
|
|
1958
|
+
async commit(input) {
|
|
1959
|
+
const mutation = AgentMemoryProjectionMutationSchema.parse(input.mutation);
|
|
1960
|
+
await this.#assertRedactedSnapshot(
|
|
1961
|
+
input.redactedBytes,
|
|
1962
|
+
mutation.snapshot.redactedBytes,
|
|
1963
|
+
mutation.snapshot.redactedByteCount,
|
|
1964
|
+
mutation.snapshot.redactedHash
|
|
1965
|
+
);
|
|
1966
|
+
const client = await this.#pool.connect();
|
|
1967
|
+
try {
|
|
1968
|
+
await client.query("BEGIN");
|
|
1969
|
+
await lockAgentMutation(client, input.tenantId, mutation.agentRef.agentId);
|
|
1970
|
+
const receipt = await this.#readReceipt(client, input.tenantId, mutation.agentRef.agentId, mutation.writerEpoch, mutation.sourceSeq);
|
|
1971
|
+
if (receipt !== void 0) {
|
|
1972
|
+
if (!sameReceiptBinding(receipt, input, mutation)) {
|
|
1973
|
+
throw replayMismatch();
|
|
1974
|
+
}
|
|
1975
|
+
await client.query("COMMIT");
|
|
1976
|
+
return toReceipt3(receipt, "idempotent");
|
|
1977
|
+
}
|
|
1978
|
+
const existingMutation = await this.#readReceiptByMutationId(
|
|
1979
|
+
client,
|
|
1980
|
+
input.tenantId,
|
|
1981
|
+
mutation.agentRef.agentId,
|
|
1982
|
+
mutation.writerEpoch,
|
|
1983
|
+
mutation.mutationId
|
|
1984
|
+
);
|
|
1985
|
+
if (existingMutation !== void 0) throw replayMismatch();
|
|
1986
|
+
const head = await this.#readHeadForUpdate(client, input.tenantId, mutation.agentRef.agentId);
|
|
1987
|
+
const fence = await this.#readEraseFenceForUpdate(client, input.tenantId, mutation.agentRef.agentId);
|
|
1988
|
+
assertNextMutation(head, fence, mutation.writerEpoch, mutation.sourceSeq);
|
|
1989
|
+
const now = this.#clock.now();
|
|
1990
|
+
const meteringReceiptId = this.#crypto.randomUuid();
|
|
1991
|
+
await client.query(
|
|
1992
|
+
`INSERT INTO agent_memory_projection_metering_receipt (${RECEIPT_COLUMNS})
|
|
1993
|
+
VALUES ($1, $2, $3, $4, $5::uuid, $6, $7, $8, $9, $10, $11, $12, $13, $14::integer, $15::uuid, $16)`,
|
|
1994
|
+
[
|
|
1995
|
+
input.tenantId,
|
|
1996
|
+
mutation.agentRef.agentId,
|
|
1997
|
+
mutation.writerEpoch,
|
|
1998
|
+
mutation.sourceSeq,
|
|
1999
|
+
mutation.mutationId,
|
|
2000
|
+
input.deviceId,
|
|
2001
|
+
mutation.taskId,
|
|
2002
|
+
mutation.agentRef.profileRevision,
|
|
2003
|
+
mutation.sessionRef,
|
|
2004
|
+
mutation.runtimeId,
|
|
2005
|
+
mutation.grantRef,
|
|
2006
|
+
mutation.policyRevision,
|
|
2007
|
+
mutation.snapshot.redactedHash,
|
|
2008
|
+
mutation.snapshot.redactedByteCount,
|
|
2009
|
+
meteringReceiptId,
|
|
2010
|
+
now
|
|
2011
|
+
]
|
|
2012
|
+
);
|
|
2013
|
+
await client.query(
|
|
2014
|
+
`INSERT INTO agent_memory_projection_head (
|
|
2015
|
+
tenant_id, agent_id, writer_epoch, source_seq, mutation_id,
|
|
2016
|
+
device_id, task_id, agent_profile_revision, session_ref, runtime_id,
|
|
2017
|
+
grant_ref, policy_revision, redacted_hash, redacted_snapshot,
|
|
2018
|
+
redacted_byte_count, committed_at
|
|
2019
|
+
) VALUES (
|
|
2020
|
+
$1, $2, $3, $4, $5::uuid,
|
|
2021
|
+
$6, $7, $8, $9, $10,
|
|
2022
|
+
$11, $12, $13, decode($14, 'base64'),
|
|
2023
|
+
$15::integer, $16
|
|
2024
|
+
)
|
|
2025
|
+
ON CONFLICT (tenant_id, agent_id) DO UPDATE SET
|
|
2026
|
+
writer_epoch = EXCLUDED.writer_epoch,
|
|
2027
|
+
source_seq = EXCLUDED.source_seq,
|
|
2028
|
+
mutation_id = EXCLUDED.mutation_id,
|
|
2029
|
+
device_id = EXCLUDED.device_id,
|
|
2030
|
+
task_id = EXCLUDED.task_id,
|
|
2031
|
+
agent_profile_revision = EXCLUDED.agent_profile_revision,
|
|
2032
|
+
session_ref = EXCLUDED.session_ref,
|
|
2033
|
+
runtime_id = EXCLUDED.runtime_id,
|
|
2034
|
+
grant_ref = EXCLUDED.grant_ref,
|
|
2035
|
+
policy_revision = EXCLUDED.policy_revision,
|
|
2036
|
+
redacted_hash = EXCLUDED.redacted_hash,
|
|
2037
|
+
redacted_snapshot = EXCLUDED.redacted_snapshot,
|
|
2038
|
+
redacted_byte_count = EXCLUDED.redacted_byte_count,
|
|
2039
|
+
committed_at = EXCLUDED.committed_at`,
|
|
2040
|
+
[
|
|
2041
|
+
input.tenantId,
|
|
2042
|
+
mutation.agentRef.agentId,
|
|
2043
|
+
mutation.writerEpoch,
|
|
2044
|
+
mutation.sourceSeq,
|
|
2045
|
+
mutation.mutationId,
|
|
2046
|
+
input.deviceId,
|
|
2047
|
+
mutation.taskId,
|
|
2048
|
+
mutation.agentRef.profileRevision,
|
|
2049
|
+
mutation.sessionRef,
|
|
2050
|
+
mutation.runtimeId,
|
|
2051
|
+
mutation.grantRef,
|
|
2052
|
+
mutation.policyRevision,
|
|
2053
|
+
mutation.snapshot.redactedHash,
|
|
2054
|
+
toBase64(input.redactedBytes),
|
|
2055
|
+
mutation.snapshot.redactedByteCount,
|
|
2056
|
+
now
|
|
2057
|
+
]
|
|
2058
|
+
);
|
|
2059
|
+
await client.query("COMMIT");
|
|
2060
|
+
return AgentMemoryProjectionReceiptSchema.parse({
|
|
2061
|
+
outcome: "accepted",
|
|
2062
|
+
tenantId: input.tenantId,
|
|
2063
|
+
deviceId: input.deviceId,
|
|
2064
|
+
taskId: mutation.taskId,
|
|
2065
|
+
agentRef: mutation.agentRef,
|
|
2066
|
+
sessionRef: mutation.sessionRef,
|
|
2067
|
+
runtimeId: mutation.runtimeId,
|
|
2068
|
+
grantRef: mutation.grantRef,
|
|
2069
|
+
writerEpoch: mutation.writerEpoch,
|
|
2070
|
+
sourceSeq: mutation.sourceSeq,
|
|
2071
|
+
mutationId: mutation.mutationId,
|
|
2072
|
+
policyRevision: mutation.policyRevision,
|
|
2073
|
+
redactedHash: mutation.snapshot.redactedHash,
|
|
2074
|
+
redactedByteCount: mutation.snapshot.redactedByteCount,
|
|
2075
|
+
metering: {
|
|
2076
|
+
meteringReceiptId,
|
|
2077
|
+
acceptedRedactedBytes: mutation.snapshot.redactedByteCount,
|
|
2078
|
+
recordedAt: now.toISOString()
|
|
2079
|
+
}
|
|
2080
|
+
});
|
|
2081
|
+
} catch (cause) {
|
|
2082
|
+
await rollback(client);
|
|
2083
|
+
throw cause;
|
|
2084
|
+
} finally {
|
|
2085
|
+
client.release();
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2088
|
+
/** Delete body/receipts but retain a body-free epoch fence under one source lock. */
|
|
2089
|
+
async erase(input) {
|
|
2090
|
+
const client = await this.#pool.connect();
|
|
2091
|
+
try {
|
|
2092
|
+
await client.query("BEGIN");
|
|
2093
|
+
await lockAgentMutation(client, input.tenantId, input.agentId);
|
|
2094
|
+
const head = await this.#readHeadForUpdate(client, input.tenantId, input.agentId);
|
|
2095
|
+
const fence = await this.#readEraseFenceForUpdate(client, input.tenantId, input.agentId);
|
|
2096
|
+
const nextWriterEpoch = Math.max(fence?.next_writer_epoch ?? 1, (head?.writer_epoch ?? 0) + 1);
|
|
2097
|
+
if (nextWriterEpoch > AGENT_MEMORY_PROJECTION_MAX_ORDERING_VALUE) {
|
|
2098
|
+
throw new ByokCloudError("agent_memory_projection_epoch_exhausted", "The memory projection writerEpoch cannot advance after erase.");
|
|
2099
|
+
}
|
|
2100
|
+
await client.query(
|
|
2101
|
+
"DELETE FROM agent_memory_projection_metering_receipt WHERE tenant_id = $1 AND agent_id = $2",
|
|
2102
|
+
[input.tenantId, input.agentId]
|
|
2103
|
+
);
|
|
2104
|
+
await client.query(
|
|
2105
|
+
"DELETE FROM agent_memory_projection_head WHERE tenant_id = $1 AND agent_id = $2",
|
|
2106
|
+
[input.tenantId, input.agentId]
|
|
2107
|
+
);
|
|
2108
|
+
await client.query(
|
|
2109
|
+
`INSERT INTO agent_memory_projection_erase_fence (tenant_id, agent_id, next_writer_epoch, erased_at)
|
|
2110
|
+
VALUES ($1, $2, $3::integer, $4)
|
|
2111
|
+
ON CONFLICT (tenant_id, agent_id) DO UPDATE SET
|
|
2112
|
+
next_writer_epoch = GREATEST(agent_memory_projection_erase_fence.next_writer_epoch, EXCLUDED.next_writer_epoch),
|
|
2113
|
+
erased_at = EXCLUDED.erased_at`,
|
|
2114
|
+
[input.tenantId, input.agentId, nextWriterEpoch, this.#clock.now()]
|
|
2115
|
+
);
|
|
2116
|
+
await client.query("COMMIT");
|
|
2117
|
+
return AgentMemoryProjectionEraseResultSchema.parse({ nextWriterEpoch });
|
|
2118
|
+
} catch (cause) {
|
|
2119
|
+
await rollback(client);
|
|
2120
|
+
throw cause;
|
|
2121
|
+
} finally {
|
|
2122
|
+
client.release();
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
async #assertRedactedSnapshot(bytes, portableBody, byteCount, expectedHash) {
|
|
2126
|
+
if (bytes.byteLength !== byteCount || bytes.byteLength > AGENT_MEMORY_PROJECTION_MAX_REDACTED_BYTES) {
|
|
2127
|
+
throw hashMismatch("Decoded redacted snapshot bytes do not match redactedByteCount.");
|
|
2128
|
+
}
|
|
2129
|
+
if (portableBody !== toBase64Url(bytes)) {
|
|
2130
|
+
throw hashMismatch("Decoded redacted snapshot bytes do not match the portable redactedBytes body.");
|
|
2131
|
+
}
|
|
2132
|
+
if (await this.#crypto.sha256(bytes) !== expectedHash) {
|
|
2133
|
+
throw hashMismatch("Decoded redacted snapshot bytes do not match redactedHash.");
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
async #readHeadForUpdate(client, tenant, agentId) {
|
|
2137
|
+
const result = await client.query(
|
|
2138
|
+
`SELECT tenant_id, agent_id, writer_epoch, source_seq
|
|
2139
|
+
FROM agent_memory_projection_head
|
|
2140
|
+
WHERE tenant_id = $1 AND agent_id = $2
|
|
2141
|
+
FOR UPDATE`,
|
|
2142
|
+
[tenant, agentId]
|
|
2143
|
+
);
|
|
2144
|
+
return result.rows[0];
|
|
2145
|
+
}
|
|
2146
|
+
async #readEraseFenceForUpdate(client, tenant, agentId) {
|
|
2147
|
+
const result = await client.query(
|
|
2148
|
+
`SELECT next_writer_epoch
|
|
2149
|
+
FROM agent_memory_projection_erase_fence
|
|
2150
|
+
WHERE tenant_id = $1 AND agent_id = $2
|
|
2151
|
+
FOR UPDATE`,
|
|
2152
|
+
[tenant, agentId]
|
|
2153
|
+
);
|
|
2154
|
+
return result.rows[0];
|
|
2155
|
+
}
|
|
2156
|
+
async #readReceipt(client, tenant, agentId, writerEpoch, sourceSeq) {
|
|
2157
|
+
const result = await client.query(
|
|
2158
|
+
`SELECT ${RECEIPT_COLUMNS}
|
|
2159
|
+
FROM agent_memory_projection_metering_receipt
|
|
2160
|
+
WHERE tenant_id = $1 AND agent_id = $2 AND writer_epoch = $3 AND source_seq = $4`,
|
|
2161
|
+
[tenant, agentId, writerEpoch, sourceSeq]
|
|
2162
|
+
);
|
|
2163
|
+
return result.rows[0];
|
|
2164
|
+
}
|
|
2165
|
+
async #readReceiptByMutationId(client, tenant, agentId, writerEpoch, mutationId) {
|
|
2166
|
+
const result = await client.query(
|
|
2167
|
+
`SELECT ${RECEIPT_COLUMNS}
|
|
2168
|
+
FROM agent_memory_projection_metering_receipt
|
|
2169
|
+
WHERE tenant_id = $1 AND agent_id = $2 AND writer_epoch = $3 AND mutation_id = $4::uuid`,
|
|
2170
|
+
[tenant, agentId, writerEpoch, mutationId]
|
|
2171
|
+
);
|
|
2172
|
+
return result.rows[0];
|
|
2173
|
+
}
|
|
2174
|
+
};
|
|
2175
|
+
function createPostgresAgentMemoryProjectionStore(options) {
|
|
2176
|
+
return new PostgresAgentMemoryProjectionStore(options);
|
|
2177
|
+
}
|
|
2178
|
+
function assertNextMutation(head, fence, writerEpoch, sourceSeq) {
|
|
2179
|
+
if (fence !== void 0 && writerEpoch < fence.next_writer_epoch) {
|
|
2180
|
+
throw erasedEpoch();
|
|
2181
|
+
}
|
|
2182
|
+
if (head === void 0) {
|
|
2183
|
+
if (sourceSeq !== 1) throw sequenceGap("The first memory projection mutation must use sourceSeq 1.");
|
|
2184
|
+
return;
|
|
2185
|
+
}
|
|
2186
|
+
if (writerEpoch < head.writer_epoch) {
|
|
2187
|
+
throw new ByokCloudError("agent_memory_projection_stale_epoch", "The memory projection writerEpoch is stale.");
|
|
2188
|
+
}
|
|
2189
|
+
if (writerEpoch > head.writer_epoch) {
|
|
2190
|
+
if (sourceSeq !== 1) throw sequenceGap("A new memory projection writerEpoch must start at sourceSeq 1.");
|
|
2191
|
+
return;
|
|
2192
|
+
}
|
|
2193
|
+
if (sourceSeq !== head.source_seq + 1) {
|
|
2194
|
+
throw sequenceGap("A memory projection mutation must advance sourceSeq exactly by one.");
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
function sameReceiptBinding(receipt, input, mutation) {
|
|
2198
|
+
return receipt.tenant_id === input.tenantId && receipt.agent_id === mutation.agentRef.agentId && receipt.device_id === input.deviceId && receipt.task_id === mutation.taskId && receipt.agent_profile_revision === mutation.agentRef.profileRevision && receipt.session_ref === mutation.sessionRef && receipt.runtime_id === mutation.runtimeId && receipt.grant_ref === mutation.grantRef && receipt.writer_epoch === mutation.writerEpoch && receipt.source_seq === mutation.sourceSeq && receipt.mutation_id === mutation.mutationId && receipt.policy_revision === mutation.policyRevision && receipt.redacted_hash === mutation.snapshot.redactedHash && receipt.redacted_byte_count === mutation.snapshot.redactedByteCount;
|
|
2199
|
+
}
|
|
2200
|
+
function toReceipt3(row, outcome) {
|
|
2201
|
+
return AgentMemoryProjectionReceiptSchema.parse({
|
|
2202
|
+
outcome,
|
|
2203
|
+
tenantId: row.tenant_id,
|
|
2204
|
+
deviceId: row.device_id,
|
|
2205
|
+
taskId: row.task_id,
|
|
2206
|
+
agentRef: { agentId: row.agent_id, profileRevision: row.agent_profile_revision },
|
|
2207
|
+
sessionRef: row.session_ref,
|
|
2208
|
+
runtimeId: row.runtime_id,
|
|
2209
|
+
grantRef: row.grant_ref,
|
|
2210
|
+
writerEpoch: row.writer_epoch,
|
|
2211
|
+
sourceSeq: row.source_seq,
|
|
2212
|
+
mutationId: row.mutation_id,
|
|
2213
|
+
policyRevision: row.policy_revision,
|
|
2214
|
+
redactedHash: row.redacted_hash,
|
|
2215
|
+
redactedByteCount: row.redacted_byte_count,
|
|
2216
|
+
metering: {
|
|
2217
|
+
meteringReceiptId: row.metering_receipt_id,
|
|
2218
|
+
acceptedRedactedBytes: row.redacted_byte_count,
|
|
2219
|
+
recordedAt: row.recorded_at.toISOString()
|
|
2220
|
+
}
|
|
2221
|
+
});
|
|
2222
|
+
}
|
|
2223
|
+
async function lockAgentMutation(client, tenant, agentId) {
|
|
2224
|
+
await client.query(
|
|
2225
|
+
`SELECT pg_advisory_xact_lock(
|
|
2226
|
+
hashtextextended(length($1)::text || ':' || $1 || length($2)::text || ':' || $2, 0)
|
|
2227
|
+
)`,
|
|
2228
|
+
[tenant, agentId]
|
|
2229
|
+
);
|
|
2230
|
+
}
|
|
2231
|
+
function hashMismatch(message) {
|
|
2232
|
+
return new ByokCloudError("agent_memory_projection_hash_mismatch", message);
|
|
2233
|
+
}
|
|
2234
|
+
function sequenceGap(message) {
|
|
2235
|
+
return new ByokCloudError("agent_memory_projection_sequence_gap", message);
|
|
2236
|
+
}
|
|
2237
|
+
function erasedEpoch() {
|
|
2238
|
+
return new ByokCloudError("agent_memory_projection_erased_epoch", "The memory projection writerEpoch was erased and cannot be replayed.");
|
|
2239
|
+
}
|
|
2240
|
+
function replayMismatch() {
|
|
2241
|
+
return new ByokCloudError(
|
|
2242
|
+
"agent_memory_projection_replay_mismatch",
|
|
2243
|
+
"A memory projection epoch and source sequence already names a different immutable mutation."
|
|
2244
|
+
);
|
|
2245
|
+
}
|
|
2246
|
+
function toBase64(bytes) {
|
|
2247
|
+
const chunks = [];
|
|
2248
|
+
for (let offset = 0; offset < bytes.length; offset += 32 * 1024) {
|
|
2249
|
+
chunks.push(String.fromCharCode(...bytes.subarray(offset, offset + 32 * 1024)));
|
|
2250
|
+
}
|
|
2251
|
+
return btoa(chunks.join(""));
|
|
2252
|
+
}
|
|
2253
|
+
function toBase64Url(bytes) {
|
|
2254
|
+
return toBase64(bytes).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/u, "");
|
|
2255
|
+
}
|
|
2256
|
+
async function rollback(client) {
|
|
2257
|
+
try {
|
|
2258
|
+
await client.query("ROLLBACK");
|
|
2259
|
+
} catch {
|
|
2260
|
+
}
|
|
2261
|
+
}
|
|
1931
2262
|
|
|
1932
2263
|
// src/stores/device-assertion-replay.ts
|
|
1933
2264
|
var PostgresDeviceAssertionReplayAuthority = class {
|
|
@@ -3242,7 +3573,7 @@ function createPostgresCoreStores(options) {
|
|
|
3242
3573
|
};
|
|
3243
3574
|
}
|
|
3244
3575
|
var RECORD_COLUMNS2 = "tenant_id, kind, subject_id, rev, content_hash, byte_size, body_kind, body_inline, body_object_hash, label, request_id, written_at";
|
|
3245
|
-
var
|
|
3576
|
+
var RECEIPT_COLUMNS2 = "tenant_id, device_id, request_id, operation, resource, body_sha256, body_size, response_status, response_body, recorded_at";
|
|
3246
3577
|
function toBody2(row) {
|
|
3247
3578
|
return row.body_kind === "inline" ? { kind: "inline", body: row.body_inline ?? "" } : { kind: "object", hash: row.body_object_hash ?? "" };
|
|
3248
3579
|
}
|
|
@@ -3260,7 +3591,7 @@ function toRecord4(tenant, row) {
|
|
|
3260
3591
|
writtenAt: row.written_at
|
|
3261
3592
|
};
|
|
3262
3593
|
}
|
|
3263
|
-
function
|
|
3594
|
+
function toReceipt4(tenant, row) {
|
|
3264
3595
|
return {
|
|
3265
3596
|
tenantId: tenant,
|
|
3266
3597
|
deviceId: row.device_id,
|
|
@@ -3340,7 +3671,7 @@ var PostgresTruthCommitter = class {
|
|
|
3340
3671
|
snapshots: applied.slice(1).map((entry) => truthRecordMetadata(entry.record))
|
|
3341
3672
|
};
|
|
3342
3673
|
await client.query(
|
|
3343
|
-
`INSERT INTO proof_request_receipt (${
|
|
3674
|
+
`INSERT INTO proof_request_receipt (${RECEIPT_COLUMNS2})
|
|
3344
3675
|
VALUES ($1, $2, $3, $4, $5, $6, $7::bigint, 200, $8, $9)`,
|
|
3345
3676
|
[
|
|
3346
3677
|
tenant,
|
|
@@ -3399,12 +3730,12 @@ var PostgresTruthCommitter = class {
|
|
|
3399
3730
|
}
|
|
3400
3731
|
async #readReceipt(client, tenant, deviceId, requestId) {
|
|
3401
3732
|
const result = await client.query(
|
|
3402
|
-
`SELECT ${
|
|
3733
|
+
`SELECT ${RECEIPT_COLUMNS2} FROM proof_request_receipt
|
|
3403
3734
|
WHERE tenant_id = $1 AND device_id = $2 AND request_id = $3`,
|
|
3404
3735
|
[tenant, deviceId, requestId]
|
|
3405
3736
|
);
|
|
3406
3737
|
const row = result.rows[0];
|
|
3407
|
-
return row === void 0 ? void 0 :
|
|
3738
|
+
return row === void 0 ? void 0 : toReceipt4(tenant, row);
|
|
3408
3739
|
}
|
|
3409
3740
|
async #lockCurrentRecords(client, tenant, writes) {
|
|
3410
3741
|
const current = /* @__PURE__ */ new Map();
|
|
@@ -3694,6 +4025,6 @@ var PostgresTruthCommitter = class {
|
|
|
3694
4025
|
}
|
|
3695
4026
|
};
|
|
3696
4027
|
|
|
3697
|
-
export { DEFAULT_MAX_ATTEMPTS, DEFAULT_PRESIGN_TTL_SECONDS, DEFAULT_RETRY_DELAY_MS, MAX_PRESIGN_TTL_SECONDS, MIN_PRESIGN_TTL_SECONDS, ObjectStoreRequestError, PostgresActivityStore, PostgresApprovalTimelineStore, PostgresBoardStore, PostgresDeviceAssertionReplayAuthority, PostgresDeviceDirectory, PostgresInboundDedupStore, PostgresMailboxStore, PostgresNonceStore, PostgresObjectStore, PostgresPairingCodeStore, PostgresPresenceStore, PostgresProofRequestReceiptStore, PostgresQuotaStore, PostgresRequestReceiptStore, PostgresSkillPackStore, PostgresTaskAttemptStore, PostgresTaskCancellationStore, PostgresTruthCommitter, PostgresTruthStore, R2BlobStoreError, R2CloudBlobStore, R2ObjectMaintenanceStore, R2_BLOB_ERROR_CODES, createByokPool, createPostgresCloudStores, createPostgresCoreStores };
|
|
4028
|
+
export { DEFAULT_MAX_ATTEMPTS, DEFAULT_PRESIGN_TTL_SECONDS, DEFAULT_RETRY_DELAY_MS, MAX_PRESIGN_TTL_SECONDS, MIN_PRESIGN_TTL_SECONDS, ObjectStoreRequestError, PostgresActivityStore, PostgresAgentMemoryProjectionStore, PostgresApprovalTimelineStore, PostgresBoardStore, PostgresDeviceAssertionReplayAuthority, PostgresDeviceDirectory, PostgresInboundDedupStore, PostgresMailboxStore, PostgresNonceStore, PostgresObjectStore, PostgresPairingCodeStore, PostgresPresenceStore, PostgresProofRequestReceiptStore, PostgresQuotaStore, PostgresRequestReceiptStore, PostgresSkillPackStore, PostgresTaskAttemptStore, PostgresTaskCancellationStore, PostgresTruthCommitter, PostgresTruthStore, R2BlobStoreError, R2CloudBlobStore, R2ObjectMaintenanceStore, R2_BLOB_ERROR_CODES, createByokPool, createPostgresAgentMemoryProjectionStore, createPostgresCloudStores, createPostgresCoreStores };
|
|
3698
4029
|
//# sourceMappingURL=runtime.js.map
|
|
3699
4030
|
//# sourceMappingURL=runtime.js.map
|