@lv-agent/logdb-client 0.1.0 → 0.2.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/README.md CHANGED
@@ -31,9 +31,21 @@ for (const r of records) {
31
31
  const stream = client.tail('my-app', 'main', { fromSeq: 0, consumerGroup: 'workers', consumerId: 'w1' });
32
32
  for await (const rec of stream) {
33
33
  console.log(`[${rec.seq}] ${rec.eventType}`);
34
- // Commit progress
35
34
  await client.commitOffset('my-app', 'main', 'workers', 'w1', rec.seq);
36
35
  }
36
+
37
+ // SQL query against cache
38
+ const rows = await client.query('my-app', 'main',
39
+ "SELECT seq, event_type FROM records WHERE event_type = 'llm.call' ORDER BY seq DESC LIMIT 10");
40
+ for (const row of rows) console.log(JSON.parse(row));
41
+
42
+ // Subscribe to event types in real-time
43
+ const sub = client.subscribe('my-app', 'main',
44
+ ['tool.call', 'llm.call'], 'sandbox-processors', 'worker-1');
45
+ sub.on('data', (rec) => {
46
+ console.log(`[${rec.seq}] ${rec.eventType}`);
47
+ client.commitOffset('my-app', 'main', 'sandbox-processors', 'worker-1', rec.seq);
48
+ });
37
49
  ```
38
50
 
39
51
  ## API
@@ -44,6 +56,8 @@ for await (const rec of stream) {
44
56
  | `read(ns, stream, seq)` | Point read |
45
57
  | `scanAll(ns, stream, fromSeq)` | Scan all records |
46
58
  | `tail(ns, stream, opts)` | Live subscription (async iterable) |
59
+ | `query(ns, stream, sql)` | SQL SELECT against query cache |
60
+ | `subscribe(ns, stream, eventTypes, group, id)` | Event-type push subscription |
47
61
  | `listNamespaces()` | List all namespaces |
48
62
  | `listStreams(ns)` | List streams in a namespace |
49
63
  | `status()` | Node status |
package/dist/client.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as grpc from '@grpc/grpc-js';
1
2
  import { TailStream } from './tail-stream';
2
3
  import type { AppendResult, BatchAppendResult, NamespaceInfo, LogRecord, StreamInfo, StatusResult, Watermark, VerifyResult, TailOptions } from './types';
3
4
  export interface ClientOptions {
@@ -43,8 +44,25 @@ export declare class Client {
43
44
  read(namespace: string, stream: string, seq: number): Promise<LogRecord | null>;
44
45
  /** Scan records in range. Returns array of records. */
45
46
  scanAll(namespace: string, stream: string, fromSeq: number, limit?: number): Promise<LogRecord[]>;
47
+ /** Subscribe to matching event types in real-time.
48
+ *
49
+ * Returns a gRPC server-streaming call. Records are pushed as they
50
+ * are committed and filtered by `eventTypes`. The consumer offset
51
+ * is tracked server-side.
52
+ *
53
+ * Usage:
54
+ * const stream = client.subscribe('my-app', 'main', ['tool.call'], 'group', 'w1');
55
+ * stream.on('data', (rec) => console.log(rec.eventType, rec.content));
56
+ */
57
+ subscribe(namespace: string, stream: string, eventTypes: string[], consumerGroup: string, consumerId: string): grpc.ClientReadableStream<any>;
46
58
  /** Subscribe to new records via Tail. */
47
59
  tail(namespace: string, stream: string, opts?: TailOptions): TailStream;
60
+ /** Execute a read-only SQL query against a stream's query cache.
61
+ *
62
+ * Only SELECT is allowed — enforced at the SQLite kernel level.
63
+ * Each row is returned as a JSON string.
64
+ */
65
+ query(namespace: string, stream: string, sql: string): Promise<string[]>;
48
66
  /** Get the watermark for a namespace/stream. */
49
67
  watermark(namespace: string, stream: string): Promise<Watermark>;
50
68
  /** List all namespaces. */
package/dist/client.js CHANGED
@@ -159,6 +159,26 @@ class Client {
159
159
  call.on('error', (err) => reject(err));
160
160
  });
161
161
  }
162
+ // ── Subscribe ───────────────────────────────────────────────────────
163
+ /** Subscribe to matching event types in real-time.
164
+ *
165
+ * Returns a gRPC server-streaming call. Records are pushed as they
166
+ * are committed and filtered by `eventTypes`. The consumer offset
167
+ * is tracked server-side.
168
+ *
169
+ * Usage:
170
+ * const stream = client.subscribe('my-app', 'main', ['tool.call'], 'group', 'w1');
171
+ * stream.on('data', (rec) => console.log(rec.eventType, rec.content));
172
+ */
173
+ subscribe(namespace, stream, eventTypes, consumerGroup, consumerId) {
174
+ return this.client.Subscribe({
175
+ namespace,
176
+ stream,
177
+ eventTypes,
178
+ consumerGroup,
179
+ consumerId,
180
+ });
181
+ }
162
182
  /** Subscribe to new records via Tail. */
163
183
  tail(namespace, stream, opts) {
164
184
  const call = this.client.Tail({
@@ -170,6 +190,21 @@ class Client {
170
190
  });
171
191
  return new tail_stream_1.TailStream(call, convertRecord);
172
192
  }
193
+ // ── Query ──────────────────────────────────────────────────────────
194
+ /** Execute a read-only SQL query against a stream's query cache.
195
+ *
196
+ * Only SELECT is allowed — enforced at the SQLite kernel level.
197
+ * Each row is returned as a JSON string.
198
+ */
199
+ query(namespace, stream, sql) {
200
+ return new Promise((resolve, reject) => {
201
+ this.client.Query({ namespace, stream, sql }, (err, resp) => {
202
+ if (err)
203
+ return reject(err);
204
+ resolve(resp.rows || []);
205
+ });
206
+ });
207
+ }
173
208
  // ── Watermark ──────────────────────────────────────────────────────
174
209
  /** Get the watermark for a namespace/stream. */
175
210
  watermark(namespace, stream) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lv-agent/logdb-client",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "TypeScript SDK for logdbd — append-only audit log database",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",