@economic/agents 0.0.1-alpha.13 → 0.0.1-alpha.14
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 +13 -19
- package/package.json +1 -1
- package/schema/schema.sql +32 -0
- package/schema/audit_events.sql +0 -16
- package/schema/conversations.sql +0 -15
package/README.md
CHANGED
|
@@ -385,7 +385,7 @@ In the [Cloudflare dashboard](https://dash.cloudflare.com) → **Workers & Pages
|
|
|
385
385
|
|
|
386
386
|
### 2. Create the schema
|
|
387
387
|
|
|
388
|
-
Open the database in the D1 dashboard, select **Console**, and run the contents of [`schema/
|
|
388
|
+
Open the database in the D1 dashboard, select **Console**, and run the contents of [`schema/schema.sql`](schema/schema.sql) — this creates both the `audit_events` and `conversations` tables in one step:
|
|
389
389
|
|
|
390
390
|
```sql
|
|
391
391
|
CREATE TABLE IF NOT EXISTS audit_events (
|
|
@@ -399,6 +399,17 @@ CREATE TABLE IF NOT EXISTS audit_events (
|
|
|
399
399
|
CREATE INDEX IF NOT EXISTS audit_events_user ON audit_events(user_id);
|
|
400
400
|
CREATE INDEX IF NOT EXISTS audit_events_do ON audit_events(durable_object_id);
|
|
401
401
|
CREATE INDEX IF NOT EXISTS audit_events_ts ON audit_events(created_at);
|
|
402
|
+
|
|
403
|
+
CREATE TABLE IF NOT EXISTS conversations (
|
|
404
|
+
durable_object_id TEXT PRIMARY KEY,
|
|
405
|
+
user_id TEXT NOT NULL,
|
|
406
|
+
title TEXT,
|
|
407
|
+
summary TEXT,
|
|
408
|
+
created_at TEXT NOT NULL,
|
|
409
|
+
updated_at TEXT NOT NULL
|
|
410
|
+
);
|
|
411
|
+
CREATE INDEX IF NOT EXISTS conversations_user ON conversations(user_id);
|
|
412
|
+
CREATE INDEX IF NOT EXISTS conversations_ts ON conversations(updated_at);
|
|
402
413
|
```
|
|
403
414
|
|
|
404
415
|
Safe to re-run — all statements use `IF NOT EXISTS`.
|
|
@@ -445,24 +456,7 @@ If the client omits `userId`, the audit insert is skipped and a `console.error`
|
|
|
445
456
|
|
|
446
457
|
`AIChatAgent` maintains a `conversations` table in `AGENT_DB` alongside `audit_events`. One row is kept per Durable Object instance (i.e. per conversation). The row is upserted automatically after every turn — no subclass code needed.
|
|
447
458
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
Run the contents of [`schema/conversations.sql`](schema/conversations.sql) in the D1 dashboard console (same database as `audit_events`):
|
|
451
|
-
|
|
452
|
-
```sql
|
|
453
|
-
CREATE TABLE IF NOT EXISTS conversations (
|
|
454
|
-
durable_object_id TEXT PRIMARY KEY,
|
|
455
|
-
user_id TEXT NOT NULL,
|
|
456
|
-
title TEXT,
|
|
457
|
-
summary TEXT,
|
|
458
|
-
created_at TEXT NOT NULL,
|
|
459
|
-
updated_at TEXT NOT NULL
|
|
460
|
-
);
|
|
461
|
-
CREATE INDEX IF NOT EXISTS conversations_user ON conversations(user_id);
|
|
462
|
-
CREATE INDEX IF NOT EXISTS conversations_ts ON conversations(updated_at);
|
|
463
|
-
```
|
|
464
|
-
|
|
465
|
-
Safe to re-run — all statements use `IF NOT EXISTS`.
|
|
459
|
+
The `conversations` table is created by the same `schema/schema.sql` file used for audit events — no separate setup step needed.
|
|
466
460
|
|
|
467
461
|
### Upsert behaviour
|
|
468
462
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
-- Full schema for @economic/agents.
|
|
2
|
+
-- One database per agent worker — create it once in the Cloudflare D1 portal.
|
|
3
|
+
-- Safe to re-run: all statements use IF NOT EXISTS.
|
|
4
|
+
|
|
5
|
+
-- ─── Audit events ─────────────────────────────────────────────────────────────
|
|
6
|
+
|
|
7
|
+
CREATE TABLE IF NOT EXISTS audit_events (
|
|
8
|
+
id TEXT PRIMARY KEY,
|
|
9
|
+
durable_object_id TEXT NOT NULL,
|
|
10
|
+
user_id TEXT NOT NULL,
|
|
11
|
+
message TEXT NOT NULL,
|
|
12
|
+
payload TEXT, -- JSON, nullable
|
|
13
|
+
created_at TEXT NOT NULL
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
CREATE INDEX IF NOT EXISTS audit_events_user ON audit_events(user_id);
|
|
17
|
+
CREATE INDEX IF NOT EXISTS audit_events_do ON audit_events(durable_object_id);
|
|
18
|
+
CREATE INDEX IF NOT EXISTS audit_events_ts ON audit_events(created_at);
|
|
19
|
+
|
|
20
|
+
-- ─── Conversations ────────────────────────────────────────────────────────────
|
|
21
|
+
|
|
22
|
+
CREATE TABLE IF NOT EXISTS conversations (
|
|
23
|
+
durable_object_id TEXT PRIMARY KEY,
|
|
24
|
+
user_id TEXT NOT NULL,
|
|
25
|
+
title TEXT, -- nullable, LLM-generated after idle
|
|
26
|
+
summary TEXT, -- nullable, LLM-generated after idle
|
|
27
|
+
created_at TEXT NOT NULL,
|
|
28
|
+
updated_at TEXT NOT NULL
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
CREATE INDEX IF NOT EXISTS conversations_user ON conversations(user_id);
|
|
32
|
+
CREATE INDEX IF NOT EXISTS conversations_ts ON conversations(updated_at);
|
package/schema/audit_events.sql
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
-- Audit events table for @economic/agents.
|
|
2
|
-
-- One database per agent worker — create it once in the Cloudflare D1 portal.
|
|
3
|
-
-- Safe to re-run: all statements use IF NOT EXISTS.
|
|
4
|
-
|
|
5
|
-
CREATE TABLE IF NOT EXISTS audit_events (
|
|
6
|
-
id TEXT PRIMARY KEY,
|
|
7
|
-
durable_object_id TEXT NOT NULL,
|
|
8
|
-
user_id TEXT NOT NULL,
|
|
9
|
-
message TEXT NOT NULL,
|
|
10
|
-
payload TEXT, -- JSON, nullable
|
|
11
|
-
created_at TEXT NOT NULL
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
CREATE INDEX IF NOT EXISTS audit_events_user ON audit_events(user_id);
|
|
15
|
-
CREATE INDEX IF NOT EXISTS audit_events_do ON audit_events(durable_object_id);
|
|
16
|
-
CREATE INDEX IF NOT EXISTS audit_events_ts ON audit_events(created_at);
|
package/schema/conversations.sql
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
-- Conversations table for @economic/agents.
|
|
2
|
-
-- One database per agent worker — create it once in the Cloudflare D1 portal.
|
|
3
|
-
-- Safe to re-run: all statements use IF NOT EXISTS.
|
|
4
|
-
|
|
5
|
-
CREATE TABLE IF NOT EXISTS conversations (
|
|
6
|
-
durable_object_id TEXT PRIMARY KEY,
|
|
7
|
-
user_id TEXT NOT NULL,
|
|
8
|
-
title TEXT, -- nullable, LLM-generated later
|
|
9
|
-
summary TEXT, -- nullable, LLM-generated later
|
|
10
|
-
created_at TEXT NOT NULL,
|
|
11
|
-
updated_at TEXT NOT NULL
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
CREATE INDEX IF NOT EXISTS conversations_user ON conversations(user_id);
|
|
15
|
-
CREATE INDEX IF NOT EXISTS conversations_ts ON conversations(updated_at);
|