@autono/pinbox-core 0.1.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 +17 -0
- package/dist/auth/verify.d.ts +15 -0
- package/dist/auth/verify.js +2 -0
- package/dist/connectors/github.d.ts +5 -0
- package/dist/connectors/github.js +49 -0
- package/dist/connectors/index.d.ts +37 -0
- package/dist/connectors/index.js +103 -0
- package/dist/context-BHcEpzVb.js +30 -0
- package/dist/delivery/openclaw.d.ts +10 -0
- package/dist/delivery/openclaw.js +50 -0
- package/dist/delivery/resume.d.ts +23 -0
- package/dist/delivery/resume.js +102 -0
- package/dist/delivery/router.d.ts +2 -0
- package/dist/delivery/router.js +262 -0
- package/dist/delivery/webhook.d.ts +9 -0
- package/dist/delivery/webhook.js +52 -0
- package/dist/do.d.ts +67 -0
- package/dist/do.js +713 -0
- package/dist/hub-QYz6OqYQ.js +328 -0
- package/dist/hub-server.d.ts +44 -0
- package/dist/hub-server.js +251 -0
- package/dist/hub.d.ts +125 -0
- package/dist/hub.js +2 -0
- package/dist/markdown.d.ts +14 -0
- package/dist/markdown.js +87 -0
- package/dist/payload-m1DbRWDD.d.ts +6 -0
- package/dist/poll-BrcAuaAz.js +252 -0
- package/dist/proc-BMp_pbPS.js +42 -0
- package/dist/router-D3dDjIaD.d.ts +62 -0
- package/dist/schema-BOTmn5SM.d.ts +297 -0
- package/dist/schema.d.ts +2 -0
- package/dist/schema.js +121 -0
- package/dist/schema.json +403 -0
- package/dist/sessions-CJdMBH3C.d.ts +47 -0
- package/dist/sessions-DrCVTMfI.js +129 -0
- package/dist/sessions.d.ts +2 -0
- package/dist/sessions.js +2 -0
- package/dist/store-DHbwWu93.d.ts +105 -0
- package/dist/store-DM8MjB8M.js +479 -0
- package/dist/store.d.ts +2 -0
- package/dist/store.js +3 -0
- package/dist/types-BLNQb7MH.d.ts +28 -0
- package/dist/verify-BDt9d9Np.js +55 -0
- package/dist/ws-protocol.d.ts +61 -0
- package/dist/ws-protocol.js +51 -0
- package/dist/ws.d.ts +7 -0
- package/dist/ws.js +1 -0
- package/package.json +104 -0
package/dist/schema.json
ADDED
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"properties": {
|
|
5
|
+
"text": {
|
|
6
|
+
"type": "string",
|
|
7
|
+
"minLength": 1
|
|
8
|
+
},
|
|
9
|
+
"kind": {
|
|
10
|
+
"default": "note",
|
|
11
|
+
"type": "string",
|
|
12
|
+
"enum": [
|
|
13
|
+
"note",
|
|
14
|
+
"move"
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
"target": {
|
|
18
|
+
"type": "object",
|
|
19
|
+
"properties": {
|
|
20
|
+
"url": {
|
|
21
|
+
"type": "string"
|
|
22
|
+
},
|
|
23
|
+
"selector": {
|
|
24
|
+
"type": "string"
|
|
25
|
+
},
|
|
26
|
+
"tag": {
|
|
27
|
+
"type": "string"
|
|
28
|
+
},
|
|
29
|
+
"rect": {
|
|
30
|
+
"type": "object",
|
|
31
|
+
"properties": {
|
|
32
|
+
"x": {
|
|
33
|
+
"type": "number"
|
|
34
|
+
},
|
|
35
|
+
"y": {
|
|
36
|
+
"type": "number"
|
|
37
|
+
},
|
|
38
|
+
"width": {
|
|
39
|
+
"type": "number"
|
|
40
|
+
},
|
|
41
|
+
"height": {
|
|
42
|
+
"type": "number"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"required": [
|
|
46
|
+
"x",
|
|
47
|
+
"y",
|
|
48
|
+
"width",
|
|
49
|
+
"height"
|
|
50
|
+
],
|
|
51
|
+
"additionalProperties": false
|
|
52
|
+
},
|
|
53
|
+
"fixed": {
|
|
54
|
+
"type": "boolean"
|
|
55
|
+
},
|
|
56
|
+
"anchor": {
|
|
57
|
+
"type": "string"
|
|
58
|
+
},
|
|
59
|
+
"source": {
|
|
60
|
+
"type": "object",
|
|
61
|
+
"properties": {
|
|
62
|
+
"file": {
|
|
63
|
+
"type": "string"
|
|
64
|
+
},
|
|
65
|
+
"line": {
|
|
66
|
+
"type": "number"
|
|
67
|
+
},
|
|
68
|
+
"via": {
|
|
69
|
+
"type": "string",
|
|
70
|
+
"enum": [
|
|
71
|
+
"plugin",
|
|
72
|
+
"framework",
|
|
73
|
+
"none"
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"required": [
|
|
78
|
+
"file",
|
|
79
|
+
"via"
|
|
80
|
+
],
|
|
81
|
+
"additionalProperties": false
|
|
82
|
+
},
|
|
83
|
+
"context": {
|
|
84
|
+
"type": "object",
|
|
85
|
+
"properties": {
|
|
86
|
+
"classes": {
|
|
87
|
+
"type": "array",
|
|
88
|
+
"items": {
|
|
89
|
+
"type": "string"
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"styles": {
|
|
93
|
+
"type": "object",
|
|
94
|
+
"propertyNames": {
|
|
95
|
+
"type": "string"
|
|
96
|
+
},
|
|
97
|
+
"additionalProperties": {
|
|
98
|
+
"type": "string"
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"aria": {
|
|
102
|
+
"type": "object",
|
|
103
|
+
"propertyNames": {
|
|
104
|
+
"type": "string"
|
|
105
|
+
},
|
|
106
|
+
"additionalProperties": {
|
|
107
|
+
"type": "string"
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
"nearbyText": {
|
|
111
|
+
"type": "string"
|
|
112
|
+
},
|
|
113
|
+
"selectedText": {
|
|
114
|
+
"type": "string"
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
"additionalProperties": false
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
"additionalProperties": false
|
|
121
|
+
},
|
|
122
|
+
"move": {
|
|
123
|
+
"type": "object",
|
|
124
|
+
"properties": {
|
|
125
|
+
"from": {
|
|
126
|
+
"type": "object",
|
|
127
|
+
"properties": {
|
|
128
|
+
"x": {
|
|
129
|
+
"type": "number"
|
|
130
|
+
},
|
|
131
|
+
"y": {
|
|
132
|
+
"type": "number"
|
|
133
|
+
},
|
|
134
|
+
"width": {
|
|
135
|
+
"type": "number"
|
|
136
|
+
},
|
|
137
|
+
"height": {
|
|
138
|
+
"type": "number"
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
"required": [
|
|
142
|
+
"x",
|
|
143
|
+
"y",
|
|
144
|
+
"width",
|
|
145
|
+
"height"
|
|
146
|
+
],
|
|
147
|
+
"additionalProperties": false
|
|
148
|
+
},
|
|
149
|
+
"to": {
|
|
150
|
+
"type": "object",
|
|
151
|
+
"properties": {
|
|
152
|
+
"x": {
|
|
153
|
+
"type": "number"
|
|
154
|
+
},
|
|
155
|
+
"y": {
|
|
156
|
+
"type": "number"
|
|
157
|
+
},
|
|
158
|
+
"width": {
|
|
159
|
+
"type": "number"
|
|
160
|
+
},
|
|
161
|
+
"height": {
|
|
162
|
+
"type": "number"
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
"required": [
|
|
166
|
+
"x",
|
|
167
|
+
"y",
|
|
168
|
+
"width",
|
|
169
|
+
"height"
|
|
170
|
+
],
|
|
171
|
+
"additionalProperties": false
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
"required": [
|
|
175
|
+
"from",
|
|
176
|
+
"to"
|
|
177
|
+
],
|
|
178
|
+
"additionalProperties": false
|
|
179
|
+
},
|
|
180
|
+
"env": {
|
|
181
|
+
"type": "object",
|
|
182
|
+
"properties": {
|
|
183
|
+
"viewport": {
|
|
184
|
+
"type": "object",
|
|
185
|
+
"properties": {
|
|
186
|
+
"w": {
|
|
187
|
+
"type": "number"
|
|
188
|
+
},
|
|
189
|
+
"h": {
|
|
190
|
+
"type": "number"
|
|
191
|
+
},
|
|
192
|
+
"dpr": {
|
|
193
|
+
"type": "number"
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
"required": [
|
|
197
|
+
"w",
|
|
198
|
+
"h",
|
|
199
|
+
"dpr"
|
|
200
|
+
],
|
|
201
|
+
"additionalProperties": false
|
|
202
|
+
},
|
|
203
|
+
"browser": {
|
|
204
|
+
"type": "string"
|
|
205
|
+
},
|
|
206
|
+
"os": {
|
|
207
|
+
"type": "string"
|
|
208
|
+
},
|
|
209
|
+
"colorScheme": {
|
|
210
|
+
"type": "string",
|
|
211
|
+
"enum": [
|
|
212
|
+
"light",
|
|
213
|
+
"dark"
|
|
214
|
+
]
|
|
215
|
+
},
|
|
216
|
+
"branch": {
|
|
217
|
+
"type": "string"
|
|
218
|
+
},
|
|
219
|
+
"commit": {
|
|
220
|
+
"type": "string"
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
"additionalProperties": false
|
|
224
|
+
},
|
|
225
|
+
"author": {
|
|
226
|
+
"type": "object",
|
|
227
|
+
"properties": {
|
|
228
|
+
"userId": {
|
|
229
|
+
"type": "string"
|
|
230
|
+
},
|
|
231
|
+
"name": {
|
|
232
|
+
"type": "string"
|
|
233
|
+
},
|
|
234
|
+
"email": {
|
|
235
|
+
"type": "string"
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
"required": [
|
|
239
|
+
"userId"
|
|
240
|
+
],
|
|
241
|
+
"additionalProperties": false
|
|
242
|
+
},
|
|
243
|
+
"agentSession": {
|
|
244
|
+
"type": "object",
|
|
245
|
+
"properties": {
|
|
246
|
+
"agent": {
|
|
247
|
+
"type": "string"
|
|
248
|
+
},
|
|
249
|
+
"key": {
|
|
250
|
+
"type": "string"
|
|
251
|
+
},
|
|
252
|
+
"cwd": {
|
|
253
|
+
"type": "string"
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
"required": [
|
|
257
|
+
"agent",
|
|
258
|
+
"key"
|
|
259
|
+
],
|
|
260
|
+
"additionalProperties": false
|
|
261
|
+
},
|
|
262
|
+
"attachments": {
|
|
263
|
+
"type": "array",
|
|
264
|
+
"items": {
|
|
265
|
+
"type": "object",
|
|
266
|
+
"properties": {
|
|
267
|
+
"id": {
|
|
268
|
+
"type": "string"
|
|
269
|
+
},
|
|
270
|
+
"kind": {
|
|
271
|
+
"type": "string",
|
|
272
|
+
"enum": [
|
|
273
|
+
"screenshot",
|
|
274
|
+
"file"
|
|
275
|
+
]
|
|
276
|
+
},
|
|
277
|
+
"path": {
|
|
278
|
+
"type": "string"
|
|
279
|
+
},
|
|
280
|
+
"url": {
|
|
281
|
+
"type": "string"
|
|
282
|
+
},
|
|
283
|
+
"contentType": {
|
|
284
|
+
"type": "string"
|
|
285
|
+
},
|
|
286
|
+
"width": {
|
|
287
|
+
"type": "integer",
|
|
288
|
+
"minimum": -9007199254740991,
|
|
289
|
+
"maximum": 9007199254740991
|
|
290
|
+
},
|
|
291
|
+
"height": {
|
|
292
|
+
"type": "integer",
|
|
293
|
+
"minimum": -9007199254740991,
|
|
294
|
+
"maximum": 9007199254740991
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
"required": [
|
|
298
|
+
"id",
|
|
299
|
+
"kind"
|
|
300
|
+
],
|
|
301
|
+
"additionalProperties": false
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
"id": {
|
|
305
|
+
"type": "string",
|
|
306
|
+
"pattern": "^pin_[a-z0-9]{10}$"
|
|
307
|
+
},
|
|
308
|
+
"schemaVersion": {
|
|
309
|
+
"type": "number",
|
|
310
|
+
"const": 1
|
|
311
|
+
},
|
|
312
|
+
"status": {
|
|
313
|
+
"default": "open",
|
|
314
|
+
"type": "string",
|
|
315
|
+
"enum": [
|
|
316
|
+
"open",
|
|
317
|
+
"resolved"
|
|
318
|
+
]
|
|
319
|
+
},
|
|
320
|
+
"createdAt": {
|
|
321
|
+
"type": "string"
|
|
322
|
+
},
|
|
323
|
+
"resolution": {
|
|
324
|
+
"type": "object",
|
|
325
|
+
"properties": {
|
|
326
|
+
"by": {
|
|
327
|
+
"type": "string",
|
|
328
|
+
"enum": [
|
|
329
|
+
"human",
|
|
330
|
+
"agent"
|
|
331
|
+
]
|
|
332
|
+
},
|
|
333
|
+
"note": {
|
|
334
|
+
"type": "string"
|
|
335
|
+
},
|
|
336
|
+
"commit": {
|
|
337
|
+
"type": "string"
|
|
338
|
+
},
|
|
339
|
+
"at": {
|
|
340
|
+
"type": "string"
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
"required": [
|
|
344
|
+
"by",
|
|
345
|
+
"at"
|
|
346
|
+
],
|
|
347
|
+
"additionalProperties": false
|
|
348
|
+
},
|
|
349
|
+
"verification": {
|
|
350
|
+
"type": "object",
|
|
351
|
+
"properties": {
|
|
352
|
+
"outcome": {
|
|
353
|
+
"type": "string",
|
|
354
|
+
"enum": [
|
|
355
|
+
"accepted",
|
|
356
|
+
"reopened"
|
|
357
|
+
]
|
|
358
|
+
},
|
|
359
|
+
"at": {
|
|
360
|
+
"type": "string"
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
"required": [
|
|
364
|
+
"outcome",
|
|
365
|
+
"at"
|
|
366
|
+
],
|
|
367
|
+
"additionalProperties": false
|
|
368
|
+
},
|
|
369
|
+
"links": {
|
|
370
|
+
"type": "array",
|
|
371
|
+
"items": {
|
|
372
|
+
"type": "object",
|
|
373
|
+
"properties": {
|
|
374
|
+
"connector": {
|
|
375
|
+
"type": "string"
|
|
376
|
+
},
|
|
377
|
+
"ref": {
|
|
378
|
+
"type": "string"
|
|
379
|
+
},
|
|
380
|
+
"url": {
|
|
381
|
+
"type": "string"
|
|
382
|
+
}
|
|
383
|
+
},
|
|
384
|
+
"required": [
|
|
385
|
+
"connector",
|
|
386
|
+
"ref",
|
|
387
|
+
"url"
|
|
388
|
+
],
|
|
389
|
+
"additionalProperties": false
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
"required": [
|
|
394
|
+
"text",
|
|
395
|
+
"kind",
|
|
396
|
+
"author",
|
|
397
|
+
"id",
|
|
398
|
+
"schemaVersion",
|
|
399
|
+
"status",
|
|
400
|
+
"createdAt"
|
|
401
|
+
],
|
|
402
|
+
"additionalProperties": false
|
|
403
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { f as SessionRef } from "./schema-BOTmn5SM.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { Database } from "bun:sqlite";
|
|
4
|
+
//#region src/trailer.d.ts
|
|
5
|
+
/** Unique pin ids named by resolution trailers, in order of appearance. */
|
|
6
|
+
declare function parseTrailers(message: string): string[];
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/sessions.d.ts
|
|
9
|
+
declare const SessionSchema: z.ZodObject<{
|
|
10
|
+
id: z.ZodString;
|
|
11
|
+
agent: z.ZodString;
|
|
12
|
+
key: z.ZodString;
|
|
13
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
14
|
+
registeredAt: z.ZodString;
|
|
15
|
+
lastSeenAt: z.ZodString;
|
|
16
|
+
endedAt: z.ZodOptional<z.ZodString>;
|
|
17
|
+
}, z.core.$strip>;
|
|
18
|
+
type Session = z.infer<typeof SessionSchema>;
|
|
19
|
+
interface SessionStore {
|
|
20
|
+
register(ref: SessionRef): Session;
|
|
21
|
+
get(id: string): Session | null;
|
|
22
|
+
findByRef(ref: Pick<SessionRef, "agent" | "key">): Session | null;
|
|
23
|
+
active(): Session | null;
|
|
24
|
+
list(): Session[];
|
|
25
|
+
touch(id: string): void;
|
|
26
|
+
end(id: string): void;
|
|
27
|
+
}
|
|
28
|
+
declare class SqliteSessionStore implements SessionStore {
|
|
29
|
+
private readonly insert;
|
|
30
|
+
private readonly update;
|
|
31
|
+
private readonly selectById;
|
|
32
|
+
private readonly selectByRef;
|
|
33
|
+
private readonly selectActive;
|
|
34
|
+
private readonly selectAll;
|
|
35
|
+
constructor(db: Database);
|
|
36
|
+
register(ref: SessionRef): Session;
|
|
37
|
+
get(id: string): Session | null;
|
|
38
|
+
findByRef(ref: Pick<SessionRef, "agent" | "key">): Session | null;
|
|
39
|
+
active(): Session | null;
|
|
40
|
+
list(): Session[];
|
|
41
|
+
touch(id: string): void;
|
|
42
|
+
end(id: string): void;
|
|
43
|
+
private write;
|
|
44
|
+
private mustGet;
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { parseTrailers as a, SqliteSessionStore as i, SessionSchema as n, SessionStore as r, Session as t };
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/id.ts
|
|
3
|
+
const ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
4
|
+
function newId(prefix) {
|
|
5
|
+
const bytes = /* @__PURE__ */ new Uint8Array(10);
|
|
6
|
+
crypto.getRandomValues(bytes);
|
|
7
|
+
let out = "";
|
|
8
|
+
for (const b of bytes) out += ALPHABET[b % 36];
|
|
9
|
+
return `${prefix}_${out}`;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/store-errors.ts
|
|
13
|
+
/** The addressed row does not exist. Mapped to 404 / `E_NOT_FOUND` by the hub. */
|
|
14
|
+
var NotFoundError = class extends Error {};
|
|
15
|
+
/** The write conflicts with current state (e.g. resolving an already-resolved pin). 409 / `E_CONFLICT`. */
|
|
16
|
+
var ConflictError = class extends Error {};
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/trailer.ts
|
|
19
|
+
const TRAILER = /\b(?:fixes|resolves|closes):?\s+(?:pin\s+)?(pin_[a-z0-9]{10})\b/gi;
|
|
20
|
+
/** Unique pin ids named by resolution trailers, in order of appearance. */
|
|
21
|
+
function parseTrailers(message) {
|
|
22
|
+
const ids = [];
|
|
23
|
+
for (const match of message.matchAll(TRAILER)) {
|
|
24
|
+
const id = match[1];
|
|
25
|
+
if (id !== void 0 && !ids.includes(id)) ids.push(id);
|
|
26
|
+
}
|
|
27
|
+
return ids;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/sessions.ts
|
|
31
|
+
const SessionSchema = z.object({
|
|
32
|
+
id: z.string().regex(/^ses_[a-z0-9]{10}$/),
|
|
33
|
+
agent: z.string(),
|
|
34
|
+
key: z.string(),
|
|
35
|
+
cwd: z.string().optional(),
|
|
36
|
+
registeredAt: z.string(),
|
|
37
|
+
lastSeenAt: z.string(),
|
|
38
|
+
endedAt: z.string().optional()
|
|
39
|
+
});
|
|
40
|
+
var JsonRow = class {
|
|
41
|
+
json;
|
|
42
|
+
};
|
|
43
|
+
function parseSession(json) {
|
|
44
|
+
return SessionSchema.parse(JSON.parse(json));
|
|
45
|
+
}
|
|
46
|
+
var SqliteSessionStore = class {
|
|
47
|
+
insert;
|
|
48
|
+
update;
|
|
49
|
+
selectById;
|
|
50
|
+
selectByRef;
|
|
51
|
+
selectActive;
|
|
52
|
+
selectAll;
|
|
53
|
+
constructor(db) {
|
|
54
|
+
this.insert = db.query(`INSERT INTO sessions (id, agent, key, cwd, registered_at, last_seen_at, ended_at, json)
|
|
55
|
+
VALUES (?, ?, ?, ?, ?, ?, NULL, ?)`);
|
|
56
|
+
this.update = db.query("UPDATE sessions SET cwd = ?, last_seen_at = ?, ended_at = ?, json = ? WHERE id = ?");
|
|
57
|
+
this.selectById = db.query("SELECT json FROM sessions WHERE id = ?").as(JsonRow);
|
|
58
|
+
this.selectByRef = db.query("SELECT json FROM sessions WHERE agent = ? AND key = ?").as(JsonRow);
|
|
59
|
+
this.selectActive = db.query(`SELECT json FROM sessions WHERE ended_at IS NULL
|
|
60
|
+
ORDER BY last_seen_at DESC, rowid DESC LIMIT 1`).as(JsonRow);
|
|
61
|
+
this.selectAll = db.query("SELECT json FROM sessions ORDER BY last_seen_at DESC, rowid DESC").as(JsonRow);
|
|
62
|
+
}
|
|
63
|
+
register(ref) {
|
|
64
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
65
|
+
const existing = this.findByRef(ref);
|
|
66
|
+
if (existing) {
|
|
67
|
+
const cwd = ref.cwd ?? existing.cwd;
|
|
68
|
+
const session = SessionSchema.parse({
|
|
69
|
+
id: existing.id,
|
|
70
|
+
agent: existing.agent,
|
|
71
|
+
key: existing.key,
|
|
72
|
+
...cwd !== void 0 ? { cwd } : {},
|
|
73
|
+
registeredAt: existing.registeredAt,
|
|
74
|
+
lastSeenAt: now
|
|
75
|
+
});
|
|
76
|
+
this.write(session);
|
|
77
|
+
return session;
|
|
78
|
+
}
|
|
79
|
+
const session = SessionSchema.parse({
|
|
80
|
+
id: newId("ses"),
|
|
81
|
+
agent: ref.agent,
|
|
82
|
+
key: ref.key,
|
|
83
|
+
...ref.cwd !== void 0 ? { cwd: ref.cwd } : {},
|
|
84
|
+
registeredAt: now,
|
|
85
|
+
lastSeenAt: now
|
|
86
|
+
});
|
|
87
|
+
this.insert.run(session.id, session.agent, session.key, session.cwd ?? null, session.registeredAt, session.lastSeenAt, JSON.stringify(session));
|
|
88
|
+
return session;
|
|
89
|
+
}
|
|
90
|
+
get(id) {
|
|
91
|
+
const row = this.selectById.get(id);
|
|
92
|
+
return row ? parseSession(row.json) : null;
|
|
93
|
+
}
|
|
94
|
+
findByRef(ref) {
|
|
95
|
+
const row = this.selectByRef.get(ref.agent, ref.key);
|
|
96
|
+
return row ? parseSession(row.json) : null;
|
|
97
|
+
}
|
|
98
|
+
active() {
|
|
99
|
+
const row = this.selectActive.get();
|
|
100
|
+
return row ? parseSession(row.json) : null;
|
|
101
|
+
}
|
|
102
|
+
list() {
|
|
103
|
+
return this.selectAll.all().map((r) => parseSession(r.json));
|
|
104
|
+
}
|
|
105
|
+
touch(id) {
|
|
106
|
+
const session = this.mustGet(id);
|
|
107
|
+
this.write({
|
|
108
|
+
...session,
|
|
109
|
+
lastSeenAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
end(id) {
|
|
113
|
+
const session = this.mustGet(id);
|
|
114
|
+
this.write({
|
|
115
|
+
...session,
|
|
116
|
+
endedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
write(session) {
|
|
120
|
+
this.update.run(session.cwd ?? null, session.lastSeenAt, session.endedAt ?? null, JSON.stringify(session), session.id);
|
|
121
|
+
}
|
|
122
|
+
mustGet(id) {
|
|
123
|
+
const session = this.get(id);
|
|
124
|
+
if (!session) throw new NotFoundError(`session not found: ${id}`);
|
|
125
|
+
return session;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
//#endregion
|
|
129
|
+
export { NotFoundError as a, ConflictError as i, SqliteSessionStore as n, newId as o, parseTrailers as r, SessionSchema as t };
|
package/dist/sessions.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { a as Pin, f as SessionRef, m as ThreadMessage, o as PinInput, r as Link, t as Attachment } from "./schema-BOTmn5SM.js";
|
|
2
|
+
import { r as SessionStore } from "./sessions-CJdMBH3C.js";
|
|
3
|
+
//#region src/store-errors.d.ts
|
|
4
|
+
/** The addressed row does not exist. Mapped to 404 / `E_NOT_FOUND` by the hub. */
|
|
5
|
+
declare class NotFoundError extends Error {}
|
|
6
|
+
/** The write conflicts with current state (e.g. resolving an already-resolved pin). 409 / `E_CONFLICT`. */
|
|
7
|
+
declare class ConflictError extends Error {}
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/store.d.ts
|
|
10
|
+
type StoredEvent = {
|
|
11
|
+
seq: number;
|
|
12
|
+
type: "pin.created" | "pin.resolved" | "thread.message" | "pin.verified" | "pin.linked";
|
|
13
|
+
at: string;
|
|
14
|
+
payload: unknown;
|
|
15
|
+
};
|
|
16
|
+
interface PinStore {
|
|
17
|
+
/** Assigns id/status/createdAt, merges env, appends pin.created. */
|
|
18
|
+
createPin(input: PinInput, env: {
|
|
19
|
+
branch?: string;
|
|
20
|
+
commit?: string;
|
|
21
|
+
}): Pin;
|
|
22
|
+
getPin(id: string): Pin | null;
|
|
23
|
+
/** Newest first. */
|
|
24
|
+
listPins(filter?: {
|
|
25
|
+
status?: "open" | "resolved";
|
|
26
|
+
}): Pin[];
|
|
27
|
+
/** @throws NotFoundError — additive opts param (attachments, origin) */
|
|
28
|
+
addThreadMessage(pinId: string, role: "human" | "agent" | "mirror", text: string, opts?: {
|
|
29
|
+
origin?: string;
|
|
30
|
+
attachments?: Attachment[];
|
|
31
|
+
}): ThreadMessage;
|
|
32
|
+
getThread(pinId: string): ThreadMessage[];
|
|
33
|
+
/** @throws NotFoundError @throws ConflictError — the trailing commit param is additive */
|
|
34
|
+
resolvePin(id: string, by: "human" | "agent", note?: string, commit?: string): Pin;
|
|
35
|
+
/** Inbound-poll deadline. @throws NotFoundError */
|
|
36
|
+
setDueAt(id: string, at: string | null): void;
|
|
37
|
+
/** due_at IS NOT NULL AND due_at <= at, oldest deadline first. */
|
|
38
|
+
pinsDueBefore(at: string): Pin[];
|
|
39
|
+
eventsAfter(seq: number): StoredEvent[];
|
|
40
|
+
summary(): {
|
|
41
|
+
open: number;
|
|
42
|
+
resolved: number;
|
|
43
|
+
lastEventSeq: number;
|
|
44
|
+
};
|
|
45
|
+
close(): void;
|
|
46
|
+
subscribe(listener: (event: StoredEvent) => void): () => void;
|
|
47
|
+
readonly sessions: SessionStore;
|
|
48
|
+
readonly deliveries: DeliveryStore;
|
|
49
|
+
/** Persists the routing binding into pin.agentSession. No event. @throws NotFoundError */
|
|
50
|
+
bindSession(pinId: string, ref: SessionRef): Pin;
|
|
51
|
+
verifyPin(id: string, outcome: "accepted" | "reopened"): Pin;
|
|
52
|
+
searchPins(query: string): Pin[];
|
|
53
|
+
readonly cursors: CursorStore;
|
|
54
|
+
addLink(pinId: string, link: Link): Pin;
|
|
55
|
+
readonly links: LinkStore;
|
|
56
|
+
}
|
|
57
|
+
type DeliveryStatus = "pending" | "delivered" | "failed" | "skipped";
|
|
58
|
+
type DeliveryRow = {
|
|
59
|
+
id: number;
|
|
60
|
+
eventSeq: number;
|
|
61
|
+
sessionId: string | null;
|
|
62
|
+
adapter: string;
|
|
63
|
+
status: DeliveryStatus;
|
|
64
|
+
attempts: number;
|
|
65
|
+
dueAt: string | null;
|
|
66
|
+
lastError: string | null;
|
|
67
|
+
updatedAt: string;
|
|
68
|
+
};
|
|
69
|
+
interface DeliveryStore {
|
|
70
|
+
enqueue(row: {
|
|
71
|
+
eventSeq: number;
|
|
72
|
+
sessionId: string | null;
|
|
73
|
+
adapter: string;
|
|
74
|
+
dueAt: string | null;
|
|
75
|
+
status?: "pending" | "skipped";
|
|
76
|
+
}): DeliveryRow;
|
|
77
|
+
due(now: string): DeliveryRow[];
|
|
78
|
+
pendingForSession(sessionId: string): DeliveryRow[];
|
|
79
|
+
unassigned(): DeliveryRow[];
|
|
80
|
+
assign(id: number, sessionId: string): void;
|
|
81
|
+
markDelivered(id: number): void;
|
|
82
|
+
markFailed(id: number, error: string, retryAt: string | null): void;
|
|
83
|
+
lastEventSeq(): number;
|
|
84
|
+
}
|
|
85
|
+
interface CursorStore {
|
|
86
|
+
get(consumerId: string): number;
|
|
87
|
+
set(consumerId: string, lastSeq: number): void;
|
|
88
|
+
}
|
|
89
|
+
interface LinkStore {
|
|
90
|
+
forPin(pinId: string): Link[];
|
|
91
|
+
all(): {
|
|
92
|
+
pinId: string;
|
|
93
|
+
link: Link;
|
|
94
|
+
lastSyncedAt: string | null;
|
|
95
|
+
}[];
|
|
96
|
+
markSynced(pinId: string, link: Pick<Link, "connector" | "ref">, at: string): void;
|
|
97
|
+
}
|
|
98
|
+
type Migration = {
|
|
99
|
+
version: number;
|
|
100
|
+
ddl: string;
|
|
101
|
+
};
|
|
102
|
+
declare const MIGRATIONS: Migration[];
|
|
103
|
+
declare function openStore(path: string): PinStore;
|
|
104
|
+
//#endregion
|
|
105
|
+
export { LinkStore as a, PinStore as c, ConflictError as d, NotFoundError as f, DeliveryStore as i, StoredEvent as l, DeliveryRow as n, MIGRATIONS as o, DeliveryStatus as r, Migration as s, CursorStore as t, openStore as u };
|