@slopus/happy-agent-base 0.0.17 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -0
- package/dist/Agent.d.ts +8 -6
- package/dist/Agent.d.ts.map +1 -1
- package/dist/Agent.js +7 -4
- package/dist/Agent.js.map +1 -1
- package/dist/AgentBase.d.ts +19 -12
- package/dist/AgentBase.d.ts.map +1 -1
- package/dist/AgentBase.js +293 -151
- package/dist/AgentBase.js.map +1 -1
- package/dist/AgentBaseHooks.d.ts +25 -5
- package/dist/AgentBaseHooks.d.ts.map +1 -1
- package/dist/AgentDatabase.d.ts.map +1 -1
- package/dist/AgentDatabase.js +27 -14
- package/dist/AgentDatabase.js.map +1 -1
- package/dist/AgentDatabaseConnection.d.ts +39 -0
- package/dist/AgentDatabaseConnection.d.ts.map +1 -0
- package/dist/AgentDatabaseConnection.js +199 -0
- package/dist/AgentDatabaseConnection.js.map +1 -0
- package/dist/AgentModule.d.ts +7 -1
- package/dist/AgentModule.d.ts.map +1 -1
- package/dist/AgentModuleAction.d.ts +4 -3
- package/dist/AgentModuleAction.d.ts.map +1 -1
- package/dist/AgentPersistence.d.ts +15 -8
- package/dist/AgentPersistence.d.ts.map +1 -1
- package/dist/AgentQueuedMessage.d.ts +13 -0
- package/dist/AgentQueuedMessage.d.ts.map +1 -0
- package/dist/AgentQueuedMessage.js +2 -0
- package/dist/AgentQueuedMessage.js.map +1 -0
- package/dist/AgentRef.d.ts +4 -4
- package/dist/AgentRef.d.ts.map +1 -1
- package/dist/AgentRef.js +1 -1
- package/dist/AgentRef.js.map +1 -1
- package/dist/AgentSpanAttributes.d.ts +11 -0
- package/dist/AgentSpanAttributes.d.ts.map +1 -0
- package/dist/AgentSpanAttributes.js +11 -0
- package/dist/AgentSpanAttributes.js.map +1 -0
- package/dist/AgentStorage.d.ts.map +1 -1
- package/dist/AgentStorage.js +2 -0
- package/dist/AgentStorage.js.map +1 -1
- package/dist/AgentSystem.d.ts +6 -5
- package/dist/AgentSystem.d.ts.map +1 -1
- package/dist/AgentSystemLocal.d.ts +3 -3
- package/dist/AgentSystemLocal.d.ts.map +1 -1
- package/dist/AgentSystemLocal.js +53 -30
- package/dist/AgentSystemLocal.js.map +1 -1
- package/dist/AgentSystemRef.d.ts +3 -3
- package/dist/AgentSystemRef.d.ts.map +1 -1
- package/dist/inTx.d.ts +0 -7
- package/dist/inTx.d.ts.map +1 -1
- package/dist/inTx.js +9 -16
- package/dist/inTx.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/openAgentPGliteDatabase.d.ts +10 -0
- package/dist/openAgentPGliteDatabase.d.ts.map +1 -0
- package/dist/openAgentPGliteDatabase.js +17 -0
- package/dist/openAgentPGliteDatabase.js.map +1 -0
- package/dist/openAgentPostgresDatabase.d.ts +13 -0
- package/dist/openAgentPostgresDatabase.d.ts.map +1 -0
- package/dist/openAgentPostgresDatabase.js +10 -0
- package/dist/openAgentPostgresDatabase.js.map +1 -0
- package/dist/openAgentSQLiteDatabase.d.ts +6 -0
- package/dist/openAgentSQLiteDatabase.d.ts.map +1 -0
- package/dist/openAgentSQLiteDatabase.js +48 -0
- package/dist/openAgentSQLiteDatabase.js.map +1 -0
- package/package.json +6 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openAgentPGliteDatabase.d.ts","sourceRoot":"","sources":["../sources/openAgentPGliteDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAW,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAElE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC;AACjD,MAAM,MAAM,8BAA8B,GAAG,aAAa,GAAG;IACzD,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,yFAAyF;AACzF,wBAAsB,uBAAuB,CACzC,OAAO,GAAE,8BAAmC,GAC7C,OAAO,CAAC,uBAAuB,CAAC,mBAAmB,CAAC,CAAC,CAUvD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PGlite } from "@electric-sql/pglite";
|
|
2
|
+
import { drizzle } from "drizzle-orm/pglite";
|
|
3
|
+
import { AgentDatabaseConnection } from "./AgentDatabaseConnection.js";
|
|
4
|
+
/** Open one embedded PostgreSQL database with Agent Base's shared ownership contract. */
|
|
5
|
+
export async function openAgentPGliteDatabase(options = {}) {
|
|
6
|
+
const { dataDir, ...pgliteOptions } = options;
|
|
7
|
+
const client = new PGlite(dataDir, pgliteOptions);
|
|
8
|
+
try {
|
|
9
|
+
await client.waitReady;
|
|
10
|
+
return new AgentDatabaseConnection(drizzle(client), async () => await client.close());
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
await client.close();
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=openAgentPGliteDatabase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openAgentPGliteDatabase.js","sourceRoot":"","sources":["../sources/openAgentPGliteDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAsB,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAuB,MAAM,oBAAoB,CAAC;AAElE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAOvE,yFAAyF;AACzF,MAAM,CAAC,KAAK,UAAU,uBAAuB,CACzC,OAAO,GAAmC,EAAE;IAE5C,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,EAAE,GAAG,OAAO,CAAC;IAC9C,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAClD,IAAI,CAAC;QACD,MAAM,MAAM,CAAC,SAAS,CAAC;QACvB,OAAO,IAAI,uBAAuB,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IAC1F,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACrB,MAAM,KAAK,CAAC;IAChB,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
|
2
|
+
import { type Options, type PostgresType, type Sql } from "postgres";
|
|
3
|
+
import { AgentDatabaseConnection } from "./AgentDatabaseConnection.js";
|
|
4
|
+
export type AgentPostgresJsDatabase = PostgresJsDatabase & {
|
|
5
|
+
readonly $client: Sql;
|
|
6
|
+
};
|
|
7
|
+
export interface OpenAgentPostgresDatabaseOptions {
|
|
8
|
+
readonly url: string;
|
|
9
|
+
readonly options?: Options<Record<string, PostgresType>>;
|
|
10
|
+
}
|
|
11
|
+
/** Open one network PostgreSQL pool with Agent Base's shared ownership contract. */
|
|
12
|
+
export declare function openAgentPostgresDatabase(config: OpenAgentPostgresDatabaseOptions): Promise<AgentDatabaseConnection<AgentPostgresJsDatabase>>;
|
|
13
|
+
//# sourceMappingURL=openAgentPostgresDatabase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openAgentPostgresDatabase.d.ts","sourceRoot":"","sources":["../sources/openAgentPostgresDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAiB,EAAE,KAAK,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/E,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,MAAM,MAAM,uBAAuB,GAAG,kBAAkB,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAA;CAAE,CAAC;AAErF,MAAM,WAAW,gCAAgC;IAC7C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;CAC5D;AAED,oFAAoF;AACpF,wBAAsB,yBAAyB,CAC3C,MAAM,EAAE,gCAAgC,GACzC,OAAO,CAAC,uBAAuB,CAAC,uBAAuB,CAAC,CAAC,CAI3D"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { drizzle } from "drizzle-orm/postgres-js";
|
|
2
|
+
import postgres, {} from "postgres";
|
|
3
|
+
import { AgentDatabaseConnection } from "./AgentDatabaseConnection.js";
|
|
4
|
+
/** Open one network PostgreSQL pool with Agent Base's shared ownership contract. */
|
|
5
|
+
export async function openAgentPostgresDatabase(config) {
|
|
6
|
+
const client = postgres(config.url, config.options);
|
|
7
|
+
const database = drizzle(client);
|
|
8
|
+
return new AgentDatabaseConnection(database, async () => await client.end());
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=openAgentPostgresDatabase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openAgentPostgresDatabase.js","sourceRoot":"","sources":["../sources/openAgentPostgresDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA2B,MAAM,yBAAyB,CAAC;AAC3E,OAAO,QAAQ,EAAE,EAA6C,MAAM,UAAU,CAAC;AAE/E,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AASvE,oFAAoF;AACpF,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC3C,MAAwC;IAExC,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACpD,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACjC,OAAO,IAAI,uBAAuB,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;AACjF,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type LibSQLDatabase } from "drizzle-orm/libsql";
|
|
2
|
+
import { AgentDatabaseConnection } from "./AgentDatabaseConnection.js";
|
|
3
|
+
export type AgentLibSQLDatabase = LibSQLDatabase;
|
|
4
|
+
/** Open one production SQLite database with Agent Base's shared ownership contract. */
|
|
5
|
+
export declare function openAgentSQLiteDatabase(path: string): Promise<AgentDatabaseConnection<AgentLibSQLDatabase>>;
|
|
6
|
+
//# sourceMappingURL=openAgentSQLiteDatabase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openAgentSQLiteDatabase.d.ts","sourceRoot":"","sources":["../sources/openAgentSQLiteDatabase.ts"],"names":[],"mappings":"AAGA,OAAO,EAAW,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAElE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC;AAEjD,uFAAuF;AACvF,wBAAsB,uBAAuB,CACzC,IAAI,EAAE,MAAM,GACb,OAAO,CAAC,uBAAuB,CAAC,mBAAmB,CAAC,CAAC,CAavD"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { pathToFileURL } from "node:url";
|
|
2
|
+
import { createClient } from "@libsql/client";
|
|
3
|
+
import { drizzle } from "drizzle-orm/libsql";
|
|
4
|
+
import { AgentDatabaseConnection } from "./AgentDatabaseConnection.js";
|
|
5
|
+
/** Open one production SQLite database with Agent Base's shared ownership contract. */
|
|
6
|
+
export async function openAgentSQLiteDatabase(path) {
|
|
7
|
+
const client = createClient({
|
|
8
|
+
intMode: "number",
|
|
9
|
+
timeout: 5_000,
|
|
10
|
+
url: pathToFileURL(path).href,
|
|
11
|
+
});
|
|
12
|
+
try {
|
|
13
|
+
await configure(client);
|
|
14
|
+
return new AgentDatabaseConnection(drizzle(client), () => client.close());
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
client.close();
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async function configure(client) {
|
|
22
|
+
await client.execute("PRAGMA journal_mode = WAL");
|
|
23
|
+
await client.execute("PRAGMA synchronous = FULL");
|
|
24
|
+
await client.execute("PRAGMA foreign_keys = ON");
|
|
25
|
+
await client.execute("PRAGMA busy_timeout = 250");
|
|
26
|
+
await awaitCrashRecovery(client);
|
|
27
|
+
await client.execute("PRAGMA busy_timeout = 5000");
|
|
28
|
+
}
|
|
29
|
+
async function awaitCrashRecovery(client) {
|
|
30
|
+
for (let attempt = 0; attempt < 20; attempt += 1) {
|
|
31
|
+
try {
|
|
32
|
+
const transaction = await client.transaction("write");
|
|
33
|
+
await transaction.rollback();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
if (!isBusy(error) || attempt === 19)
|
|
38
|
+
throw error;
|
|
39
|
+
await new Promise((resolve) => {
|
|
40
|
+
setTimeout(resolve, Math.min(25 * (attempt + 1), 250));
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function isBusy(error) {
|
|
46
|
+
return error instanceof Error && "code" in error && error.code === "SQLITE_BUSY";
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=openAgentSQLiteDatabase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openAgentSQLiteDatabase.js","sourceRoot":"","sources":["../sources/openAgentSQLiteDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,YAAY,EAAe,MAAM,gBAAg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AC;YACtD,MAAM,WAAW,CAAC,QAAQ,EAAE,CAAC;YAC7B,OAAO;QACX,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,EAAE;gBAAE,MAAM,KAAK,CAAC;YAClD,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;gBAChC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;YAC3D,CAAC,CAAC,CAAC;QACP,CAAC;IACL,CAAC;AACL,CAAC;AAED,SAAS,MAAM,CAAC,KAAc;IAC1B,OAAO,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,aAAa,CAAC;AACrF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slopus/happy-agent-base",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"description": "Durable runtime for Happy agents.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -24,14 +24,16 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
+
"@electric-sql/pglite": "^0.5.5",
|
|
28
|
+
"@libsql/client": "^0.17.4",
|
|
27
29
|
"@paralleldrive/cuid2": "^3.3.0",
|
|
28
30
|
"@sinclair/typebox": "^0.34.49",
|
|
29
|
-
"@slopus/happy-providers": "0.0.
|
|
31
|
+
"@slopus/happy-providers": "0.0.10",
|
|
30
32
|
"@steve.kite/stdlib": "0.0.12",
|
|
31
|
-
"drizzle-orm": "^0.45.2"
|
|
33
|
+
"drizzle-orm": "^0.45.2",
|
|
34
|
+
"postgres": "^3.4.9"
|
|
32
35
|
},
|
|
33
36
|
"devDependencies": {
|
|
34
|
-
"@libsql/client": "^0.17.4",
|
|
35
37
|
"@types/node": "^24.0.10",
|
|
36
38
|
"typescript": "^7.0.2",
|
|
37
39
|
"vitest": "^3.2.4"
|