@agentuity/runtime 0.1.16 → 0.1.18

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.
Files changed (44) hide show
  1. package/dist/_context.d.ts +2 -1
  2. package/dist/_context.d.ts.map +1 -1
  3. package/dist/_context.js +10 -0
  4. package/dist/_context.js.map +1 -1
  5. package/dist/_services.d.ts +2 -1
  6. package/dist/_services.d.ts.map +1 -1
  7. package/dist/_services.js +12 -3
  8. package/dist/_services.js.map +1 -1
  9. package/dist/_standalone.d.ts +2 -1
  10. package/dist/_standalone.d.ts.map +1 -1
  11. package/dist/_standalone.js +1 -0
  12. package/dist/_standalone.js.map +1 -1
  13. package/dist/agent.d.ts +11 -1
  14. package/dist/agent.d.ts.map +1 -1
  15. package/dist/agent.js.map +1 -1
  16. package/dist/router.d.ts +17 -0
  17. package/dist/router.d.ts.map +1 -1
  18. package/dist/router.js.map +1 -1
  19. package/dist/services/local/index.d.ts +1 -0
  20. package/dist/services/local/index.d.ts.map +1 -1
  21. package/dist/services/local/index.js +1 -0
  22. package/dist/services/local/index.js.map +1 -1
  23. package/dist/services/local/keyvalue.d.ts +3 -3
  24. package/dist/services/local/keyvalue.d.ts.map +1 -1
  25. package/dist/services/local/keyvalue.js +2 -2
  26. package/dist/services/local/keyvalue.js.map +1 -1
  27. package/dist/services/local/queue.d.ts +8 -0
  28. package/dist/services/local/queue.d.ts.map +1 -0
  29. package/dist/services/local/queue.js +86 -0
  30. package/dist/services/local/queue.js.map +1 -0
  31. package/dist/services/local/vector.d.ts +2 -2
  32. package/dist/services/local/vector.d.ts.map +1 -1
  33. package/dist/services/local/vector.js +1 -1
  34. package/dist/services/local/vector.js.map +1 -1
  35. package/package.json +7 -7
  36. package/src/_context.ts +12 -0
  37. package/src/_services.ts +13 -1
  38. package/src/_standalone.ts +2 -0
  39. package/src/agent.ts +12 -0
  40. package/src/router.ts +22 -2
  41. package/src/services/local/index.ts +1 -0
  42. package/src/services/local/keyvalue.ts +5 -2
  43. package/src/services/local/queue.ts +127 -0
  44. package/src/services/local/vector.ts +3 -1
