@glows777/vela-channels 0.0.0-stage → 0.5.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/CHANGELOG.md +263 -0
- package/LICENSE +21 -0
- package/README.md +4 -2
- package/dist/admission.d.ts +15 -0
- package/dist/admission.d.ts.map +1 -0
- package/dist/admission.js +31 -0
- package/dist/admission.js.map +1 -0
- package/dist/atomic-json.d.ts +3 -0
- package/dist/atomic-json.d.ts.map +1 -0
- package/dist/atomic-json.js +23 -0
- package/dist/atomic-json.js.map +1 -0
- package/dist/commands.d.ts +47 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +130 -0
- package/dist/commands.js.map +1 -0
- package/dist/directory.d.ts +144 -0
- package/dist/directory.d.ts.map +1 -0
- package/dist/directory.js +309 -0
- package/dist/directory.js.map +1 -0
- package/dist/event-receiver.d.ts +19 -0
- package/dist/event-receiver.d.ts.map +1 -0
- package/dist/event-receiver.js +192 -0
- package/dist/event-receiver.js.map +1 -0
- package/dist/events.d.ts +40 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +247 -0
- package/dist/events.js.map +1 -0
- package/dist/feedback.d.ts +61 -0
- package/dist/feedback.d.ts.map +1 -0
- package/dist/feedback.js +470 -0
- package/dist/feedback.js.map +1 -0
- package/dist/gateway.d.ts +76 -0
- package/dist/gateway.d.ts.map +1 -0
- package/dist/gateway.js +536 -0
- package/dist/gateway.js.map +1 -0
- package/dist/generic-events.d.ts +9 -0
- package/dist/generic-events.d.ts.map +1 -0
- package/dist/generic-events.js +33 -0
- package/dist/generic-events.js.map +1 -0
- package/dist/github-events.d.ts +11 -0
- package/dist/github-events.d.ts.map +1 -0
- package/dist/github-events.js +118 -0
- package/dist/github-events.js.map +1 -0
- package/dist/handoff.d.ts +28 -0
- package/dist/handoff.d.ts.map +1 -0
- package/dist/handoff.js +189 -0
- package/dist/handoff.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/log.d.ts +2 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +2 -0
- package/dist/log.js.map +1 -0
- package/dist/recovery.d.ts +19 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +190 -0
- package/dist/recovery.js.map +1 -0
- package/dist/routine-time.d.ts +8 -0
- package/dist/routine-time.d.ts.map +1 -0
- package/dist/routine-time.js +114 -0
- package/dist/routine-time.js.map +1 -0
- package/dist/routines.d.ts +126 -0
- package/dist/routines.d.ts.map +1 -0
- package/dist/routines.js +370 -0
- package/dist/routines.js.map +1 -0
- package/dist/scope.d.ts +11 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +26 -0
- package/dist/scope.js.map +1 -0
- package/dist/session-id.d.ts +6 -0
- package/dist/session-id.d.ts.map +1 -0
- package/dist/session-id.js +21 -0
- package/dist/session-id.js.map +1 -0
- package/dist/sessions.d.ts +13 -0
- package/dist/sessions.d.ts.map +1 -0
- package/dist/sessions.js +40 -0
- package/dist/sessions.js.map +1 -0
- package/dist/testing.d.ts +4 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +8 -0
- package/dist/testing.js.map +1 -0
- package/dist/types.d.ts +177 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/usage.d.ts +31 -0
- package/dist/usage.d.ts.map +1 -0
- package/dist/usage.js +151 -0
- package/dist/usage.js.map +1 -0
- package/dist/vela.d.ts +38 -0
- package/dist/vela.d.ts.map +1 -0
- package/dist/vela.js +112 -0
- package/dist/vela.js.map +1 -0
- package/package.json +41 -4
package/dist/commands.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/** Match only a complete normalized topic message, before history or sender decoration. */
|
|
2
|
+
function topicCommand(msg) {
|
|
3
|
+
const text = msg.text.trim();
|
|
4
|
+
if (text === '!routines')
|
|
5
|
+
return 'routines';
|
|
6
|
+
if (!msg.topic)
|
|
7
|
+
return;
|
|
8
|
+
if (text === '!stop')
|
|
9
|
+
return 'stop';
|
|
10
|
+
if (text === '!restart')
|
|
11
|
+
return 'restart';
|
|
12
|
+
if (text === '!status')
|
|
13
|
+
return 'status';
|
|
14
|
+
}
|
|
15
|
+
/** Topic command barriers and preparation cancellation; the gateway owns normal message queues. */
|
|
16
|
+
export class TopicCommands {
|
|
17
|
+
options;
|
|
18
|
+
commands = new Map();
|
|
19
|
+
processing = new Map();
|
|
20
|
+
active = new Set();
|
|
21
|
+
constructor(options) {
|
|
22
|
+
this.options = options;
|
|
23
|
+
}
|
|
24
|
+
begin(key) {
|
|
25
|
+
const state = { stopped: false };
|
|
26
|
+
this.processing.set(key, state);
|
|
27
|
+
return state;
|
|
28
|
+
}
|
|
29
|
+
end(key, state) {
|
|
30
|
+
if (this.processing.get(key) === state)
|
|
31
|
+
this.processing.delete(key);
|
|
32
|
+
}
|
|
33
|
+
receive(key, name, msg, admit, previous) {
|
|
34
|
+
const command = topicCommand(msg);
|
|
35
|
+
const barrier = this.commands.get(key);
|
|
36
|
+
// Only Stop/Restart cancel preparation; read-only commands leave live work alone.
|
|
37
|
+
const processing = !barrier &&
|
|
38
|
+
command &&
|
|
39
|
+
(command === 'stop' || command === 'restart') &&
|
|
40
|
+
this.processing.get(key);
|
|
41
|
+
if (processing && !this.options.stopped())
|
|
42
|
+
processing.stopped = true;
|
|
43
|
+
const stopping = processing ? this.options.feedback.stop(key) : undefined;
|
|
44
|
+
void stopping?.catch(() => { });
|
|
45
|
+
const admitted = admit();
|
|
46
|
+
if (command) {
|
|
47
|
+
const next = this.handleCommand(key, name, msg, command, admitted, previous, barrier, stopping);
|
|
48
|
+
const blocks = command === 'stop' || command === 'restart';
|
|
49
|
+
this.commands.set(key, next);
|
|
50
|
+
this.active.add(next);
|
|
51
|
+
void next.then(() => {
|
|
52
|
+
this.active.delete(next);
|
|
53
|
+
if (this.commands.get(key) === next)
|
|
54
|
+
this.commands.delete(key);
|
|
55
|
+
});
|
|
56
|
+
return { command: next, blocks, blocked: !!barrier, available: admitted };
|
|
57
|
+
}
|
|
58
|
+
// Later messages must not steer the generation being archived.
|
|
59
|
+
const available = barrier
|
|
60
|
+
? admitted.then(async (accepted) => {
|
|
61
|
+
await barrier;
|
|
62
|
+
return accepted;
|
|
63
|
+
})
|
|
64
|
+
: admitted;
|
|
65
|
+
return { blocked: !!barrier, available };
|
|
66
|
+
}
|
|
67
|
+
async handleCommand(key, name, msg, command, admitted, previous, barrier, stopping) {
|
|
68
|
+
const o = this.options;
|
|
69
|
+
try {
|
|
70
|
+
if (!(await admitted))
|
|
71
|
+
return;
|
|
72
|
+
await barrier;
|
|
73
|
+
if (o.stopped())
|
|
74
|
+
return;
|
|
75
|
+
let stopped = false;
|
|
76
|
+
if (command === 'stop' || command === 'restart') {
|
|
77
|
+
const processing = this.processing.get(key);
|
|
78
|
+
if (processing)
|
|
79
|
+
processing.stopped = true;
|
|
80
|
+
stopped = (await (stopping ?? o.feedback.stop(key))) || !!processing;
|
|
81
|
+
await previous;
|
|
82
|
+
}
|
|
83
|
+
await o.closing(key);
|
|
84
|
+
if (o.stopped())
|
|
85
|
+
return;
|
|
86
|
+
const channel = o.channel(name);
|
|
87
|
+
if (!channel)
|
|
88
|
+
return;
|
|
89
|
+
const session = command === 'status'
|
|
90
|
+
? (o.find(key) ?? (await o.admission.admit(key, channel, msg)))
|
|
91
|
+
: o.find(key);
|
|
92
|
+
await this.finish(command, key, channel, msg, stopped, session);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
await o.feedback.feedbackError(name, msg, error);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** Stop/Restart arrive after the old run's normal delivery and finish path has drained. */
|
|
99
|
+
async finish(command, key, channel, msg, stopped, session) {
|
|
100
|
+
const { directory, feedback, usage } = this.options;
|
|
101
|
+
const inputs = feedback.acknowledge(channel, msg);
|
|
102
|
+
let outcome = 'failed';
|
|
103
|
+
try {
|
|
104
|
+
await Promise.all(inputs.map((input) => input.ready));
|
|
105
|
+
let text = stopped ? '' : 'No run is currently active.';
|
|
106
|
+
if (command === 'restart') {
|
|
107
|
+
// Save before closing: a save failure must retain the old live session.
|
|
108
|
+
await session?.save();
|
|
109
|
+
await session?.close();
|
|
110
|
+
directory.observe(key, channel.name, msg);
|
|
111
|
+
await directory.restart(key);
|
|
112
|
+
text = 'Restarted with a fresh session';
|
|
113
|
+
}
|
|
114
|
+
else if (command === 'routines') {
|
|
115
|
+
text = this.options.routines(channel.name, msg.channelId);
|
|
116
|
+
}
|
|
117
|
+
else if (command === 'status' && session) {
|
|
118
|
+
text = usage.status(key, channel.name, msg.channelId, session);
|
|
119
|
+
}
|
|
120
|
+
if (text)
|
|
121
|
+
await channel.send({ ...msg, recipientId: msg.senderId, text });
|
|
122
|
+
await directory.forget(key, msg.replyToId ? [msg.replyToId] : []);
|
|
123
|
+
outcome = 'done';
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
await Promise.all(inputs.map((input) => input.finish(outcome)));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AASA,2FAA2F;AAC3F,SAAS,YAAY,CAAC,GAAoB;IACxC,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAA;IAC5B,IAAI,IAAI,KAAK,WAAW;QAAE,OAAO,UAAU,CAAA;IAC3C,IAAI,CAAC,GAAG,CAAC,KAAK;QAAE,OAAM;IACtB,IAAI,IAAI,KAAK,OAAO;QAAE,OAAO,MAAM,CAAA;IACnC,IAAI,IAAI,KAAK,UAAU;QAAE,OAAO,SAAS,CAAA;IACzC,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,QAAQ,C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AI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,SAAS,CAAC,CAAA;YAC3D,CAAC;iBAAM,IAAI,OAAO,KAAK,QAAQ,IAAI,OAAO,EAAE,CAAC;gBAC3C,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;YAChE,CAAC;YACD,IAAI,IAAI;gBAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,GAAG,EAAE,WAAW,EAAE,GAAG,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;YACzE,MAAM,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;YACjE,OAAO,GAAG,MAAM,CAAA;QAClB,CAAC;gBAAS,CAAC;YACT,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;QACjE,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ChannelTopic, IncomingMessage } from './types.ts';
|
|
3
|
+
declare const recordSchema: z.ZodObject<{
|
|
4
|
+
key: z.ZodString;
|
|
5
|
+
channel: z.ZodString;
|
|
6
|
+
legacyKey: z.ZodOptional<z.ZodString>;
|
|
7
|
+
storageKey: z.ZodOptional<z.ZodString>;
|
|
8
|
+
chatId: z.ZodString;
|
|
9
|
+
chatKind: z.ZodEnum<{
|
|
10
|
+
group: "group";
|
|
11
|
+
direct: "direct";
|
|
12
|
+
}>;
|
|
13
|
+
rootId: z.ZodOptional<z.ZodString>;
|
|
14
|
+
threadId: z.ZodOptional<z.ZodString>;
|
|
15
|
+
requester: z.ZodObject<{
|
|
16
|
+
id: z.ZodString;
|
|
17
|
+
name: z.ZodString;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
replyTarget: z.ZodOptional<z.ZodString>;
|
|
20
|
+
task: z.ZodString;
|
|
21
|
+
activeSessionId: z.ZodString;
|
|
22
|
+
previousSessionIds: z.ZodArray<z.ZodString>;
|
|
23
|
+
state: z.ZodEnum<{
|
|
24
|
+
running: "running";
|
|
25
|
+
waiting: "waiting";
|
|
26
|
+
done: "done";
|
|
27
|
+
stopped: "stopped";
|
|
28
|
+
}>;
|
|
29
|
+
waitingReason: z.ZodOptional<z.ZodString>;
|
|
30
|
+
passive: z.ZodOptional<z.ZodBoolean>;
|
|
31
|
+
handoff: z.ZodOptional<z.ZodObject<{
|
|
32
|
+
id: z.ZodString;
|
|
33
|
+
from: z.ZodString;
|
|
34
|
+
depth: z.ZodNumber;
|
|
35
|
+
}, z.core.$strip>>;
|
|
36
|
+
routine: z.ZodOptional<z.ZodObject<{
|
|
37
|
+
id: z.ZodString;
|
|
38
|
+
scheduledAt: z.ZodString;
|
|
39
|
+
creator: z.ZodOptional<z.ZodObject<{
|
|
40
|
+
id: z.ZodString;
|
|
41
|
+
name: z.ZodString;
|
|
42
|
+
}, z.core.$strip>>;
|
|
43
|
+
}, z.core.$strip>>;
|
|
44
|
+
pendingMessageIds: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
45
|
+
id: z.ZodString;
|
|
46
|
+
passive: z.ZodLiteral<true>;
|
|
47
|
+
}, z.core.$strip>]>>;
|
|
48
|
+
createdAt: z.ZodString;
|
|
49
|
+
updatedAt: z.ZodString;
|
|
50
|
+
}, z.core.$strip>;
|
|
51
|
+
export declare const channelIndexSchema: z.ZodObject<{
|
|
52
|
+
version: z.ZodLiteral<1>;
|
|
53
|
+
createdAt: z.ZodString;
|
|
54
|
+
records: z.ZodArray<z.ZodObject<{
|
|
55
|
+
key: z.ZodString;
|
|
56
|
+
channel: z.ZodString;
|
|
57
|
+
legacyKey: z.ZodOptional<z.ZodString>;
|
|
58
|
+
storageKey: z.ZodOptional<z.ZodString>;
|
|
59
|
+
chatId: z.ZodString;
|
|
60
|
+
chatKind: z.ZodEnum<{
|
|
61
|
+
group: "group";
|
|
62
|
+
direct: "direct";
|
|
63
|
+
}>;
|
|
64
|
+
rootId: z.ZodOptional<z.ZodString>;
|
|
65
|
+
threadId: z.ZodOptional<z.ZodString>;
|
|
66
|
+
requester: z.ZodObject<{
|
|
67
|
+
id: z.ZodString;
|
|
68
|
+
name: z.ZodString;
|
|
69
|
+
}, z.core.$strip>;
|
|
70
|
+
replyTarget: z.ZodOptional<z.ZodString>;
|
|
71
|
+
task: z.ZodString;
|
|
72
|
+
activeSessionId: z.ZodString;
|
|
73
|
+
previousSessionIds: z.ZodArray<z.ZodString>;
|
|
74
|
+
state: z.ZodEnum<{
|
|
75
|
+
running: "running";
|
|
76
|
+
waiting: "waiting";
|
|
77
|
+
done: "done";
|
|
78
|
+
stopped: "stopped";
|
|
79
|
+
}>;
|
|
80
|
+
waitingReason: z.ZodOptional<z.ZodString>;
|
|
81
|
+
passive: z.ZodOptional<z.ZodBoolean>;
|
|
82
|
+
handoff: z.ZodOptional<z.ZodObject<{
|
|
83
|
+
id: z.ZodString;
|
|
84
|
+
from: z.ZodString;
|
|
85
|
+
depth: z.ZodNumber;
|
|
86
|
+
}, z.core.$strip>>;
|
|
87
|
+
routine: z.ZodOptional<z.ZodObject<{
|
|
88
|
+
id: z.ZodString;
|
|
89
|
+
scheduledAt: z.ZodString;
|
|
90
|
+
creator: z.ZodOptional<z.ZodObject<{
|
|
91
|
+
id: z.ZodString;
|
|
92
|
+
name: z.ZodString;
|
|
93
|
+
}, z.core.$strip>>;
|
|
94
|
+
}, z.core.$strip>>;
|
|
95
|
+
pendingMessageIds: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
96
|
+
id: z.ZodString;
|
|
97
|
+
passive: z.ZodLiteral<true>;
|
|
98
|
+
}, z.core.$strip>]>>;
|
|
99
|
+
createdAt: z.ZodString;
|
|
100
|
+
updatedAt: z.ZodString;
|
|
101
|
+
}, z.core.$strip>>;
|
|
102
|
+
notes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
|
|
103
|
+
}, z.core.$strip>;
|
|
104
|
+
export type ChannelRecord = z.infer<typeof recordSchema>;
|
|
105
|
+
/** Hand-off notes exist only in groups and address the group session without a service message. */
|
|
106
|
+
export declare function isGroupInput(msg: IncomingMessage): boolean;
|
|
107
|
+
/** Passive metadata travels with the existing pending ID, never in a second ID registry. */
|
|
108
|
+
export declare function pendingMessageId(input: ChannelRecord['pendingMessageIds'][number]): string;
|
|
109
|
+
/** One directory for recovery and topic discovery. No input text is copied here except the task label. */
|
|
110
|
+
export declare class ChannelDirectory {
|
|
111
|
+
private records;
|
|
112
|
+
private notes;
|
|
113
|
+
private loaded?;
|
|
114
|
+
private writing;
|
|
115
|
+
private readonly path?;
|
|
116
|
+
private createdAt;
|
|
117
|
+
constructor(dataDir?: string);
|
|
118
|
+
load(): Promise<void>;
|
|
119
|
+
private read;
|
|
120
|
+
get(key: string): ChannelRecord | undefined;
|
|
121
|
+
storageKey(channel: string, chatId: string): string | undefined;
|
|
122
|
+
sessionId(key: string): string;
|
|
123
|
+
keyForSession(id: string): string;
|
|
124
|
+
restart(key: string): Promise<void>;
|
|
125
|
+
entries(channel: string): ChannelRecord[];
|
|
126
|
+
get coverage(): string;
|
|
127
|
+
observe(key: string, channel: string, msg: IncomingMessage, task?: string): ChannelRecord;
|
|
128
|
+
admit(key: string, channel: string, msg: IncomingMessage): Promise<void>;
|
|
129
|
+
begin(key: string, msg: IncomingMessage): Promise<void>;
|
|
130
|
+
forget(key: string, ids: string[]): Promise<void>;
|
|
131
|
+
waitForInput(key: string, reason: string): Promise<void>;
|
|
132
|
+
finish(key: string, state: ChannelRecord['state'], answered?: boolean): Promise<void>;
|
|
133
|
+
list(channel: string, chatId: string, state: (id: string) => ChannelTopic['state']): ChannelTopic[];
|
|
134
|
+
/** Status lines for a group session's next run, oldest first. */
|
|
135
|
+
pendingNotes(key: string): readonly string[];
|
|
136
|
+
addNote(key: string, line: string): Promise<void>;
|
|
137
|
+
/** Drops these delivered notes once a session has saved them; newer ones stay. */
|
|
138
|
+
dropNotes(key: string, delivered: readonly string[]): Promise<void>;
|
|
139
|
+
flush(): Promise<void>;
|
|
140
|
+
private save;
|
|
141
|
+
private write;
|
|
142
|
+
}
|
|
143
|
+
export {};
|
|
144
|
+
//# sourceMappingURL=directory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory.d.ts","sourceRoot":"","sources":["../src/directory.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE/D,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4Cf,CAAA;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAM7B,CAAA;AACF,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAA;AAExD,mGAAmG;AACnG,wBAAgB,YAAY,CAAC,GAAG,EAAE,eAAe,GAAG,OAAO,CAE1D;AAKD,4FAA4F;AAC5F,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAC,MAAM,CAAC,GAChD,MAAM,CAER;AAED,0GAA0G;AAC1G,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,OAAO,CAAmC;IAClD,OAAO,CAAC,KAAK,CAA8B;IAC3C,OAAO,CAAC,MAAM,CAA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,IAAI,CAAC;IAShB,IAAI,CACF,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,YAAY,CAAC,OAAO,CAAC,GAC3C,YAAY,EAAE;IAkBjB,iEAAiE;IACjE,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE;IAI5C,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjD,kFAAkF;IAClF,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAWnE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,OAAO,CAAC,IAAI;IAKZ,OAAO,CAAC,KAAK;CAuBd"}
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { writeAtomicJson } from "./atomic-json.js";
|
|
6
|
+
const recordSchema = z
|
|
7
|
+
.object({
|
|
8
|
+
key: z.string(),
|
|
9
|
+
channel: z.string(),
|
|
10
|
+
legacyKey: z.string().optional(),
|
|
11
|
+
storageKey: z
|
|
12
|
+
.string()
|
|
13
|
+
.regex(/^[A-Za-z0-9_.-]+$/)
|
|
14
|
+
.refine((key) => key !== '.' && key !== '..')
|
|
15
|
+
.optional(),
|
|
16
|
+
chatId: z.string(),
|
|
17
|
+
chatKind: z.enum(['group', 'direct']),
|
|
18
|
+
rootId: z.string().optional(),
|
|
19
|
+
threadId: z.string().optional(),
|
|
20
|
+
requester: z.object({ id: z.string(), name: z.string() }),
|
|
21
|
+
replyTarget: z.string().optional(),
|
|
22
|
+
task: z.string(),
|
|
23
|
+
activeSessionId: z.string(),
|
|
24
|
+
previousSessionIds: z.array(z.string()),
|
|
25
|
+
state: z.enum(['running', 'waiting', 'done', 'stopped']),
|
|
26
|
+
waitingReason: z.string().optional(),
|
|
27
|
+
passive: z.boolean().optional(),
|
|
28
|
+
handoff: z
|
|
29
|
+
.object({ id: z.string(), from: z.string(), depth: z.number() })
|
|
30
|
+
.optional(),
|
|
31
|
+
routine: z
|
|
32
|
+
.object({
|
|
33
|
+
id: z.string(),
|
|
34
|
+
scheduledAt: z.string(),
|
|
35
|
+
creator: z.object({ id: z.string(), name: z.string() }).optional(),
|
|
36
|
+
})
|
|
37
|
+
.optional(),
|
|
38
|
+
pendingMessageIds: z.array(z.union([
|
|
39
|
+
z.string(),
|
|
40
|
+
z.object({ id: z.string(), passive: z.literal(true) }),
|
|
41
|
+
])),
|
|
42
|
+
createdAt: z.string(),
|
|
43
|
+
updatedAt: z.string(),
|
|
44
|
+
})
|
|
45
|
+
.refine((record) => !!record.rootId === !!record.threadId, 'Incomplete topic address');
|
|
46
|
+
export const channelIndexSchema = z.object({
|
|
47
|
+
version: z.literal(1),
|
|
48
|
+
createdAt: z.string(),
|
|
49
|
+
records: z.array(recordSchema),
|
|
50
|
+
/** Status lines waiting for a group session's next run, by group key. */
|
|
51
|
+
notes: z.record(z.string(), z.array(z.string())).optional(),
|
|
52
|
+
});
|
|
53
|
+
/** Hand-off notes exist only in groups and address the group session without a service message. */
|
|
54
|
+
export function isGroupInput(msg) {
|
|
55
|
+
return !!(msg.topic || msg.replyToId || msg.handoff);
|
|
56
|
+
}
|
|
57
|
+
const MAX_NOTES = 20;
|
|
58
|
+
const MAX_NOTE_CHARS = 300;
|
|
59
|
+
/** Passive metadata travels with the existing pending ID, never in a second ID registry. */
|
|
60
|
+
export function pendingMessageId(input) {
|
|
61
|
+
return typeof input === 'string' ? input : input.id;
|
|
62
|
+
}
|
|
63
|
+
/** One directory for recovery and topic discovery. No input text is copied here except the task label. */
|
|
64
|
+
export class ChannelDirectory {
|
|
65
|
+
records = new Map();
|
|
66
|
+
notes = new Map();
|
|
67
|
+
loaded;
|
|
68
|
+
writing = Promise.resolve();
|
|
69
|
+
path;
|
|
70
|
+
createdAt = new Date().toISOString();
|
|
71
|
+
constructor(dataDir) {
|
|
72
|
+
this.path = dataDir ? join(dataDir, 'channels', 'index.json') : undefined;
|
|
73
|
+
}
|
|
74
|
+
load() {
|
|
75
|
+
this.loaded ??= this.read();
|
|
76
|
+
return this.loaded;
|
|
77
|
+
}
|
|
78
|
+
async read() {
|
|
79
|
+
if (!this.path)
|
|
80
|
+
return;
|
|
81
|
+
const marker = join(this.path, '..', 'migration.json');
|
|
82
|
+
if (existsSync(marker)) {
|
|
83
|
+
const migration = JSON.parse(await readFile(marker, 'utf8'));
|
|
84
|
+
if (migration.version !== 1 || migration.status !== 'complete')
|
|
85
|
+
throw new Error('Channel migration is incomplete; rerun the migration utility before starting transports');
|
|
86
|
+
}
|
|
87
|
+
let text;
|
|
88
|
+
try {
|
|
89
|
+
text = await readFile(this.path, 'utf8');
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
if (error.code === 'ENOENT')
|
|
93
|
+
return;
|
|
94
|
+
throw new Error(`Cannot read channel directory ${this.path}`, {
|
|
95
|
+
cause: error,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const data = channelIndexSchema.parse(JSON.parse(text));
|
|
100
|
+
if (new Set(data.records.map((r) => r.key)).size !== data.records.length)
|
|
101
|
+
throw new Error('Duplicate channel key');
|
|
102
|
+
const keys = new Set(data.records.map((record) => record.key));
|
|
103
|
+
const legacy = data.records.flatMap((record) => record.legacyKey ? [record.legacyKey] : []);
|
|
104
|
+
if (new Set(legacy).size !== legacy.length ||
|
|
105
|
+
legacy.some((key) => keys.has(key)))
|
|
106
|
+
throw new Error('Conflicting legacy channel key');
|
|
107
|
+
const stores = new Map();
|
|
108
|
+
for (const record of data.records) {
|
|
109
|
+
const chat = JSON.stringify([record.channel, record.chatId]);
|
|
110
|
+
if (stores.has(chat) && stores.get(chat) !== record.storageKey)
|
|
111
|
+
throw new Error('Conflicting channel storage keys');
|
|
112
|
+
stores.set(chat, record.storageKey);
|
|
113
|
+
}
|
|
114
|
+
this.createdAt = data.createdAt;
|
|
115
|
+
this.records = new Map(data.records.map((record) => [record.key, record]));
|
|
116
|
+
this.notes = new Map(Object.entries(data.notes ?? {}));
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
throw new Error(`Invalid channel directory ${this.path}: ${String(error)}`, { cause: error });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
get(key) {
|
|
123
|
+
return (this.records.get(key) ??
|
|
124
|
+
[...this.records.values()].find((record) => record.legacyKey === key));
|
|
125
|
+
}
|
|
126
|
+
storageKey(channel, chatId) {
|
|
127
|
+
return this.entries(channel).find((record) => record.chatId === chatId)
|
|
128
|
+
?.storageKey;
|
|
129
|
+
}
|
|
130
|
+
sessionId(key) {
|
|
131
|
+
return this.get(key)?.activeSessionId ?? key;
|
|
132
|
+
}
|
|
133
|
+
keyForSession(id) {
|
|
134
|
+
return ([...this.records.values()].find((record) => record.activeSessionId === id)
|
|
135
|
+
?.key ?? id);
|
|
136
|
+
}
|
|
137
|
+
async restart(key) {
|
|
138
|
+
const record = this.records.get(key);
|
|
139
|
+
if (!record)
|
|
140
|
+
throw new Error(`Unknown channel session ${key}`);
|
|
141
|
+
const next = {
|
|
142
|
+
...record,
|
|
143
|
+
activeSessionId: `channel-${crypto.randomUUID()}`,
|
|
144
|
+
previousSessionIds: [
|
|
145
|
+
...record.previousSessionIds,
|
|
146
|
+
record.activeSessionId,
|
|
147
|
+
],
|
|
148
|
+
state: 'done',
|
|
149
|
+
waitingReason: undefined,
|
|
150
|
+
};
|
|
151
|
+
await this.save(next, true);
|
|
152
|
+
}
|
|
153
|
+
entries(channel) {
|
|
154
|
+
return [...this.records.values()].filter((record) => record.channel === channel);
|
|
155
|
+
}
|
|
156
|
+
get coverage() {
|
|
157
|
+
return `Topics recorded since M2 directory creation at ${this.createdAt}; earlier topics may exist until they receive a new message. An empty list does not mean there are no tasks.`;
|
|
158
|
+
}
|
|
159
|
+
observe(key, channel, msg, task = msg.text) {
|
|
160
|
+
let record = this.records.get(key);
|
|
161
|
+
if (!record) {
|
|
162
|
+
const now = new Date().toISOString();
|
|
163
|
+
record = {
|
|
164
|
+
key,
|
|
165
|
+
channel,
|
|
166
|
+
chatId: msg.channelId,
|
|
167
|
+
chatKind: isGroupInput(msg) ? 'group' : 'direct',
|
|
168
|
+
rootId: msg.topic?.rootId,
|
|
169
|
+
threadId: msg.topic?.threadId,
|
|
170
|
+
requester: { id: msg.senderId, name: msg.senderName },
|
|
171
|
+
replyTarget: msg.replyToId,
|
|
172
|
+
task: task.slice(0, 120),
|
|
173
|
+
activeSessionId: key,
|
|
174
|
+
storageKey: this.storageKey(channel, msg.channelId),
|
|
175
|
+
previousSessionIds: [],
|
|
176
|
+
state: 'done',
|
|
177
|
+
pendingMessageIds: [],
|
|
178
|
+
createdAt: now,
|
|
179
|
+
updatedAt: now,
|
|
180
|
+
};
|
|
181
|
+
this.records.set(key, record);
|
|
182
|
+
}
|
|
183
|
+
return record;
|
|
184
|
+
}
|
|
185
|
+
async admit(key, channel, msg) {
|
|
186
|
+
const record = this.observe(key, channel, msg);
|
|
187
|
+
// A note from another session never answers a person's pending decision.
|
|
188
|
+
if (!msg.handoff) {
|
|
189
|
+
record.waitingReason = undefined;
|
|
190
|
+
if (record.state === 'waiting')
|
|
191
|
+
record.state = 'done';
|
|
192
|
+
}
|
|
193
|
+
// A note has no service message of its own: its reply target is the topic root.
|
|
194
|
+
if (msg.replyToId &&
|
|
195
|
+
!msg.routine &&
|
|
196
|
+
!msg.handoff &&
|
|
197
|
+
!record.pendingMessageIds.some((input) => pendingMessageId(input) === msg.replyToId))
|
|
198
|
+
record.pendingMessageIds.push(msg.passive ? { id: msg.replyToId, passive: true } : msg.replyToId);
|
|
199
|
+
await this.save(record);
|
|
200
|
+
}
|
|
201
|
+
async begin(key, msg) {
|
|
202
|
+
const record = this.records.get(key);
|
|
203
|
+
if (!record)
|
|
204
|
+
return;
|
|
205
|
+
record.state = 'running';
|
|
206
|
+
record.passive = msg.passive;
|
|
207
|
+
record.handoff = msg.handoff;
|
|
208
|
+
record.routine = msg.routine
|
|
209
|
+
? { ...msg.routine, creator: { id: msg.senderId, name: msg.senderName } }
|
|
210
|
+
: undefined;
|
|
211
|
+
if (!record.rootId || record.requester.id === msg.senderId)
|
|
212
|
+
record.requester = { id: msg.senderId, name: msg.senderName };
|
|
213
|
+
record.replyTarget = msg.replyToId;
|
|
214
|
+
await this.save(record);
|
|
215
|
+
}
|
|
216
|
+
async forget(key, ids) {
|
|
217
|
+
const record = this.records.get(key);
|
|
218
|
+
if (!record?.pendingMessageIds.some((input) => ids.includes(pendingMessageId(input))))
|
|
219
|
+
return;
|
|
220
|
+
record.pendingMessageIds = record.pendingMessageIds.filter((input) => !ids.includes(pendingMessageId(input)));
|
|
221
|
+
await this.save(record);
|
|
222
|
+
}
|
|
223
|
+
async waitForInput(key, reason) {
|
|
224
|
+
const record = this.records.get(key);
|
|
225
|
+
if (!record?.rootId)
|
|
226
|
+
throw new Error('Waiting requires a topic');
|
|
227
|
+
record.waitingReason = reason;
|
|
228
|
+
await this.save(record);
|
|
229
|
+
}
|
|
230
|
+
async finish(key, state, answered = false) {
|
|
231
|
+
const record = this.records.get(key);
|
|
232
|
+
if (!record)
|
|
233
|
+
return;
|
|
234
|
+
record.state =
|
|
235
|
+
state === 'done' && answered && record.waitingReason ? 'waiting' : state;
|
|
236
|
+
if (record.state !== 'waiting')
|
|
237
|
+
record.waitingReason = undefined;
|
|
238
|
+
await this.save(record);
|
|
239
|
+
}
|
|
240
|
+
list(channel, chatId, state) {
|
|
241
|
+
return this.entries(channel).flatMap((record) => record.chatId === chatId && record.rootId && record.threadId
|
|
242
|
+
? [
|
|
243
|
+
{
|
|
244
|
+
rootId: record.rootId,
|
|
245
|
+
threadId: record.threadId,
|
|
246
|
+
task: record.task,
|
|
247
|
+
state: state(record.key),
|
|
248
|
+
requester: record.requester,
|
|
249
|
+
updatedAt: record.updatedAt,
|
|
250
|
+
waitingReason: record.waitingReason,
|
|
251
|
+
},
|
|
252
|
+
]
|
|
253
|
+
: []);
|
|
254
|
+
}
|
|
255
|
+
/** Status lines for a group session's next run, oldest first. */
|
|
256
|
+
pendingNotes(key) {
|
|
257
|
+
return this.notes.get(key) ?? [];
|
|
258
|
+
}
|
|
259
|
+
addNote(key, line) {
|
|
260
|
+
const note = line.length > MAX_NOTE_CHARS ? `${line.slice(0, MAX_NOTE_CHARS)}…` : line;
|
|
261
|
+
this.notes.set(key, [...this.pendingNotes(key), note].slice(-MAX_NOTES));
|
|
262
|
+
return this.write();
|
|
263
|
+
}
|
|
264
|
+
/** Drops these delivered notes once a session has saved them; newer ones stay. */
|
|
265
|
+
dropNotes(key, delivered) {
|
|
266
|
+
const rest = [...this.pendingNotes(key)];
|
|
267
|
+
for (const note of delivered) {
|
|
268
|
+
const index = rest.indexOf(note);
|
|
269
|
+
if (index >= 0)
|
|
270
|
+
rest.splice(index, 1);
|
|
271
|
+
}
|
|
272
|
+
if (rest.length)
|
|
273
|
+
this.notes.set(key, rest);
|
|
274
|
+
else
|
|
275
|
+
this.notes.delete(key);
|
|
276
|
+
return this.write();
|
|
277
|
+
}
|
|
278
|
+
flush() {
|
|
279
|
+
return this.writing;
|
|
280
|
+
}
|
|
281
|
+
save(record, replace = false) {
|
|
282
|
+
record.updatedAt = new Date().toISOString();
|
|
283
|
+
return this.write(replace ? record : undefined);
|
|
284
|
+
}
|
|
285
|
+
write(replacement) {
|
|
286
|
+
const path = this.path;
|
|
287
|
+
if (!path) {
|
|
288
|
+
if (replacement)
|
|
289
|
+
this.records.set(replacement.key, replacement);
|
|
290
|
+
return Promise.resolve();
|
|
291
|
+
}
|
|
292
|
+
const write = this.writing
|
|
293
|
+
.catch(() => { })
|
|
294
|
+
.then(async () => {
|
|
295
|
+
// Later saves see only generations whose index write succeeded.
|
|
296
|
+
await writeAtomicJson(path, {
|
|
297
|
+
version: 1,
|
|
298
|
+
createdAt: this.createdAt,
|
|
299
|
+
records: [...this.records.values()].map((current) => current.key === replacement?.key ? replacement : current),
|
|
300
|
+
...(this.notes.size ? { notes: Object.fromEntries(this.notes) } : {}),
|
|
301
|
+
});
|
|
302
|
+
if (replacement)
|
|
303
|
+
this.records.set(replacement.key, replacement);
|
|
304
|
+
});
|
|
305
|
+
this.writing = write;
|
|
306
|
+
return write;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
//# sourceMappingURL=directory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory.js","sourceRoot":"","sources":["../src/directory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAGlD,MAAM,YAAY,GAAG,CAAC;KACnB,MAAM,CAAC;IACN,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,UAAU,EAAE,CAAC;SACV,MAAM,EAAE;SACR,KAAK,CAAC,mBAAmB,CAAC;SAC1B,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,IAAI,CAAC;SAC5C,QAAQ,EAAE;IACb,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACrC,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
+
import type { ChannelEvent } from './types.ts';
|
|
3
|
+
/** Optional ingress owned by the channel assembly; no daemon, persisted cache or provider access. */
|
|
4
|
+
export declare class EventReceiver {
|
|
5
|
+
private publish;
|
|
6
|
+
private logger;
|
|
7
|
+
private readonly options;
|
|
8
|
+
private server?;
|
|
9
|
+
private starting?;
|
|
10
|
+
private readonly active;
|
|
11
|
+
private readonly seen;
|
|
12
|
+
private accepting;
|
|
13
|
+
constructor(config: unknown, publish: (event: ChannelEvent) => Promise<void>, logger: VelaLogger);
|
|
14
|
+
start(): Promise<void>;
|
|
15
|
+
private listen;
|
|
16
|
+
stop(): Promise<void>;
|
|
17
|
+
private handle;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=event-receiver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-receiver.d.ts","sourceRoot":"","sources":["../src/event-receiver.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AAKnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAmE9C,qGAAqG;AACrG,qBAAa,aAAa;IAUtB,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,MAAM;IAVhB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA+B;IACvD,OAAO,CAAC,MAAM,CAAC,CAAiC;IAChD,OAAO,CAAC,QAAQ,CAAC,CAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2B;IAClD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAoB;IACzC,OAAO,CAAC,SAAS,CAAQ;gBAGvB,MAAM,EAAE,OAAO,EACP,OAAO,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,EAC/C,MAAM,EAAE,UAAU;IAU5B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAKR,MAAM;IAwBd,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;YAeb,MAAM;CAiFrB"}
|