@pingagent/sdk 0.1.3 → 0.1.4

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/dist/index.d.ts CHANGED
@@ -67,7 +67,18 @@ declare class HistoryManager {
67
67
  limit?: number;
68
68
  beforeSeq?: number;
69
69
  afterSeq?: number;
70
+ beforeTsMs?: number;
71
+ afterTsMs?: number;
70
72
  }): StoredMessage[];
73
+ /**
74
+ * List the most recent N messages *before* a seq (paging older history).
75
+ * Only compares rows where seq is not null.
76
+ */
77
+ listBeforeSeq(conversationId: string, beforeSeq: number, limit: number): StoredMessage[];
78
+ /**
79
+ * List the most recent N messages *before* a timestamp (paging older history).
80
+ */
81
+ listBeforeTs(conversationId: string, beforeTsMs: number, limit: number): StoredMessage[];
71
82
  /** Returns the N most recent messages (chronological order, oldest to newest of those N). */
72
83
  listRecent(conversationId: string, limit: number): StoredMessage[];
73
84
  search(query: string, opts?: {
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@ import {
16
16
  loadIdentity,
17
17
  saveIdentity,
18
18
  updateStoredToken
19
- } from "./chunk-HMVPT5N4.js";
19
+ } from "./chunk-YS54ADYV.js";
20
20
  export {
21
21
  A2AAdapter,
22
22
  ContactManager,
@@ -5,7 +5,7 @@ import {
5
5
  ensureTokenValid,
6
6
  loadIdentity,
7
7
  updateStoredToken
8
- } from "./chunk-HMVPT5N4.js";
8
+ } from "./chunk-YS54ADYV.js";
9
9
 
10
10
  // src/web-server.ts
11
11
  import * as fs from "fs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pingagent/sdk",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -26,9 +26,9 @@
26
26
  "commander": "^13.0.0",
27
27
  "uuid": "^11.0.0",
28
28
  "ws": "^8.0.0",
29
- "@pingagent/protocol": "0.1.1",
30
29
  "@pingagent/schemas": "0.1.1",
31
- "@pingagent/a2a": "0.1.1"
30
+ "@pingagent/a2a": "0.1.1",
31
+ "@pingagent/protocol": "0.1.1"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/better-sqlite3": "^7.6.0",
package/src/history.ts CHANGED
@@ -82,7 +82,10 @@ export class HistoryManager {
82
82
  return count;
83
83
  }
84
84
 
85
- list(conversationId: string, opts?: { limit?: number; beforeSeq?: number; afterSeq?: number }): StoredMessage[] {
85
+ list(
86
+ conversationId: string,
87
+ opts?: { limit?: number; beforeSeq?: number; afterSeq?: number; beforeTsMs?: number; afterTsMs?: number },
88
+ ): StoredMessage[] {
86
89
  const conditions = ['conversation_id = ?'];
87
90
  const params: any[] = [conversationId];
88
91
 
@@ -94,6 +97,14 @@ export class HistoryManager {
94
97
  conditions.push('seq > ?');
95
98
  params.push(opts.afterSeq);
96
99
  }
100
+ if (opts?.beforeTsMs !== undefined) {
101
+ conditions.push('ts_ms < ?');
102
+ params.push(opts.beforeTsMs);
103
+ }
104
+ if (opts?.afterTsMs !== undefined) {
105
+ conditions.push('ts_ms > ?');
106
+ params.push(opts.afterTsMs);
107
+ }
97
108
 
98
109
  const limit = opts?.limit ?? 100;
99
110
  const rows = this.store.getDb()
@@ -102,6 +113,37 @@ export class HistoryManager {
102
113
  return rows.map(rowToMessage);
103
114
  }
104
115
 
116
+ /**
117
+ * List the most recent N messages *before* a seq (paging older history).
118
+ * Only compares rows where seq is not null.
119
+ */
120
+ listBeforeSeq(conversationId: string, beforeSeq: number, limit: number): StoredMessage[] {
121
+ const rows = this.store.getDb()
122
+ .prepare(
123
+ `SELECT * FROM messages
124
+ WHERE conversation_id = ? AND seq IS NOT NULL AND seq < ?
125
+ ORDER BY seq DESC
126
+ LIMIT ?`,
127
+ )
128
+ .all(conversationId, beforeSeq, limit) as MessageRow[];
129
+ return rows.map(rowToMessage).reverse();
130
+ }
131
+
132
+ /**
133
+ * List the most recent N messages *before* a timestamp (paging older history).
134
+ */
135
+ listBeforeTs(conversationId: string, beforeTsMs: number, limit: number): StoredMessage[] {
136
+ const rows = this.store.getDb()
137
+ .prepare(
138
+ `SELECT * FROM messages
139
+ WHERE conversation_id = ? AND ts_ms < ?
140
+ ORDER BY ts_ms DESC
141
+ LIMIT ?`,
142
+ )
143
+ .all(conversationId, beforeTsMs, limit) as MessageRow[];
144
+ return rows.map(rowToMessage).reverse();
145
+ }
146
+
105
147
  /** Returns the N most recent messages (chronological order, oldest to newest of those N). */
106
148
  listRecent(conversationId: string, limit: number): StoredMessage[] {
107
149
  const rows = this.store.getDb()