@@ -0,0 +1,127 @@
1
+ import type { Database } from 'bun:sqlite';
2
+ import type { QueueService, QueuePublishParams, QueuePublishResult } from '@agentuity/core';
3
+
4
+ export class LocalQueueStorage implements QueueService {
5
+ #db: Database;
6
+ #projectPath: string;
7
+
8
+ constructor(db: Database, projectPath: string) {
9
+ this.#db = db;
10
+ this.#projectPath = projectPath;
11
+ this.#initializeTable();
12
+ }
13
+
14
+ #initializeTable(): void {
15
+ this.#db.run(`
16
+ CREATE TABLE IF NOT EXISTS queue_messages (
17
+ id TEXT PRIMARY KEY,
18
+ project_path TEXT NOT NULL,
19
+ queue_name TEXT NOT NULL,
20
+ offset INTEGER NOT NULL,
21
+ payload TEXT NOT NULL,
22
+ metadata TEXT,
23
+ partition_key TEXT,
24
+ idempotency_key TEXT,
25
+ ttl_seconds INTEGER,
26
+ expires_at TEXT,
27
+ state TEXT NOT NULL DEFAULT 'pending',
28
+ created_at TEXT NOT NULL,
29
+ published_at TEXT NOT NULL
30
+ )
31
+ `);
32
+
33
+ this.#db.run(`
34
+ CREATE INDEX IF NOT EXISTS idx_queue_name
35
+ ON queue_messages(project_path, queue_name)
36
+ `);
37
+
38
+ this.#db.run(`
39
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_queue_idempotency_unique
40
+ ON queue_messages(project_path, queue_name, idempotency_key)
41
+ WHERE idempotency_key IS NOT NULL
42
+ `);
43
+ }
44
+
45
+ async publish(
46
+ queueName: string,
47
+ payload: string | object,
48
+ params?: QueuePublishParams
49
+ ): Promise<QueuePublishResult> {
50
+ const id = crypto.randomUUID();
51
+ const timestamp = new Date().toISOString();
52
+ const payloadStr = typeof payload === 'string' ? payload : JSON.stringify(payload);
53
+ const metadataStr = params?.metadata ? JSON.stringify(params.metadata) : null;
54
+ const ttlSeconds = params?.ttl ?? null;
55
+ const expiresAt = ttlSeconds ? new Date(Date.now() + ttlSeconds * 1000).toISOString() : null;
56
+
57
+ const publishInTransaction = this.#db.transaction(() => {
58
+ if (params?.idempotencyKey) {
59
+ const existing = this.#db
60
+ .query(
61
+ `
62
+ SELECT id, offset, published_at
63
+ FROM queue_messages
64
+ WHERE project_path = ? AND queue_name = ? AND idempotency_key = ?
65
+ `
66
+ )
67
+ .get(this.#projectPath, queueName, params.idempotencyKey) as {
68
+ id: string;
69
+ offset: number;
70
+ published_at: string;
71
+ } | null;
72
+
73
+ if (existing) {
74
+ return {
75
+ id: existing.id,
76
+ offset: existing.offset,
77
+ publishedAt: existing.published_at,
78
+ };
79
+ }
80
+ }
81
+
82
+ const offsetResult = this.#db
83
+ .query(
84
+ `
85
+ SELECT COALESCE(MAX(offset), -1) + 1 as next_offset
86
+ FROM queue_messages
87
+ WHERE project_path = ? AND queue_name = ?
88
+ `
89
+ )
90
+ .get(this.#projectPath, queueName) as { next_offset: number };
91
+
92
+ const offset = offsetResult.next_offset;
93
+
94
+ this.#db
95
+ .prepare(
96
+ `
97
+ INSERT INTO queue_messages (
98
+ id, project_path, queue_name, offset, payload, metadata,
99
+ partition_key, idempotency_key, ttl_seconds, expires_at, state, created_at, published_at
100
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'pending', ?, ?)
101
+ `
102
+ )
103
+ .run(
104
+ id,
105
+ this.#projectPath,
106
+ queueName,
107
+ offset,
108
+ payloadStr,
109
+ metadataStr,
110
+ params?.partitionKey ?? null,
111
+ params?.idempotencyKey ?? null,
112
+ ttlSeconds,
113
+ expiresAt,
114
+ timestamp,
115
+ timestamp
116
+ );
117
+
118
+ return {
119
+ id,
120
+ offset,
121
+ publishedAt: timestamp,
122
+ };
123
+ });
124
+
125
+ return publishInTransaction.immediate();
126
+ }
127
+ }
@@ -10,6 +10,8 @@ import type {
10
10
  VectorSearchResult,
11
11
  VectorNamespaceStats,
12
12
  VectorNamespaceStatsWithSamples,
13
+ VectorGetAllStatsParams,
14
+ VectorStatsPaginated,
13
15
  } from '@agentuity/core';
14
16
  import { randomUUID } from 'node:crypto';
15
17
  import { simpleEmbedding, cosineSimilarity, now } from './_util';
@@ -345,7 +347,7 @@ export class LocalVectorStorage implements VectorStorage {
345
347
  };
346
348
  }
347
349
 
348
- async getAllStats(): Promise<Record<string, VectorNamespaceStats>> {
350
+ async getAllStats(_params?: VectorGetAllStatsParams): Promise<Record<string, VectorNamespaceStats> | VectorStatsPaginated> {
349
351
  const query = this.#db.query(`
350
352
  SELECT name, embedding, document
351
353
  FROM vector_storage