@assemblyline-agents/postgres 0.1.0
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/LICENSE +21 -0
- package/README.md +19 -0
- package/dist/adapter-checkpoints.d.ts +6 -0
- package/dist/adapter-checkpoints.d.ts.map +1 -0
- package/dist/adapter-checkpoints.js +110 -0
- package/dist/adapter-checkpoints.js.map +1 -0
- package/dist/adapter-conversation-turns.d.ts +20 -0
- package/dist/adapter-conversation-turns.d.ts.map +1 -0
- package/dist/adapter-conversation-turns.js +216 -0
- package/dist/adapter-conversation-turns.js.map +1 -0
- package/dist/adapter-conversations.d.ts +46 -0
- package/dist/adapter-conversations.d.ts.map +1 -0
- package/dist/adapter-conversations.js +129 -0
- package/dist/adapter-conversations.js.map +1 -0
- package/dist/adapter-delivery.d.ts +13 -0
- package/dist/adapter-delivery.d.ts.map +1 -0
- package/dist/adapter-delivery.js +157 -0
- package/dist/adapter-delivery.js.map +1 -0
- package/dist/adapter-grants.d.ts +11 -0
- package/dist/adapter-grants.d.ts.map +1 -0
- package/dist/adapter-grants.js +125 -0
- package/dist/adapter-grants.js.map +1 -0
- package/dist/adapter-memory.d.ts +21 -0
- package/dist/adapter-memory.d.ts.map +1 -0
- package/dist/adapter-memory.js +181 -0
- package/dist/adapter-memory.js.map +1 -0
- package/dist/adapter-misc.d.ts +61 -0
- package/dist/adapter-misc.d.ts.map +1 -0
- package/dist/adapter-misc.js +127 -0
- package/dist/adapter-misc.js.map +1 -0
- package/dist/adapter-runs.d.ts +20 -0
- package/dist/adapter-runs.d.ts.map +1 -0
- package/dist/adapter-runs.js +193 -0
- package/dist/adapter-runs.js.map +1 -0
- package/dist/adapter-sandbox.d.ts +27 -0
- package/dist/adapter-sandbox.d.ts.map +1 -0
- package/dist/adapter-sandbox.js +267 -0
- package/dist/adapter-sandbox.js.map +1 -0
- package/dist/adapter-settings.d.ts +8 -0
- package/dist/adapter-settings.d.ts.map +1 -0
- package/dist/adapter-settings.js +38 -0
- package/dist/adapter-settings.js.map +1 -0
- package/dist/adapter-usage.d.ts +7 -0
- package/dist/adapter-usage.d.ts.map +1 -0
- package/dist/adapter-usage.js +243 -0
- package/dist/adapter-usage.js.map +1 -0
- package/dist/client-types.d.ts +6 -0
- package/dist/client-types.d.ts.map +1 -0
- package/dist/client-types.js +2 -0
- package/dist/client-types.js.map +1 -0
- package/dist/index.d.ts +208 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +424 -0
- package/dist/index.js.map +1 -0
- package/dist/migrations.d.ts +35 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +694 -0
- package/dist/migrations.js.map +1 -0
- package/dist/presets.d.ts +19 -0
- package/dist/presets.d.ts.map +1 -0
- package/dist/presets.js +31 -0
- package/dist/presets.js.map +1 -0
- package/dist/provider.d.ts +12 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +86 -0
- package/dist/provider.js.map +1 -0
- package/dist/row-mappers.d.ts +24 -0
- package/dist/row-mappers.d.ts.map +1 -0
- package/dist/row-mappers.js +450 -0
- package/dist/row-mappers.js.map +1 -0
- package/dist/sql-helpers.d.ts +46 -0
- package/dist/sql-helpers.d.ts.map +1 -0
- package/dist/sql-helpers.js +244 -0
- package/dist/sql-helpers.js.map +1 -0
- package/dist/stores.d.ts +40 -0
- package/dist/stores.d.ts.map +1 -0
- package/dist/stores.js +210 -0
- package/dist/stores.js.map +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type AdapterDefinition, type JsonObject } from "@assemblyline-agents/core";
|
|
2
|
+
export interface PostgresAdapter extends AdapterDefinition {
|
|
3
|
+
kind: "postgres";
|
|
4
|
+
}
|
|
5
|
+
export type PostgresProvider = "neon" | "railway" | "supabase" | "local" | "custom";
|
|
6
|
+
export interface RailwayPostgresOptions extends JsonObject {
|
|
7
|
+
/** Railway database service referenced by the deployed OpenEve service. */
|
|
8
|
+
databaseService?: string;
|
|
9
|
+
/** Create the Railway Postgres service when it does not exist. Defaults to true. */
|
|
10
|
+
provision?: boolean;
|
|
11
|
+
/** Railway's generated database certificate is self-signed. Defaults to false. */
|
|
12
|
+
sslRejectUnauthorized?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function postgresAdapter(options?: JsonObject): PostgresAdapter;
|
|
15
|
+
export declare function neonPostgres(options?: JsonObject): PostgresAdapter;
|
|
16
|
+
export declare function railwayPostgres(options?: RailwayPostgresOptions): PostgresAdapter;
|
|
17
|
+
export declare function supabasePostgres(options?: JsonObject): PostgresAdapter;
|
|
18
|
+
export declare function localPostgres(options?: JsonObject): PostgresAdapter;
|
|
19
|
+
//# sourceMappingURL=presets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presets.d.ts","sourceRoot":"","sources":["../src/presets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,iBAAiB,EAAE,KAAK,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAG7F,MAAM,WAAW,eAAgB,SAAQ,iBAAiB;IACxD,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEpF,MAAM,WAAW,sBAAuB,SAAQ,UAAU;IACxD,2EAA2E;IAC3E,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,oFAAoF;IACpF,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,kFAAkF;IAClF,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED,wBAAgB,eAAe,CAAC,OAAO,GAAE,UAAe,GAAG,eAAe,CAMzE;AAED,wBAAgB,YAAY,CAAC,OAAO,GAAE,UAAe,GAAG,eAAe,CAEtE;AAED,wBAAgB,eAAe,CAAC,OAAO,GAAE,sBAA2B,GAAG,eAAe,CASrF;AAED,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,UAAe,GAAG,eAAe,CAE1E;AAED,wBAAgB,aAAa,CAAC,OAAO,GAAE,UAAe,GAAG,eAAe,CAEvE"}
|
package/dist/presets.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { adapter } from "@assemblyline-agents/core";
|
|
2
|
+
import { POSTGRES_STATE_PROVIDER_METADATA as postgresStateProviderMetadata } from "./provider.js";
|
|
3
|
+
export function postgresAdapter(options = {}) {
|
|
4
|
+
const metadata = postgresStateProviderMetadata;
|
|
5
|
+
const definition = { ...adapter("postgres", options), kind: "postgres" };
|
|
6
|
+
if (metadata.requiredEnv)
|
|
7
|
+
definition.requiredEnv = metadata.requiredEnv;
|
|
8
|
+
if (metadata.capabilities)
|
|
9
|
+
definition.capabilities = metadata.capabilities;
|
|
10
|
+
return definition;
|
|
11
|
+
}
|
|
12
|
+
export function neonPostgres(options = {}) {
|
|
13
|
+
return postgresAdapter({ provider: "neon", connectionEnv: "DATABASE_URL", ...options });
|
|
14
|
+
}
|
|
15
|
+
export function railwayPostgres(options = {}) {
|
|
16
|
+
return postgresAdapter({
|
|
17
|
+
provider: "railway",
|
|
18
|
+
connectionEnv: "DATABASE_URL",
|
|
19
|
+
databaseService: "Postgres",
|
|
20
|
+
provision: true,
|
|
21
|
+
sslRejectUnauthorized: false,
|
|
22
|
+
...options
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export function supabasePostgres(options = {}) {
|
|
26
|
+
return postgresAdapter({ provider: "supabase", connectionEnv: "DATABASE_URL", ...options });
|
|
27
|
+
}
|
|
28
|
+
export function localPostgres(options = {}) {
|
|
29
|
+
return postgresAdapter({ provider: "local", connectionEnv: "DATABASE_URL", ssl: false, ...options });
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=presets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presets.js","sourceRoot":"","sources":["../src/presets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA2C,MAAM,2BAA2B,C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AAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AdapterProviderMetadata, JsonObject, ProviderModule } from "@assemblyline-agents/core";
|
|
2
|
+
import { type QueryClient } from "./index.js";
|
|
3
|
+
/** Metadata owned by this package; the core registry mirrors it as an offline default. */
|
|
4
|
+
export declare const POSTGRES_STATE_PROVIDER_METADATA: AdapterProviderMetadata;
|
|
5
|
+
/**
|
|
6
|
+
* Creates a `pg` Pool from environment variables. `OPENEVE_POSTGRES_CONNECTION_ENV`
|
|
7
|
+
* overrides which variable holds the connection string (default `DATABASE_URL`).
|
|
8
|
+
*/
|
|
9
|
+
export declare function createPostgresPoolFromEnv(env: Record<string, string | undefined>, options?: JsonObject): Promise<QueryClient>;
|
|
10
|
+
export declare const openeveProvider: ProviderModule;
|
|
11
|
+
export declare function optionalMigrationsFromOptions(options: JsonObject): boolean | string[] | undefined;
|
|
12
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,UAAU,EAA0B,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC7H,OAAO,EAAwB,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAEpE,0FAA0F;AAC1F,eAAO,MAAM,gCAAgC,EAAE,uBAc9C,CAAC;AAIF;;;GAGG;AACH,wBAAsB,yBAAyB,CAC7C,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,EACvC,OAAO,GAAE,UAAe,GACvB,OAAO,CAAC,WAAW,CAAC,CA2BtB;AAED,eAAO,MAAM,eAAe,EAAE,cAgB7B,CAAC;AAEF,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,GAAG,MAAM,EAAE,GAAG,SAAS,CAWjG"}
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { PostgresStateAdapter } from "./index.js";
|
|
2
|
+
/** Metadata owned by this package; the core registry mirrors it as an offline default. */
|
|
3
|
+
export const POSTGRES_STATE_PROVIDER_METADATA = {
|
|
4
|
+
kind: "postgres",
|
|
5
|
+
role: "state",
|
|
6
|
+
packageName: "@assemblyline-agents/postgres",
|
|
7
|
+
requiredEnv: ["DATABASE_URL"],
|
|
8
|
+
capabilities: ["durable-state", "migrations"],
|
|
9
|
+
setup: [
|
|
10
|
+
{
|
|
11
|
+
kind: "migration",
|
|
12
|
+
name: "postgres-schema",
|
|
13
|
+
required: true,
|
|
14
|
+
message: "Apply OpenEve state migrations to Postgres before production runs."
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Creates a `pg` Pool from environment variables. `OPENEVE_POSTGRES_CONNECTION_ENV`
|
|
20
|
+
* overrides which variable holds the connection string (default `DATABASE_URL`).
|
|
21
|
+
*/
|
|
22
|
+
export async function createPostgresPoolFromEnv(env, options = {}) {
|
|
23
|
+
const configuredConnectionEnv = typeof options.connectionEnv === "string" ? options.connectionEnv : undefined;
|
|
24
|
+
const connectionEnv = env.OPENEVE_POSTGRES_CONNECTION_ENV ?? configuredConnectionEnv ?? "DATABASE_URL";
|
|
25
|
+
const connectionString = env[connectionEnv];
|
|
26
|
+
if (!connectionString)
|
|
27
|
+
throw new Error(`Postgres state requires ${connectionEnv}.`);
|
|
28
|
+
const pg = await dynamicImport("pg");
|
|
29
|
+
const Pool = pg.Pool ?? pg.default?.Pool;
|
|
30
|
+
if (!Pool)
|
|
31
|
+
throw new Error("The pg package did not expose a Pool constructor.");
|
|
32
|
+
const sslDisabled = options.ssl === false || /(?:[?&]sslmode=disable)(?:&|$)/.test(connectionString);
|
|
33
|
+
const configuredRejectUnauthorized = typeof options.sslRejectUnauthorized === "boolean"
|
|
34
|
+
? options.sslRejectUnauthorized
|
|
35
|
+
: undefined;
|
|
36
|
+
const rejectUnauthorized = env.OPENEVE_POSTGRES_SSL_REJECT_UNAUTHORIZED !== undefined
|
|
37
|
+
? env.OPENEVE_POSTGRES_SSL_REJECT_UNAUTHORIZED !== "false"
|
|
38
|
+
: configuredRejectUnauthorized ?? true;
|
|
39
|
+
return new Pool({
|
|
40
|
+
connectionString,
|
|
41
|
+
ssl: sslDisabled
|
|
42
|
+
? false
|
|
43
|
+
: {
|
|
44
|
+
// Secure by default: verify the server certificate so a MITM cannot
|
|
45
|
+
// read runtime state (including stored OAuth/connection tokens).
|
|
46
|
+
// Provider presets may opt out for generated/self-signed certificates;
|
|
47
|
+
// OPENEVE_POSTGRES_SSL_REJECT_UNAUTHORIZED remains the final override.
|
|
48
|
+
rejectUnauthorized
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
export const openeveProvider = {
|
|
53
|
+
providers: [
|
|
54
|
+
{
|
|
55
|
+
metadata: POSTGRES_STATE_PROVIDER_METADATA,
|
|
56
|
+
async create(ctx) {
|
|
57
|
+
// The provider constructs the pool, so the adapter owns it and closes it on shutdown.
|
|
58
|
+
const optionalMigrations = optionalMigrationsFromOptions(ctx.options);
|
|
59
|
+
const state = new PostgresStateAdapter(await createPostgresPoolFromEnv(ctx.env, ctx.options), {
|
|
60
|
+
ownsClient: true,
|
|
61
|
+
...(optionalMigrations !== undefined ? { optionalMigrations } : {})
|
|
62
|
+
});
|
|
63
|
+
if (ctx.env.OPENEVE_AUTO_MIGRATE !== "false")
|
|
64
|
+
await state.migrate();
|
|
65
|
+
return state;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
};
|
|
70
|
+
export function optionalMigrationsFromOptions(options) {
|
|
71
|
+
const configured = options.optionalMigrations;
|
|
72
|
+
if (configured === undefined || configured === false)
|
|
73
|
+
return undefined;
|
|
74
|
+
if (configured === true)
|
|
75
|
+
return true;
|
|
76
|
+
if (Array.isArray(configured)
|
|
77
|
+
&& configured.every((migration) => typeof migration === "string" && migration.trim().length > 0)) {
|
|
78
|
+
return [...new Set(configured.map((migration) => migration.trim()))];
|
|
79
|
+
}
|
|
80
|
+
throw new Error("Postgres optionalMigrations must be true or an array of migration IDs.");
|
|
81
|
+
}
|
|
82
|
+
async function dynamicImport(specifier) {
|
|
83
|
+
const load = new Function("specifier", "return import(specifier)");
|
|
84
|
+
return load(specifier);
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAoB,MAAM,YAAY,CAAC;AAEpE,0FAA0F;AAC1F,MAAM,CAAC,MAAM,gCAAgC,GAA4B;IACvE,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,OAAO;IACb,WAAW,EAAE,+BAA+B;IAC5C,WAAW,EAAE,CAAC,cAAc,CAAC;IAC7B,YAAY,EAAE,CAAC,eAAe,EAAE,YAAY,CAAC;IAC7C,KAAK,EAAE;QACL;YACE,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE,iBAAiB;YACvB,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,oEAAoE;SAC9E;KACF;CACF,CAAC;AAIF;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,GAAuC,EACvC,UAAsB,EAAE;IAExB,MAAM,uBAAuB,GAAG,OAAO,OAAO,CAAC,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;IAC9G,MAAM,aAAa,GAAG,GAAG,CAAC,+BAA+B,IAAI,uBAAuB,IAAI,cAAc,CAAC;IACvG,MAAM,gBAAgB,GAAG,GAAG,CAAC,aAAa,CAAC,CAAC;IAC5C,IAAI,CAAC,gBAAgB;QAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,aAAa,GAAG,CAAC,CAAC;I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CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBACpE,CAAC,CAAC;gBACH,IAAI,GAAG,CAAC,GAAG,CAAC,oBAAoB,KAAK,OAAO;oBAAE,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;gBACpE,OAAO,KAAK,CAAC;YACf,CAAC;SACF;KACF;CACF,CAAC;AAEF,MAAM,UAAU,6BAA6B,CAAC,OAAmB;IAC/D,MAAM,UAAU,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAC9C,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,KAAK,KAAK;QAAE,OAAO,SAAS,CAAC;IACvE,IAAI,UAAU,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACrC,IACE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC;WACtB,UAAU,CAAC,KAAK,CAAC,CAAC,SAAS,EAAuB,EAAE,CAAC,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,EACrH,CAAC;QACD,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IACvE,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;AAC5F,CAAC;AAED,KAAK,UAAU,aAAa,CAAI,SAAiB;IAC/C,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,WAAW,EAAE,0BAA0B,CAAsC,CAAC;IACxG,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { MemorySearchInput } from "@assemblyline-agents/core";
|
|
2
|
+
import type { CheckpointRecord, ConnectionAuthorizationSessionRecord, ConversationRecord, DeliveryObligation, DynamicScheduleRecord, FileIndexRecord, MemoryDocument, MemoryEmbeddingRecord, MemorySearchResult, MessageRecord, RunEvent, RunRecord, SandboxSessionRecord, SandboxSyncJobRecord, StoredConnectionDefinition, StoredConnectionGrant, StoredSkill, ToolCallRecord, UsageRecord } from "@assemblyline-agents/runtime";
|
|
3
|
+
export type Row = Record<string, unknown>;
|
|
4
|
+
export declare function mapRun(row: Row): RunRecord;
|
|
5
|
+
export declare function mapEvent(row: Row): RunEvent;
|
|
6
|
+
export declare function mapToolCall(row: Row): ToolCallRecord;
|
|
7
|
+
export declare function mapCheckpoint(row: Row): CheckpointRecord;
|
|
8
|
+
export declare function mapDelivery(row: Row): DeliveryObligation;
|
|
9
|
+
export declare function mapUsage(row: Row): UsageRecord;
|
|
10
|
+
export declare function mapSandboxSession(row: Row): SandboxSessionRecord;
|
|
11
|
+
export declare function mapSandboxSyncJob(row: Row): SandboxSyncJobRecord;
|
|
12
|
+
export declare function mapMemoryDocument(row: Row): MemoryDocument;
|
|
13
|
+
export declare function memorySearchResultFromPostgres(row: Row, query: string, mode: MemorySearchInput["mode"] | undefined): MemorySearchResult;
|
|
14
|
+
export declare function memoryEmbeddingSearchResultFromPostgres(row: Row, query: string): MemorySearchResult;
|
|
15
|
+
export declare function mapMemoryEmbedding(row: Row): MemoryEmbeddingRecord;
|
|
16
|
+
export declare function mapFileIndexRecord(row: Row): FileIndexRecord;
|
|
17
|
+
export declare function mapConversation(row: Row): ConversationRecord;
|
|
18
|
+
export declare function mapMessage(row: Row): MessageRecord;
|
|
19
|
+
export declare function mapConnectionGrant(row: Row): StoredConnectionGrant;
|
|
20
|
+
export declare function mapConnectionAuthorizationSession(row: Row): ConnectionAuthorizationSessionRecord;
|
|
21
|
+
export declare function mapSkill(row: Row): StoredSkill;
|
|
22
|
+
export declare function mapDynamicSchedule(row: Row): DynamicScheduleRecord;
|
|
23
|
+
export declare function mapConnectionDefinition(row: Row): StoredConnectionDefinition;
|
|
24
|
+
//# sourceMappingURL=row-mappers.d.ts.map
|
|
@@ -0,0 +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S,GAAG,kBAAkB,CAevI;AAED,wBAAgB,uCAAuC,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,kBAAkB,CAcnG;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,GAAG,GAAG,qBAAqB,CAclE;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,GAAG,GAAG,eAAe,CAa5D;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,GAAG,GAAG,kBAAkB,CAc5D;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,aAAa,CAUlD;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,GAAG,GAAG,qBAAqB,CAelE;AAED,wBAAgB,iCAAiC,CAAC,GAAG,EAAE,GAAG,GAAG,oCAAoC,CAsBhG;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,WAAW,CAW9C;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,GAAG,GAAG,qBAAqB,CA8BlE;AAED,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,GAAG,GAAG,0BAA0B,CAa5E"}
|
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import { microsToUsd } from "@assemblyline-agents/runtime";
|
|
2
|
+
import { memoryBodyTextForPostgres, memorySnippetForPostgres, normalizeJsonArray, normalizeJsonObject, normalizeJsonValue, postgresMemoryRankReason, postgresVectorValue, toIso } from "./sql-helpers.js";
|
|
3
|
+
export function mapRun(row) {
|
|
4
|
+
const run = {
|
|
5
|
+
id: String(row.id),
|
|
6
|
+
agentRevision: String(row.agent_revision),
|
|
7
|
+
status: String(row.status),
|
|
8
|
+
input: normalizeJsonObject(row.input),
|
|
9
|
+
createdAt: toIso(row.created_at),
|
|
10
|
+
updatedAt: toIso(row.updated_at)
|
|
11
|
+
};
|
|
12
|
+
if (row.context_bundle_id)
|
|
13
|
+
run.contextBundleId = String(row.context_bundle_id);
|
|
14
|
+
if (row.sandbox_id)
|
|
15
|
+
run.sandboxId = String(row.sandbox_id);
|
|
16
|
+
if (row.sandbox_snapshot_id)
|
|
17
|
+
run.sandboxSnapshotId = String(row.sandbox_snapshot_id);
|
|
18
|
+
if (row.memory_revision)
|
|
19
|
+
run.memoryRevision = String(row.memory_revision);
|
|
20
|
+
if (row.control_intent === "suspend" || row.control_intent === "cancel")
|
|
21
|
+
run.controlIntent = row.control_intent;
|
|
22
|
+
if (row.terminal_reason)
|
|
23
|
+
run.terminalReason = String(row.terminal_reason);
|
|
24
|
+
if (row.terminal_error)
|
|
25
|
+
run.terminalError = String(row.terminal_error);
|
|
26
|
+
return run;
|
|
27
|
+
}
|
|
28
|
+
export function mapEvent(row) {
|
|
29
|
+
return {
|
|
30
|
+
id: String(row.id),
|
|
31
|
+
runId: String(row.run_id),
|
|
32
|
+
sequence: Number(row.sequence),
|
|
33
|
+
type: String(row.type),
|
|
34
|
+
timestamp: toIso(row.created_at),
|
|
35
|
+
data: normalizeJsonObject(row.data)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export function mapToolCall(row) {
|
|
39
|
+
const record = {
|
|
40
|
+
id: String(row.id),
|
|
41
|
+
runId: String(row.run_id),
|
|
42
|
+
toolName: String(row.tool_name),
|
|
43
|
+
status: String(row.status),
|
|
44
|
+
input: row.input,
|
|
45
|
+
idempotencyKey: String(row.idempotency_key),
|
|
46
|
+
createdAt: toIso(row.created_at),
|
|
47
|
+
updatedAt: toIso(row.updated_at)
|
|
48
|
+
};
|
|
49
|
+
if (row.result !== null && row.result !== undefined)
|
|
50
|
+
record.result = row.result;
|
|
51
|
+
if (row.model_output !== null && row.model_output !== undefined)
|
|
52
|
+
record.modelOutput = row.model_output;
|
|
53
|
+
if (row.error)
|
|
54
|
+
record.error = String(row.error);
|
|
55
|
+
return record;
|
|
56
|
+
}
|
|
57
|
+
export function mapCheckpoint(row) {
|
|
58
|
+
return {
|
|
59
|
+
id: String(row.id),
|
|
60
|
+
runId: String(row.run_id),
|
|
61
|
+
name: String(row.name),
|
|
62
|
+
createdAt: toIso(row.created_at),
|
|
63
|
+
data: normalizeJsonObject(row.data)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export function mapDelivery(row) {
|
|
67
|
+
const createdAt = toIso(row.created_at);
|
|
68
|
+
const record = {
|
|
69
|
+
id: String(row.id),
|
|
70
|
+
runId: String(row.run_id),
|
|
71
|
+
channel: String(row.channel),
|
|
72
|
+
payload: normalizeJsonObject(row.payload),
|
|
73
|
+
idempotencyKey: String(row.idempotency_key),
|
|
74
|
+
status: String(row.status),
|
|
75
|
+
attemptCount: Number(row.attempt_count ?? 0),
|
|
76
|
+
maxAttempts: Number(row.max_attempts ?? 5),
|
|
77
|
+
nextAttemptAt: row.next_attempt_at ? toIso(row.next_attempt_at) : createdAt,
|
|
78
|
+
createdAt,
|
|
79
|
+
updatedAt: toIso(row.updated_at)
|
|
80
|
+
};
|
|
81
|
+
if (row.lease_token)
|
|
82
|
+
record.leaseToken = String(row.lease_token);
|
|
83
|
+
if (row.lease_expires_at)
|
|
84
|
+
record.leaseExpiresAt = toIso(row.lease_expires_at);
|
|
85
|
+
if (row.last_error)
|
|
86
|
+
record.lastError = String(row.last_error);
|
|
87
|
+
if (row.sent_at)
|
|
88
|
+
record.sentAt = toIso(row.sent_at);
|
|
89
|
+
if (row.failed_at)
|
|
90
|
+
record.failedAt = toIso(row.failed_at);
|
|
91
|
+
return record;
|
|
92
|
+
}
|
|
93
|
+
export function mapUsage(row) {
|
|
94
|
+
const tokenSource = actualTokenSource(row.token_source);
|
|
95
|
+
const costSource = actualCostSource(row.cost_source);
|
|
96
|
+
const costMicros = costSource === "unavailable" ? null : nullableString(row.cost_micros);
|
|
97
|
+
const upstreamCostMicros = costSource === "unavailable" ? null : nullableString(row.upstream_cost_micros);
|
|
98
|
+
const record = {
|
|
99
|
+
id: String(row.id),
|
|
100
|
+
idempotencyKey: String(row.idempotency_key ?? `legacy:${String(row.id)}`),
|
|
101
|
+
billingMode: String(row.billing_mode ?? "unknown"),
|
|
102
|
+
recordKind: String(row.record_kind ?? "transaction"),
|
|
103
|
+
inputTokens: tokenSource === "unavailable" ? 0 : Number(row.input_tokens ?? 0),
|
|
104
|
+
outputTokens: tokenSource === "unavailable" ? 0 : Number(row.output_tokens ?? 0),
|
|
105
|
+
cachedTokens: tokenSource === "unavailable" ? 0 : Number(row.cached_tokens ?? 0),
|
|
106
|
+
cacheWriteTokens: tokenSource === "unavailable" ? 0 : Number(row.cache_write_tokens ?? 0),
|
|
107
|
+
reasoningTokens: tokenSource === "unavailable" ? 0 : Number(row.reasoning_tokens ?? 0),
|
|
108
|
+
costMicros,
|
|
109
|
+
upstreamCostMicros,
|
|
110
|
+
costUsd: costMicros === null ? null : microsToUsd(costMicros),
|
|
111
|
+
upstreamCostUsd: upstreamCostMicros === null ? null : microsToUsd(upstreamCostMicros),
|
|
112
|
+
currency: String(row.currency ?? "USD"),
|
|
113
|
+
tokenSource,
|
|
114
|
+
costSource,
|
|
115
|
+
providerReceipt: normalizeJsonObject(row.provider_receipt),
|
|
116
|
+
metadata: normalizeJsonObject(row.metadata),
|
|
117
|
+
occurredAt: toIso(row.occurred_at ?? row.created_at),
|
|
118
|
+
createdAt: toIso(row.created_at)
|
|
119
|
+
};
|
|
120
|
+
if (row.run_id)
|
|
121
|
+
record.runId = String(row.run_id);
|
|
122
|
+
if (row.parent_run_id)
|
|
123
|
+
record.parentRunId = String(row.parent_run_id);
|
|
124
|
+
if (row.agent_id)
|
|
125
|
+
record.agentId = String(row.agent_id);
|
|
126
|
+
if (row.agent_revision)
|
|
127
|
+
record.agentRevision = String(row.agent_revision);
|
|
128
|
+
if (row.subagent)
|
|
129
|
+
record.subagent = String(row.subagent);
|
|
130
|
+
if (row.turn_id)
|
|
131
|
+
record.turnId = String(row.turn_id);
|
|
132
|
+
if (row.iteration !== null && row.iteration !== undefined)
|
|
133
|
+
record.iteration = Number(row.iteration);
|
|
134
|
+
if (row.provider)
|
|
135
|
+
record.provider = String(row.provider);
|
|
136
|
+
if (row.provider_request_id)
|
|
137
|
+
record.providerRequestId = String(row.provider_request_id);
|
|
138
|
+
if (row.model)
|
|
139
|
+
record.model = String(row.model);
|
|
140
|
+
if (row.response_model)
|
|
141
|
+
record.responseModel = String(row.response_model);
|
|
142
|
+
if (row.receipt_sha256)
|
|
143
|
+
record.receiptSha256 = String(row.receipt_sha256);
|
|
144
|
+
return record;
|
|
145
|
+
}
|
|
146
|
+
function nullableString(value) {
|
|
147
|
+
return value === null || value === undefined ? null : String(value);
|
|
148
|
+
}
|
|
149
|
+
function actualTokenSource(value) {
|
|
150
|
+
return value === "provider_reported" || value === "provider_reconciled"
|
|
151
|
+
? value
|
|
152
|
+
: "unavailable";
|
|
153
|
+
}
|
|
154
|
+
function actualCostSource(value) {
|
|
155
|
+
return value === "provider_reported" || value === "provider_reconciled"
|
|
156
|
+
? value
|
|
157
|
+
: "unavailable";
|
|
158
|
+
}
|
|
159
|
+
export function mapSandboxSession(row) {
|
|
160
|
+
const record = {
|
|
161
|
+
id: String(row.id),
|
|
162
|
+
sessionKey: String(row.session_key),
|
|
163
|
+
provider: String(row.provider),
|
|
164
|
+
sandboxId: String(row.sandbox_id),
|
|
165
|
+
state: String(row.state),
|
|
166
|
+
dirty: Boolean(row.dirty),
|
|
167
|
+
lastSeenAt: toIso(row.last_seen_at),
|
|
168
|
+
manifest: normalizeJsonObject(row.manifest),
|
|
169
|
+
createdAt: toIso(row.created_at),
|
|
170
|
+
updatedAt: toIso(row.updated_at)
|
|
171
|
+
};
|
|
172
|
+
if (row.run_id)
|
|
173
|
+
record.runId = String(row.run_id);
|
|
174
|
+
if (row.last_synced_at)
|
|
175
|
+
record.lastSyncedAt = toIso(row.last_synced_at);
|
|
176
|
+
if (row.snapshot_id)
|
|
177
|
+
record.snapshotId = String(row.snapshot_id);
|
|
178
|
+
if (row.sync_job_id)
|
|
179
|
+
record.syncJobId = String(row.sync_job_id);
|
|
180
|
+
return record;
|
|
181
|
+
}
|
|
182
|
+
export function mapSandboxSyncJob(row) {
|
|
183
|
+
const record = {
|
|
184
|
+
id: String(row.id),
|
|
185
|
+
runId: String(row.run_id),
|
|
186
|
+
sandboxId: String(row.sandbox_id),
|
|
187
|
+
status: String(row.status),
|
|
188
|
+
idempotencyKey: String(row.idempotency_key),
|
|
189
|
+
reason: String(row.reason),
|
|
190
|
+
manifest: normalizeJsonObject(row.manifest),
|
|
191
|
+
attemptCount: Number(row.attempt_count ?? 0),
|
|
192
|
+
maxAttempts: Number(row.max_attempts ?? 5),
|
|
193
|
+
nextAttemptAt: toIso(row.next_attempt_at ?? row.created_at),
|
|
194
|
+
metadata: normalizeJsonObject(row.metadata),
|
|
195
|
+
createdAt: toIso(row.created_at),
|
|
196
|
+
updatedAt: toIso(row.updated_at)
|
|
197
|
+
};
|
|
198
|
+
if (row.error)
|
|
199
|
+
record.error = String(row.error);
|
|
200
|
+
if (row.lease_token)
|
|
201
|
+
record.leaseToken = String(row.lease_token);
|
|
202
|
+
if (row.lease_expires_at)
|
|
203
|
+
record.leaseExpiresAt = toIso(row.lease_expires_at);
|
|
204
|
+
if (row.completed_at)
|
|
205
|
+
record.completedAt = toIso(row.completed_at);
|
|
206
|
+
if (row.failed_at)
|
|
207
|
+
record.failedAt = toIso(row.failed_at);
|
|
208
|
+
if (row.last_error)
|
|
209
|
+
record.lastError = String(row.last_error);
|
|
210
|
+
return record;
|
|
211
|
+
}
|
|
212
|
+
export function mapMemoryDocument(row) {
|
|
213
|
+
const sourceRefs = normalizeJsonArray(row.source_refs).map(String);
|
|
214
|
+
const document = {
|
|
215
|
+
scope: normalizeJsonObject(row.scope),
|
|
216
|
+
path: String(row.path),
|
|
217
|
+
body: row.body,
|
|
218
|
+
contentType: String(row.content_type),
|
|
219
|
+
tags: normalizeJsonArray(row.tags).map(String),
|
|
220
|
+
tokenEstimate: Number(row.token_estimate ?? 0),
|
|
221
|
+
sha256: String(row.sha256),
|
|
222
|
+
revision: String(row.revision),
|
|
223
|
+
createdAt: toIso(row.created_at),
|
|
224
|
+
updatedAt: toIso(row.updated_at)
|
|
225
|
+
};
|
|
226
|
+
if (row.title)
|
|
227
|
+
document.title = String(row.title);
|
|
228
|
+
if (row.summary)
|
|
229
|
+
document.summary = String(row.summary);
|
|
230
|
+
if (row.confidence)
|
|
231
|
+
document.confidence = String(row.confidence);
|
|
232
|
+
if (sourceRefs.length > 0)
|
|
233
|
+
document.sourceRefs = sourceRefs;
|
|
234
|
+
return document;
|
|
235
|
+
}
|
|
236
|
+
export function memorySearchResultFromPostgres(row, query, mode) {
|
|
237
|
+
const document = mapMemoryDocument(row);
|
|
238
|
+
const rank = Number(row.rank ?? 0);
|
|
239
|
+
const rowSnippet = typeof row.snippet === "string" ? row.snippet.replace(/<\/?b>/gu, "") : "";
|
|
240
|
+
const body = memoryBodyTextForPostgres(document);
|
|
241
|
+
return {
|
|
242
|
+
path: document.path,
|
|
243
|
+
...(document.title ? { title: document.title } : {}),
|
|
244
|
+
...(document.summary ? { summary: document.summary } : {}),
|
|
245
|
+
snippet: rowSnippet || memorySnippetForPostgres(body, query),
|
|
246
|
+
revision: document.revision,
|
|
247
|
+
tags: document.tags,
|
|
248
|
+
updatedAt: document.updatedAt,
|
|
249
|
+
rankReason: postgresMemoryRankReason(document, query, rank, mode)
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
export function memoryEmbeddingSearchResultFromPostgres(row, query) {
|
|
253
|
+
const document = mapMemoryDocument(row);
|
|
254
|
+
const distance = Number(row.distance ?? 1);
|
|
255
|
+
const similarity = Math.max(0, 1 - distance);
|
|
256
|
+
return {
|
|
257
|
+
path: document.path,
|
|
258
|
+
...(document.title ? { title: document.title } : {}),
|
|
259
|
+
...(document.summary ? { summary: document.summary } : {}),
|
|
260
|
+
snippet: memorySnippetForPostgres(memoryBodyTextForPostgres(document), query),
|
|
261
|
+
revision: document.revision,
|
|
262
|
+
tags: document.tags,
|
|
263
|
+
updatedAt: document.updatedAt,
|
|
264
|
+
rankReason: `semantic similarity ${similarity.toFixed(3)}`
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
export function mapMemoryEmbedding(row) {
|
|
268
|
+
return {
|
|
269
|
+
id: String(row.id),
|
|
270
|
+
scope: normalizeJsonObject(row.scope),
|
|
271
|
+
path: String(row.path),
|
|
272
|
+
model: String(row.model),
|
|
273
|
+
dimensions: Number(row.dimensions ?? 0),
|
|
274
|
+
contentSha256: String(row.content_sha256),
|
|
275
|
+
embedding: postgresVectorValue(row.embedding),
|
|
276
|
+
stale: row.stale === true || row.stale === "true",
|
|
277
|
+
metadata: normalizeJsonObject(row.metadata),
|
|
278
|
+
createdAt: toIso(row.created_at),
|
|
279
|
+
updatedAt: toIso(row.updated_at)
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
export function mapFileIndexRecord(row) {
|
|
283
|
+
const record = {
|
|
284
|
+
id: String(row.id),
|
|
285
|
+
path: String(row.path),
|
|
286
|
+
kind: String(row.kind),
|
|
287
|
+
blobKey: String(row.blob_key),
|
|
288
|
+
sha256: String(row.sha256),
|
|
289
|
+
sizeBytes: Number(row.size_bytes ?? 0),
|
|
290
|
+
metadata: normalizeJsonObject(row.metadata),
|
|
291
|
+
createdAt: toIso(row.created_at)
|
|
292
|
+
};
|
|
293
|
+
if (row.run_id)
|
|
294
|
+
record.runId = String(row.run_id);
|
|
295
|
+
return record;
|
|
296
|
+
}
|
|
297
|
+
export function mapConversation(row) {
|
|
298
|
+
const record = {
|
|
299
|
+
id: String(row.id),
|
|
300
|
+
agentRevision: String(row.agent_revision ?? row.agent_id ?? ""),
|
|
301
|
+
channel: String(row.channel),
|
|
302
|
+
metadata: normalizeJsonObject(row.metadata),
|
|
303
|
+
createdAt: toIso(row.created_at),
|
|
304
|
+
updatedAt: toIso(row.updated_at)
|
|
305
|
+
};
|
|
306
|
+
if (row.agent_scope)
|
|
307
|
+
record.agentScope = String(row.agent_scope);
|
|
308
|
+
if (row.subject)
|
|
309
|
+
record.subject = String(row.subject);
|
|
310
|
+
if (row.title)
|
|
311
|
+
record.title = String(row.title);
|
|
312
|
+
if (row.archived_at)
|
|
313
|
+
record.archivedAt = toIso(row.archived_at);
|
|
314
|
+
return record;
|
|
315
|
+
}
|
|
316
|
+
export function mapMessage(row) {
|
|
317
|
+
const record = {
|
|
318
|
+
id: String(row.id),
|
|
319
|
+
conversationId: String(row.conversation_id),
|
|
320
|
+
role: String(row.role),
|
|
321
|
+
content: normalizeJsonObject(row.content),
|
|
322
|
+
createdAt: toIso(row.created_at)
|
|
323
|
+
};
|
|
324
|
+
if (row.run_id)
|
|
325
|
+
record.runId = String(row.run_id);
|
|
326
|
+
return record;
|
|
327
|
+
}
|
|
328
|
+
export function mapConnectionGrant(row) {
|
|
329
|
+
const grant = {
|
|
330
|
+
connectionName: String(row.connection_name),
|
|
331
|
+
principalKey: String(row.principal_key),
|
|
332
|
+
principal: normalizeJsonObject(row.principal),
|
|
333
|
+
token: String(row.token),
|
|
334
|
+
createdAt: toIso(row.created_at),
|
|
335
|
+
updatedAt: toIso(row.updated_at)
|
|
336
|
+
};
|
|
337
|
+
if (row.refresh_token)
|
|
338
|
+
grant.refreshToken = String(row.refresh_token);
|
|
339
|
+
if (row.token_type)
|
|
340
|
+
grant.tokenType = String(row.token_type);
|
|
341
|
+
if (Array.isArray(row.scopes))
|
|
342
|
+
grant.scopes = row.scopes.map(String);
|
|
343
|
+
if (row.expires_at !== null && row.expires_at !== undefined)
|
|
344
|
+
grant.expiresAt = Number(row.expires_at);
|
|
345
|
+
if (row.credential && typeof row.credential === "object")
|
|
346
|
+
grant.credential = normalizeJsonObject(row.credential);
|
|
347
|
+
return grant;
|
|
348
|
+
}
|
|
349
|
+
export function mapConnectionAuthorizationSession(row) {
|
|
350
|
+
const record = {
|
|
351
|
+
id: String(row.id),
|
|
352
|
+
state: String(row.state),
|
|
353
|
+
connectionName: String(row.connection_name),
|
|
354
|
+
principalKey: String(row.principal_key),
|
|
355
|
+
principal: normalizeJsonObject(row.principal),
|
|
356
|
+
session: normalizeJsonObject(row.session),
|
|
357
|
+
callbackUrl: String(row.callback_url),
|
|
358
|
+
challenge: normalizeJsonObject(row.challenge),
|
|
359
|
+
status: String(row.status),
|
|
360
|
+
expiresAt: Number(row.expires_at),
|
|
361
|
+
createdAt: toIso(row.created_at),
|
|
362
|
+
updatedAt: toIso(row.updated_at)
|
|
363
|
+
};
|
|
364
|
+
if (row.code_verifier)
|
|
365
|
+
record.codeVerifier = String(row.code_verifier);
|
|
366
|
+
if (row.resume !== null && row.resume !== undefined)
|
|
367
|
+
record.resume = normalizeJsonValue(row.resume);
|
|
368
|
+
if (row.run_id)
|
|
369
|
+
record.runId = String(row.run_id);
|
|
370
|
+
if (row.tool_call_id)
|
|
371
|
+
record.toolCallId = String(row.tool_call_id);
|
|
372
|
+
if (row.tool_name)
|
|
373
|
+
record.toolName = String(row.tool_name);
|
|
374
|
+
if (row.continuation !== null && row.continuation !== undefined)
|
|
375
|
+
record.continuation = normalizeJsonObject(row.continuation);
|
|
376
|
+
return record;
|
|
377
|
+
}
|
|
378
|
+
export function mapSkill(row) {
|
|
379
|
+
const record = {
|
|
380
|
+
name: String(row.name),
|
|
381
|
+
body: String(row.body),
|
|
382
|
+
origin: String(row.origin),
|
|
383
|
+
bodySha256: String(row.body_sha256),
|
|
384
|
+
updatedAt: toIso(row.updated_at)
|
|
385
|
+
};
|
|
386
|
+
if (row.seed_sha256)
|
|
387
|
+
record.seedSha256 = String(row.seed_sha256);
|
|
388
|
+
if (row.pending)
|
|
389
|
+
record.pending = Boolean(row.pending);
|
|
390
|
+
return record;
|
|
391
|
+
}
|
|
392
|
+
export function mapDynamicSchedule(row) {
|
|
393
|
+
const record = {
|
|
394
|
+
id: String(row.id),
|
|
395
|
+
scope: String(row.scope),
|
|
396
|
+
prompt: String(row.prompt),
|
|
397
|
+
channel: String(row.channel),
|
|
398
|
+
nextRunAt: toIso(row.next_run_at),
|
|
399
|
+
enabled: Boolean(row.enabled),
|
|
400
|
+
createdAt: toIso(row.created_at),
|
|
401
|
+
updatedAt: toIso(row.updated_at)
|
|
402
|
+
};
|
|
403
|
+
if (row.message)
|
|
404
|
+
record.message = String(row.message);
|
|
405
|
+
if (row.user_id)
|
|
406
|
+
record.userId = String(row.user_id);
|
|
407
|
+
if (row.conversation_id)
|
|
408
|
+
record.conversationId = String(row.conversation_id);
|
|
409
|
+
if (row.project_id)
|
|
410
|
+
record.projectId = String(row.project_id);
|
|
411
|
+
if (row.target !== null && row.target !== undefined)
|
|
412
|
+
record.target = normalizeJsonObject(row.target);
|
|
413
|
+
if (row.trigger !== null && row.trigger !== undefined) {
|
|
414
|
+
record.trigger = normalizeJsonObject(row.trigger);
|
|
415
|
+
}
|
|
416
|
+
if (row.cron)
|
|
417
|
+
record.cron = String(row.cron);
|
|
418
|
+
if (row.every_minutes !== null && row.every_minutes !== undefined)
|
|
419
|
+
record.everyMinutes = Number(row.every_minutes);
|
|
420
|
+
if (row.timezone)
|
|
421
|
+
record.timezone = String(row.timezone);
|
|
422
|
+
if (row.lease_token)
|
|
423
|
+
record.leaseToken = String(row.lease_token);
|
|
424
|
+
if (row.lease_expires_at)
|
|
425
|
+
record.leaseExpiresAt = toIso(row.lease_expires_at);
|
|
426
|
+
if (row.last_run_at)
|
|
427
|
+
record.lastRunAt = toIso(row.last_run_at);
|
|
428
|
+
if (row.consecutive_failures !== null && row.consecutive_failures !== undefined) {
|
|
429
|
+
record.consecutiveFailures = Number(row.consecutive_failures);
|
|
430
|
+
}
|
|
431
|
+
if (row.metadata !== null && row.metadata !== undefined)
|
|
432
|
+
record.metadata = normalizeJsonObject(row.metadata);
|
|
433
|
+
return record;
|
|
434
|
+
}
|
|
435
|
+
export function mapConnectionDefinition(row) {
|
|
436
|
+
const record = {
|
|
437
|
+
name: String(row.name),
|
|
438
|
+
scope: String(row.scope),
|
|
439
|
+
protocol: String(row.protocol),
|
|
440
|
+
description: String(row.description),
|
|
441
|
+
definition: normalizeJsonObject(row.definition),
|
|
442
|
+
origin: String(row.origin),
|
|
443
|
+
createdAt: toIso(row.created_at),
|
|
444
|
+
updatedAt: toIso(row.updated_at)
|
|
445
|
+
};
|
|
446
|
+
if (row.metadata !== null && row.metadata !== undefined)
|
|
447
|
+
record.metadata = normalizeJsonObject(row.metadata);
|
|
448
|
+
return record;
|
|
449
|
+
}
|
|
450
|
+
//# sourceMappingURL=row-mappers.js.map
|