@pingagent/sdk 0.1.2 → 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/bin/pingagent.js +25 -3
- package/dist/chunk-HMVPT5N4.js +1317 -0
- package/dist/chunk-YS54ADYV.js +1350 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +1 -1
- package/dist/web-server.js +2 -2
- package/package.json +3 -3
- package/src/auth.ts +1 -1
- package/src/history.ts +43 -1
- package/src/web-server.ts +1 -1
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
package/dist/web-server.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
ensureTokenValid,
|
|
6
6
|
loadIdentity,
|
|
7
7
|
updateStoredToken
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-YS54ADYV.js";
|
|
9
9
|
|
|
10
10
|
// src/web-server.ts
|
|
11
11
|
import * as fs from "fs";
|
|
@@ -75,7 +75,7 @@ function listProfiles(rootDir) {
|
|
|
75
75
|
}
|
|
76
76
|
return profiles;
|
|
77
77
|
}
|
|
78
|
-
var DEFAULT_SERVER_URL = "
|
|
78
|
+
var DEFAULT_SERVER_URL = "https://pingagent.chat";
|
|
79
79
|
async function getContextForProfile(profile, defaultServerUrl) {
|
|
80
80
|
const identity = loadIdentity(profile.identityPath);
|
|
81
81
|
const serverUrl = identity.serverUrl ?? defaultServerUrl ?? DEFAULT_SERVER_URL;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pingagent/sdk",
|
|
3
|
-
"version": "0.1.
|
|
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/
|
|
29
|
+
"@pingagent/schemas": "0.1.1",
|
|
30
30
|
"@pingagent/a2a": "0.1.1",
|
|
31
|
-
"@pingagent/
|
|
31
|
+
"@pingagent/protocol": "0.1.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/better-sqlite3": "^7.6.0",
|
package/src/auth.ts
CHANGED
|
@@ -26,7 +26,7 @@ export async function ensureTokenValid(
|
|
|
26
26
|
const now = Date.now();
|
|
27
27
|
if (expiresAt > now + REFRESH_GRACE_MS) return false; // still valid, no need to refresh
|
|
28
28
|
|
|
29
|
-
const baseUrl = (serverUrl ?? id.serverUrl ?? '
|
|
29
|
+
const baseUrl = (serverUrl ?? id.serverUrl ?? 'https://pingagent.chat').replace(/\/$/, '');
|
|
30
30
|
try {
|
|
31
31
|
const res = await fetch(`${baseUrl}/v1/auth/refresh`, {
|
|
32
32
|
method: 'POST',
|
package/src/history.ts
CHANGED
|
@@ -82,7 +82,10 @@ export class HistoryManager {
|
|
|
82
82
|
return count;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
list(
|
|
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()
|
package/src/web-server.ts
CHANGED
|
@@ -110,7 +110,7 @@ function listProfiles(rootDir: string): ProfileEntry[] {
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
/** Default server URL when identity has none (e.g. legacy). */
|
|
113
|
-
const DEFAULT_SERVER_URL = '
|
|
113
|
+
const DEFAULT_SERVER_URL = 'https://pingagent.chat';
|
|
114
114
|
|
|
115
115
|
async function getContextForProfile(
|
|
116
116
|
profile: ProfileEntry,
|