@rfnry/thread 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +5 -2
- package/dist/client.d.ts +136 -0
- package/dist/client.js +592 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +23 -0
- package/dist/errors.js +38 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/outbox.d.ts +15 -0
- package/dist/outbox.js +38 -0
- package/dist/outbox.js.map +1 -0
- package/dist/protocol.d.ts +41 -0
- package/dist/protocol.js +24 -0
- package/dist/protocol.js.map +1 -0
- package/dist/resolve.d.ts +2 -0
- package/dist/resolve.js +20 -0
- package/dist/resolve.js.map +1 -0
- package/dist/timing.d.ts +8 -0
- package/dist/timing.js +9 -0
- package/dist/timing.js.map +1 -0
- package/dist/types.d.ts +159 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +27 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 rfnry (github.com/rfnry)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# rfnry-thread
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Conversational text interfaces for humans and machines.
|
|
4
|
+
|
|
5
|
+
[`docs/thread.md`](https://github.com/rfnry/thread/blob/main/docs/thread.md).
|
|
6
|
+
[`docs/api.md`](https://github.com/rfnry/thread/blob/main/docs/api.md).
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { ThreadException } from './errors.js';
|
|
2
|
+
import type { Content, Custom, Edit, Event, Identity, Item, Joined, Member, Message, Part, Read, Retract, Status, Step, Thread } from './types.js';
|
|
3
|
+
type Payload = Record<string, unknown>;
|
|
4
|
+
export type Protocols = string | string[];
|
|
5
|
+
export type ConnectOptions = {
|
|
6
|
+
url: string;
|
|
7
|
+
protocols?: Protocols | (() => Promise<Protocols>);
|
|
8
|
+
};
|
|
9
|
+
export type Listener = (item: Item) => void;
|
|
10
|
+
export type StreamOptions = {
|
|
11
|
+
inReplyTo?: string;
|
|
12
|
+
triggeredBy?: Identity;
|
|
13
|
+
metadata?: Record<string, unknown>;
|
|
14
|
+
};
|
|
15
|
+
export type SendOptions = StreamOptions & {
|
|
16
|
+
clientId?: string;
|
|
17
|
+
};
|
|
18
|
+
export type WriteOptions = {
|
|
19
|
+
clientId?: string;
|
|
20
|
+
};
|
|
21
|
+
export type StepOptions = Omit<SendOptions, 'metadata'> & {
|
|
22
|
+
name: string;
|
|
23
|
+
input?: Record<string, unknown>;
|
|
24
|
+
output?: Part[];
|
|
25
|
+
isError?: boolean;
|
|
26
|
+
durationMs?: number;
|
|
27
|
+
};
|
|
28
|
+
type Wire = {
|
|
29
|
+
request(method: string, payload: Payload): Promise<Payload>;
|
|
30
|
+
notify(method: string, payload: Payload): void;
|
|
31
|
+
message(threadId: string, content: Content, options: StreamOptions, clientId: string): Promise<Message>;
|
|
32
|
+
};
|
|
33
|
+
export declare class Stream {
|
|
34
|
+
private readonly wire;
|
|
35
|
+
private readonly threadId;
|
|
36
|
+
private readonly options;
|
|
37
|
+
readonly id: string;
|
|
38
|
+
text: string;
|
|
39
|
+
private index;
|
|
40
|
+
private ended;
|
|
41
|
+
private readonly started;
|
|
42
|
+
constructor(wire: Wire, threadId: string, options: StreamOptions);
|
|
43
|
+
write(text: string): void;
|
|
44
|
+
finish(content?: Content): Promise<Message>;
|
|
45
|
+
abort(): Promise<void>;
|
|
46
|
+
private end;
|
|
47
|
+
}
|
|
48
|
+
export declare class Client {
|
|
49
|
+
private readonly options;
|
|
50
|
+
identity: Identity;
|
|
51
|
+
scope: string;
|
|
52
|
+
readonly closed: Promise<ThreadException | null>;
|
|
53
|
+
private settle;
|
|
54
|
+
private socket;
|
|
55
|
+
private readonly pending;
|
|
56
|
+
private nextId;
|
|
57
|
+
private readonly listeners;
|
|
58
|
+
private readonly cursors;
|
|
59
|
+
private rewinds;
|
|
60
|
+
private following;
|
|
61
|
+
private readonly held;
|
|
62
|
+
private readonly left;
|
|
63
|
+
private leaving;
|
|
64
|
+
private stopped;
|
|
65
|
+
private current;
|
|
66
|
+
private failure;
|
|
67
|
+
private waiting;
|
|
68
|
+
private readonly outbox;
|
|
69
|
+
private readonly wire;
|
|
70
|
+
constructor(options: ConnectOptions);
|
|
71
|
+
private establish;
|
|
72
|
+
private offered;
|
|
73
|
+
private receive;
|
|
74
|
+
private emit;
|
|
75
|
+
private change;
|
|
76
|
+
private lost;
|
|
77
|
+
private reconnect;
|
|
78
|
+
private rejoin;
|
|
79
|
+
private fail;
|
|
80
|
+
private request;
|
|
81
|
+
private notify;
|
|
82
|
+
private event;
|
|
83
|
+
private message;
|
|
84
|
+
private joinFrom;
|
|
85
|
+
createThread(options?: {
|
|
86
|
+
threadId?: string;
|
|
87
|
+
metadata?: Record<string, unknown>;
|
|
88
|
+
}): Promise<Thread>;
|
|
89
|
+
getThread(threadId: string): Promise<Thread>;
|
|
90
|
+
listThreads(options?: {
|
|
91
|
+
before?: string;
|
|
92
|
+
limit?: number;
|
|
93
|
+
order?: 'created' | 'activity';
|
|
94
|
+
preview?: boolean;
|
|
95
|
+
}): Promise<Thread[]>;
|
|
96
|
+
updateThread(threadId: string, metadata: Record<string, unknown>): Promise<Thread>;
|
|
97
|
+
deleteThread(threadId: string): Promise<void>;
|
|
98
|
+
join(threadId: string, options?: {
|
|
99
|
+
since?: number;
|
|
100
|
+
resume?: boolean;
|
|
101
|
+
}): Promise<Joined>;
|
|
102
|
+
leave(threadId: string): Promise<void>;
|
|
103
|
+
follow(options?: {
|
|
104
|
+
resume?: boolean;
|
|
105
|
+
}): Promise<Joined[]>;
|
|
106
|
+
private followFrom;
|
|
107
|
+
mark(threadId: string, seq: number): Promise<number>;
|
|
108
|
+
marked(threadId: string): Promise<number | null>;
|
|
109
|
+
history(threadId: string, options?: {
|
|
110
|
+
before?: number;
|
|
111
|
+
after?: number;
|
|
112
|
+
limit?: number;
|
|
113
|
+
kinds?: string[];
|
|
114
|
+
}): Promise<Event[]>;
|
|
115
|
+
present(threadId: string): Promise<Identity[]>;
|
|
116
|
+
addMember(threadId: string, identity: Identity): Promise<Member>;
|
|
117
|
+
removeMember(threadId: string, identity: Identity): Promise<void>;
|
|
118
|
+
listMembers(threadId: string): Promise<Member[]>;
|
|
119
|
+
send(threadId: string, content: Content, options?: SendOptions): Promise<Message>;
|
|
120
|
+
stream(threadId: string, options?: StreamOptions): Stream;
|
|
121
|
+
step(threadId: string, options: StepOptions): Promise<Step>;
|
|
122
|
+
edit(threadId: string, target: string, content: Content, options?: WriteOptions): Promise<Edit>;
|
|
123
|
+
retract(threadId: string, target: string, options?: WriteOptions): Promise<Retract>;
|
|
124
|
+
read(threadId: string, upToSeq: number): Promise<Read>;
|
|
125
|
+
custom(threadId: string, name: string, payload: Record<string, unknown>, options?: WriteOptions): Promise<Custom>;
|
|
126
|
+
working(threadId: string, label?: string): Promise<void>;
|
|
127
|
+
idle(threadId: string): Promise<void>;
|
|
128
|
+
cancel(threadId: string, to: Identity): Promise<void>;
|
|
129
|
+
get status(): Status;
|
|
130
|
+
subscribe(listener: Listener, options?: {
|
|
131
|
+
includeOwn?: boolean;
|
|
132
|
+
}): () => void;
|
|
133
|
+
close(): Promise<void>;
|
|
134
|
+
}
|
|
135
|
+
export declare function connect(options: ConnectOptions): Promise<Client>;
|
|
136
|
+
export {};
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,592 @@
|
|
|
1
|
+
import { ConfigurationError, ForbiddenError, InputError, raised, ThreadException, TransportError, } from './errors.js';
|
|
2
|
+
import { Outbox } from './outbox.js';
|
|
3
|
+
import { CLOSE_REFUSED, decode, encode, HELLO, PROTOCOL } from './protocol.js';
|
|
4
|
+
import { timing } from './timing.js';
|
|
5
|
+
const parts = (content) => typeof content === 'string' ? [{ type: 'text', text: content }] : content;
|
|
6
|
+
const newId = () => crypto.randomUUID().replaceAll('-', '');
|
|
7
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
8
|
+
function open(url, protocols) {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
let socket;
|
|
11
|
+
try {
|
|
12
|
+
socket = new WebSocket(url, protocols);
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
reject(new TransportError(`client: could not connect: ${String(error)}`));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
socket.onopen = () => resolve(socket);
|
|
19
|
+
socket.onerror = () => reject(new TransportError(`client: could not connect to ${url}`));
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function handshake(socket) {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
const timer = setTimeout(() => reject(new TransportError('client: the hello was not answered')), timing.handshakeMs);
|
|
25
|
+
socket.onmessage = (message) => {
|
|
26
|
+
clearTimeout(timer);
|
|
27
|
+
let frame;
|
|
28
|
+
try {
|
|
29
|
+
frame = decode(String(message.data));
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
reject(error);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (frame.type === 'error' && frame.id === HELLO)
|
|
36
|
+
reject(raised(frame.error.code, frame.error.message));
|
|
37
|
+
else if (frame.type === 'response' && frame.id === HELLO)
|
|
38
|
+
resolve(frame.payload);
|
|
39
|
+
else
|
|
40
|
+
reject(new TransportError('client: the server did not answer the hello'));
|
|
41
|
+
};
|
|
42
|
+
socket.onclose = (event) => {
|
|
43
|
+
clearTimeout(timer);
|
|
44
|
+
const reason = event.reason ? `: ${event.reason}` : '';
|
|
45
|
+
reject(event.code === CLOSE_REFUSED
|
|
46
|
+
? new ForbiddenError(`client: the server refused the connection with code ${CLOSE_REFUSED}${reason}`)
|
|
47
|
+
: new TransportError('client: the hello was not answered'));
|
|
48
|
+
};
|
|
49
|
+
socket.send(encode({ type: 'hello', protocol: PROTOCOL }));
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
export class Stream {
|
|
53
|
+
wire;
|
|
54
|
+
threadId;
|
|
55
|
+
options;
|
|
56
|
+
id = newId();
|
|
57
|
+
text = '';
|
|
58
|
+
index = 0;
|
|
59
|
+
ended = false;
|
|
60
|
+
started;
|
|
61
|
+
constructor(wire, threadId, options) {
|
|
62
|
+
this.wire = wire;
|
|
63
|
+
this.threadId = threadId;
|
|
64
|
+
this.options = options;
|
|
65
|
+
this.started = wire.request('signal.send', {
|
|
66
|
+
thread_id: threadId,
|
|
67
|
+
kind: 'stream.start',
|
|
68
|
+
stream_id: this.id,
|
|
69
|
+
in_reply_to: options.inReplyTo ?? null,
|
|
70
|
+
});
|
|
71
|
+
this.started.catch(() => undefined);
|
|
72
|
+
}
|
|
73
|
+
write(text) {
|
|
74
|
+
this.text += text;
|
|
75
|
+
const index = this.index++;
|
|
76
|
+
void this.started.then(() => this.wire.notify('signal.send', {
|
|
77
|
+
thread_id: this.threadId,
|
|
78
|
+
kind: 'stream.delta',
|
|
79
|
+
stream_id: this.id,
|
|
80
|
+
index,
|
|
81
|
+
text,
|
|
82
|
+
}), () => undefined);
|
|
83
|
+
}
|
|
84
|
+
async finish(content) {
|
|
85
|
+
if (this.ended)
|
|
86
|
+
throw new InputError(`client: stream '${this.id}' has already ended`);
|
|
87
|
+
this.ended = true;
|
|
88
|
+
await this.started;
|
|
89
|
+
try {
|
|
90
|
+
return await this.wire.message(this.threadId, content ?? this.text, this.options, this.id);
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
await this.end();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async abort() {
|
|
97
|
+
if (this.ended)
|
|
98
|
+
return;
|
|
99
|
+
this.ended = true;
|
|
100
|
+
await this.started.catch(() => undefined);
|
|
101
|
+
await this.end();
|
|
102
|
+
}
|
|
103
|
+
async end() {
|
|
104
|
+
await this.wire
|
|
105
|
+
.request('signal.send', { thread_id: this.threadId, kind: 'stream.end', stream_id: this.id })
|
|
106
|
+
.catch(() => undefined);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
let establish;
|
|
110
|
+
export class Client {
|
|
111
|
+
options;
|
|
112
|
+
static {
|
|
113
|
+
establish = (client) => client.establish();
|
|
114
|
+
}
|
|
115
|
+
identity;
|
|
116
|
+
scope;
|
|
117
|
+
closed;
|
|
118
|
+
settle;
|
|
119
|
+
socket = null;
|
|
120
|
+
pending = new Map();
|
|
121
|
+
nextId = 1;
|
|
122
|
+
listeners = new Map();
|
|
123
|
+
cursors = new Map();
|
|
124
|
+
rewinds = [];
|
|
125
|
+
following = false;
|
|
126
|
+
held = new Set();
|
|
127
|
+
left = new Set();
|
|
128
|
+
leaving = new Set();
|
|
129
|
+
stopped = false;
|
|
130
|
+
current = 'open';
|
|
131
|
+
failure = null;
|
|
132
|
+
waiting = [];
|
|
133
|
+
outbox;
|
|
134
|
+
wire;
|
|
135
|
+
constructor(options) {
|
|
136
|
+
this.options = options;
|
|
137
|
+
this.closed = new Promise((resolve) => {
|
|
138
|
+
this.settle = resolve;
|
|
139
|
+
});
|
|
140
|
+
this.outbox = new Outbox((payload) => this.request('event.send', payload), {
|
|
141
|
+
isConnected: () => this.socket !== null,
|
|
142
|
+
isClosed: () => this.stopped,
|
|
143
|
+
waitConnected: (ms) => new Promise((resolve) => {
|
|
144
|
+
const timer = setTimeout(resolve, ms);
|
|
145
|
+
this.waiting.push(() => {
|
|
146
|
+
clearTimeout(timer);
|
|
147
|
+
resolve();
|
|
148
|
+
});
|
|
149
|
+
}),
|
|
150
|
+
});
|
|
151
|
+
this.wire = {
|
|
152
|
+
request: (method, payload) => this.request(method, payload),
|
|
153
|
+
notify: (method, payload) => this.notify(method, payload),
|
|
154
|
+
message: (threadId, content, options, clientId) => this.message(threadId, content, options, clientId),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
async establish() {
|
|
158
|
+
const socket = await open(this.options.url, await this.offered());
|
|
159
|
+
let reply;
|
|
160
|
+
try {
|
|
161
|
+
reply = await handshake(socket);
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
socket.close();
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
167
|
+
if (this.stopped) {
|
|
168
|
+
socket.close(1000, 'client: closed');
|
|
169
|
+
throw new TransportError('client: the client is closed');
|
|
170
|
+
}
|
|
171
|
+
this.identity = reply.identity;
|
|
172
|
+
this.scope = String(reply.scope);
|
|
173
|
+
this.socket = socket;
|
|
174
|
+
socket.onmessage = (message) => this.receive(String(message.data));
|
|
175
|
+
socket.onclose = () => this.lost(socket);
|
|
176
|
+
for (const wake of this.waiting.splice(0))
|
|
177
|
+
wake();
|
|
178
|
+
}
|
|
179
|
+
async offered() {
|
|
180
|
+
const { protocols } = this.options;
|
|
181
|
+
if (typeof protocols !== 'function')
|
|
182
|
+
return protocols;
|
|
183
|
+
try {
|
|
184
|
+
return await protocols();
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
if (error instanceof ThreadException)
|
|
188
|
+
throw error;
|
|
189
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
190
|
+
throw new TransportError(`client: the protocols function threw: ${reason}`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
receive(text) {
|
|
194
|
+
let frame;
|
|
195
|
+
try {
|
|
196
|
+
frame = decode(text);
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (frame.type === 'response' || frame.type === 'error') {
|
|
202
|
+
const waiter = this.pending.get(frame.id);
|
|
203
|
+
if (!waiter)
|
|
204
|
+
return;
|
|
205
|
+
this.pending.delete(frame.id);
|
|
206
|
+
if (frame.type === 'error')
|
|
207
|
+
waiter.reject(raised(frame.error.code, frame.error.message));
|
|
208
|
+
else
|
|
209
|
+
waiter.resolve(frame.payload);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (frame.type !== 'push')
|
|
213
|
+
return;
|
|
214
|
+
if (frame.name === 'joined') {
|
|
215
|
+
const joined = frame.payload;
|
|
216
|
+
this.left.delete(joined.thread.id);
|
|
217
|
+
this.leaving.delete(joined.thread.id);
|
|
218
|
+
this.cursors.set(joined.thread.id, Math.max(this.cursors.get(joined.thread.id) ?? 0, joined.seq));
|
|
219
|
+
this.emit(joined);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (frame.name === 'event') {
|
|
223
|
+
const event = frame.payload;
|
|
224
|
+
if (this.leaving.has(event.thread_id))
|
|
225
|
+
return;
|
|
226
|
+
const rewind = this.rewinds.find((pending) => pending.threadId === event.thread_id &&
|
|
227
|
+
event.seq > pending.since &&
|
|
228
|
+
event.seq <= pending.held &&
|
|
229
|
+
!pending.taken.has(event.seq));
|
|
230
|
+
if (rewind) {
|
|
231
|
+
rewind.taken.add(event.seq);
|
|
232
|
+
this.emit(event);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const cursor = this.cursors.get(event.thread_id);
|
|
236
|
+
if (cursor !== undefined) {
|
|
237
|
+
if (event.seq <= cursor)
|
|
238
|
+
return;
|
|
239
|
+
this.cursors.set(event.thread_id, event.seq);
|
|
240
|
+
}
|
|
241
|
+
if (event.kind === 'member_removed' && event.identity.id === this.identity.id)
|
|
242
|
+
this.cursors.delete(event.thread_id);
|
|
243
|
+
this.emit(event);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const signal = frame.payload;
|
|
247
|
+
if (this.leaving.has(signal.thread_id) && signal.kind !== 'marked')
|
|
248
|
+
return;
|
|
249
|
+
if (signal.kind === 'thread.deleted')
|
|
250
|
+
this.cursors.delete(signal.thread_id);
|
|
251
|
+
this.emit(signal);
|
|
252
|
+
}
|
|
253
|
+
emit(item) {
|
|
254
|
+
const who = 'author' in item ? item.author : 'sender' in item ? item.sender : null;
|
|
255
|
+
const own = who !== null && who.id === this.identity.id && !('kind' in item && item.kind === 'marked');
|
|
256
|
+
for (const [listener, includeOwn] of this.listeners) {
|
|
257
|
+
if (!includeOwn && own)
|
|
258
|
+
continue;
|
|
259
|
+
try {
|
|
260
|
+
listener(item);
|
|
261
|
+
}
|
|
262
|
+
catch (error) {
|
|
263
|
+
queueMicrotask(() => {
|
|
264
|
+
throw error;
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
change(status) {
|
|
270
|
+
if (this.current === status || this.current === 'closed')
|
|
271
|
+
return;
|
|
272
|
+
this.current = status;
|
|
273
|
+
this.emit({ kind: 'status', status });
|
|
274
|
+
}
|
|
275
|
+
lost(socket) {
|
|
276
|
+
if (this.socket !== socket)
|
|
277
|
+
return;
|
|
278
|
+
this.socket = null;
|
|
279
|
+
for (const waiter of this.pending.values())
|
|
280
|
+
waiter.reject(new TransportError('client: connection lost'));
|
|
281
|
+
this.pending.clear();
|
|
282
|
+
if (this.stopped)
|
|
283
|
+
return;
|
|
284
|
+
this.change('reconnecting');
|
|
285
|
+
void this.reconnect();
|
|
286
|
+
}
|
|
287
|
+
async reconnect() {
|
|
288
|
+
for (let attempt = 0; !this.stopped; attempt++) {
|
|
289
|
+
const ceiling = attempt === 0 ? 0 : Math.min(timing.reconnectCapMs, timing.reconnectMs * 2 ** (attempt - 1));
|
|
290
|
+
await sleep(Math.random() * ceiling);
|
|
291
|
+
if (this.stopped)
|
|
292
|
+
return;
|
|
293
|
+
try {
|
|
294
|
+
await this.establish();
|
|
295
|
+
}
|
|
296
|
+
catch (error) {
|
|
297
|
+
if (error instanceof ForbiddenError || error instanceof ConfigurationError) {
|
|
298
|
+
this.fail(error);
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
await this.rejoin();
|
|
304
|
+
if (this.socket)
|
|
305
|
+
this.change('open');
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
async rejoin() {
|
|
310
|
+
let followed = false;
|
|
311
|
+
if (this.following) {
|
|
312
|
+
this.leaving = new Set(this.left);
|
|
313
|
+
try {
|
|
314
|
+
await this.followFrom(true, Object.fromEntries(this.cursors));
|
|
315
|
+
followed = true;
|
|
316
|
+
}
|
|
317
|
+
catch (error) {
|
|
318
|
+
if (error instanceof TransportError)
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
for (const threadId of [...this.leaving].sort()) {
|
|
322
|
+
if (!this.leaving.has(threadId))
|
|
323
|
+
continue;
|
|
324
|
+
try {
|
|
325
|
+
await this.request('thread.leave', { thread_id: threadId });
|
|
326
|
+
}
|
|
327
|
+
catch (error) {
|
|
328
|
+
if (error instanceof TransportError)
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
this.leaving = new Set();
|
|
333
|
+
}
|
|
334
|
+
for (const threadId of [...this.cursors.keys()]) {
|
|
335
|
+
const cursor = this.cursors.get(threadId);
|
|
336
|
+
if (cursor === undefined || (followed && !this.held.has(threadId)))
|
|
337
|
+
continue;
|
|
338
|
+
try {
|
|
339
|
+
this.emit(await this.joinFrom(threadId, cursor));
|
|
340
|
+
}
|
|
341
|
+
catch (error) {
|
|
342
|
+
if (error instanceof TransportError)
|
|
343
|
+
return;
|
|
344
|
+
this.cursors.delete(threadId);
|
|
345
|
+
this.held.delete(threadId);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
fail(error) {
|
|
350
|
+
this.failure = error;
|
|
351
|
+
this.stopped = true;
|
|
352
|
+
this.change('closed');
|
|
353
|
+
this.settle(error);
|
|
354
|
+
}
|
|
355
|
+
request(method, payload) {
|
|
356
|
+
if (this.stopped)
|
|
357
|
+
return Promise.reject(this.failure ?? new TransportError('client: the client is closed'));
|
|
358
|
+
const socket = this.socket;
|
|
359
|
+
if (!socket)
|
|
360
|
+
return Promise.reject(new TransportError('client: not connected'));
|
|
361
|
+
const id = String(this.nextId++);
|
|
362
|
+
return new Promise((resolve, reject) => {
|
|
363
|
+
this.pending.set(id, { resolve, reject });
|
|
364
|
+
try {
|
|
365
|
+
socket.send(encode({ type: 'request', id, method, payload }));
|
|
366
|
+
}
|
|
367
|
+
catch (error) {
|
|
368
|
+
this.pending.delete(id);
|
|
369
|
+
reject(new TransportError(`client: ${method} failed: ${String(error)}`));
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
notify(method, payload) {
|
|
374
|
+
try {
|
|
375
|
+
this.socket?.send(encode({ type: 'notify', method, payload }));
|
|
376
|
+
}
|
|
377
|
+
catch {
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
async event(threadId, fields, clientId) {
|
|
382
|
+
const reply = await this.outbox.send(threadId, {
|
|
383
|
+
thread_id: threadId,
|
|
384
|
+
client_id: clientId ?? newId(),
|
|
385
|
+
...fields,
|
|
386
|
+
});
|
|
387
|
+
return reply.event;
|
|
388
|
+
}
|
|
389
|
+
async message(threadId, content, options, clientId) {
|
|
390
|
+
const fields = {
|
|
391
|
+
kind: 'message',
|
|
392
|
+
content: parts(content),
|
|
393
|
+
in_reply_to: options.inReplyTo ?? null,
|
|
394
|
+
triggered_by: options.triggeredBy ?? null,
|
|
395
|
+
metadata: options.metadata ?? {},
|
|
396
|
+
};
|
|
397
|
+
return (await this.event(threadId, fields, clientId));
|
|
398
|
+
}
|
|
399
|
+
async joinFrom(threadId, since, resume = false) {
|
|
400
|
+
const held = this.cursors.get(threadId);
|
|
401
|
+
const start = resume ? 0 : since;
|
|
402
|
+
const rewind = start !== null && held !== undefined && start < held
|
|
403
|
+
? { threadId, since: start, held, taken: new Set() }
|
|
404
|
+
: null;
|
|
405
|
+
if (held === undefined)
|
|
406
|
+
this.cursors.set(threadId, since ?? 0);
|
|
407
|
+
if (rewind)
|
|
408
|
+
this.rewinds.push(rewind);
|
|
409
|
+
const payload = { thread_id: threadId, since };
|
|
410
|
+
if (resume)
|
|
411
|
+
payload.resume = true;
|
|
412
|
+
let joined;
|
|
413
|
+
try {
|
|
414
|
+
joined = (await this.request('thread.join', payload));
|
|
415
|
+
}
|
|
416
|
+
finally {
|
|
417
|
+
this.rewinds = this.rewinds.filter((other) => other !== rewind);
|
|
418
|
+
}
|
|
419
|
+
this.cursors.set(threadId, joined.seq < (since ?? 0) ? joined.seq : Math.max(this.cursors.get(threadId) ?? 0, joined.seq));
|
|
420
|
+
return joined;
|
|
421
|
+
}
|
|
422
|
+
async createThread(options = {}) {
|
|
423
|
+
const reply = await this.request('thread.create', {
|
|
424
|
+
thread_id: options.threadId ?? null,
|
|
425
|
+
metadata: options.metadata ?? {},
|
|
426
|
+
});
|
|
427
|
+
return reply.thread;
|
|
428
|
+
}
|
|
429
|
+
async getThread(threadId) {
|
|
430
|
+
return (await this.request('thread.get', { thread_id: threadId })).thread;
|
|
431
|
+
}
|
|
432
|
+
async listThreads(options = {}) {
|
|
433
|
+
const payload = { before: options.before ?? null, limit: options.limit ?? 50 };
|
|
434
|
+
if (options.order !== undefined && options.order !== 'created')
|
|
435
|
+
payload.order = options.order;
|
|
436
|
+
if (options.preview)
|
|
437
|
+
payload.preview = true;
|
|
438
|
+
const reply = await this.request('thread.list', payload);
|
|
439
|
+
return reply.threads;
|
|
440
|
+
}
|
|
441
|
+
async updateThread(threadId, metadata) {
|
|
442
|
+
return (await this.request('thread.update', { thread_id: threadId, metadata })).thread;
|
|
443
|
+
}
|
|
444
|
+
async deleteThread(threadId) {
|
|
445
|
+
await this.request('thread.delete', { thread_id: threadId });
|
|
446
|
+
this.cursors.delete(threadId);
|
|
447
|
+
}
|
|
448
|
+
async join(threadId, options = {}) {
|
|
449
|
+
this.left.delete(threadId);
|
|
450
|
+
this.leaving.delete(threadId);
|
|
451
|
+
const known = this.cursors.has(threadId);
|
|
452
|
+
try {
|
|
453
|
+
const joined = await this.joinFrom(threadId, options.since ?? null, options.resume ?? false);
|
|
454
|
+
this.held.add(threadId);
|
|
455
|
+
return joined;
|
|
456
|
+
}
|
|
457
|
+
catch (error) {
|
|
458
|
+
if (!known)
|
|
459
|
+
this.cursors.delete(threadId);
|
|
460
|
+
throw error;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
async leave(threadId) {
|
|
464
|
+
this.cursors.delete(threadId);
|
|
465
|
+
this.held.delete(threadId);
|
|
466
|
+
if (this.following)
|
|
467
|
+
this.left.add(threadId);
|
|
468
|
+
await this.request('thread.leave', { thread_id: threadId });
|
|
469
|
+
}
|
|
470
|
+
async follow(options = {}) {
|
|
471
|
+
this.left.clear();
|
|
472
|
+
this.leaving.clear();
|
|
473
|
+
return this.followFrom(options.resume ?? false, null);
|
|
474
|
+
}
|
|
475
|
+
async followFrom(resume, since) {
|
|
476
|
+
const reply = await this.request('thread.follow', { resume, since });
|
|
477
|
+
this.following = true;
|
|
478
|
+
const found = reply.joined.filter((joined) => !this.leaving.has(joined.thread.id));
|
|
479
|
+
for (const joined of found) {
|
|
480
|
+
const id = joined.thread.id;
|
|
481
|
+
const sent = since?.[id];
|
|
482
|
+
this.cursors.set(id, sent !== undefined && joined.seq < sent
|
|
483
|
+
? joined.seq
|
|
484
|
+
: Math.max(this.cursors.get(id) ?? 0, joined.seq));
|
|
485
|
+
this.emit(joined);
|
|
486
|
+
}
|
|
487
|
+
return found;
|
|
488
|
+
}
|
|
489
|
+
async mark(threadId, seq) {
|
|
490
|
+
const reply = await this.request('thread.mark', { thread_id: threadId, seq });
|
|
491
|
+
return reply.seq;
|
|
492
|
+
}
|
|
493
|
+
async marked(threadId) {
|
|
494
|
+
const reply = await this.request('thread.marked', { thread_id: threadId });
|
|
495
|
+
return reply.seq ?? null;
|
|
496
|
+
}
|
|
497
|
+
async history(threadId, options = {}) {
|
|
498
|
+
const payload = {
|
|
499
|
+
thread_id: threadId,
|
|
500
|
+
before: options.before ?? null,
|
|
501
|
+
limit: options.limit ?? 50,
|
|
502
|
+
kinds: options.kinds ?? null,
|
|
503
|
+
};
|
|
504
|
+
if (options.after !== undefined)
|
|
505
|
+
payload.after = options.after;
|
|
506
|
+
const reply = await this.request('thread.history', payload);
|
|
507
|
+
return reply.events;
|
|
508
|
+
}
|
|
509
|
+
async present(threadId) {
|
|
510
|
+
return (await this.request('thread.present', { thread_id: threadId })).identities;
|
|
511
|
+
}
|
|
512
|
+
async addMember(threadId, identity) {
|
|
513
|
+
return (await this.request('member.add', { thread_id: threadId, identity })).member;
|
|
514
|
+
}
|
|
515
|
+
async removeMember(threadId, identity) {
|
|
516
|
+
await this.request('member.remove', { thread_id: threadId, identity_id: identity.id });
|
|
517
|
+
}
|
|
518
|
+
async listMembers(threadId) {
|
|
519
|
+
return (await this.request('member.list', { thread_id: threadId })).members;
|
|
520
|
+
}
|
|
521
|
+
send(threadId, content, options = {}) {
|
|
522
|
+
return this.message(threadId, content, options, options.clientId);
|
|
523
|
+
}
|
|
524
|
+
stream(threadId, options = {}) {
|
|
525
|
+
return new Stream(this.wire, threadId, options);
|
|
526
|
+
}
|
|
527
|
+
async step(threadId, options) {
|
|
528
|
+
return (await this.event(threadId, {
|
|
529
|
+
kind: 'step',
|
|
530
|
+
name: options.name,
|
|
531
|
+
input: options.input ?? {},
|
|
532
|
+
output: options.output ?? [],
|
|
533
|
+
is_error: options.isError ?? false,
|
|
534
|
+
duration_ms: options.durationMs ?? null,
|
|
535
|
+
in_reply_to: options.inReplyTo ?? null,
|
|
536
|
+
triggered_by: options.triggeredBy ?? null,
|
|
537
|
+
}, options.clientId));
|
|
538
|
+
}
|
|
539
|
+
async edit(threadId, target, content, options = {}) {
|
|
540
|
+
return (await this.event(threadId, { kind: 'edit', target, content: parts(content) }, options.clientId));
|
|
541
|
+
}
|
|
542
|
+
async retract(threadId, target, options = {}) {
|
|
543
|
+
return (await this.event(threadId, { kind: 'retract', target }, options.clientId));
|
|
544
|
+
}
|
|
545
|
+
async read(threadId, upToSeq) {
|
|
546
|
+
return (await this.event(threadId, { kind: 'read', up_to_seq: upToSeq }));
|
|
547
|
+
}
|
|
548
|
+
async custom(threadId, name, payload, options = {}) {
|
|
549
|
+
return (await this.event(threadId, { kind: 'custom', name, payload }, options.clientId));
|
|
550
|
+
}
|
|
551
|
+
async working(threadId, label) {
|
|
552
|
+
await this.request('signal.send', {
|
|
553
|
+
thread_id: threadId,
|
|
554
|
+
kind: 'working',
|
|
555
|
+
label: label ?? null,
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
async idle(threadId) {
|
|
559
|
+
await this.request('signal.send', { thread_id: threadId, kind: 'idle' });
|
|
560
|
+
}
|
|
561
|
+
async cancel(threadId, to) {
|
|
562
|
+
await this.request('signal.send', { thread_id: threadId, kind: 'cancel', to });
|
|
563
|
+
}
|
|
564
|
+
get status() {
|
|
565
|
+
return this.current;
|
|
566
|
+
}
|
|
567
|
+
subscribe(listener, options = {}) {
|
|
568
|
+
this.listeners.set(listener, options.includeOwn ?? false);
|
|
569
|
+
return () => {
|
|
570
|
+
this.listeners.delete(listener);
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
async close() {
|
|
574
|
+
if (this.stopped && this.socket === null)
|
|
575
|
+
return;
|
|
576
|
+
this.stopped = true;
|
|
577
|
+
const socket = this.socket;
|
|
578
|
+
this.socket = null;
|
|
579
|
+
for (const waiter of this.pending.values())
|
|
580
|
+
waiter.reject(new TransportError('client: the client is closed'));
|
|
581
|
+
this.pending.clear();
|
|
582
|
+
socket?.close(1000, 'client: closed');
|
|
583
|
+
this.change('closed');
|
|
584
|
+
this.settle(null);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
export async function connect(options) {
|
|
588
|
+
const client = new Client(options);
|
|
589
|
+
await establish(client);
|
|
590
|
+
return client;
|
|
591
|
+
}
|
|
592
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,MAAM,EACN,eAAe,EACf,cAAc,GACf,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAc,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC1F,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAuCpC,MAAM,KAAK,GAAG,CAAC,OAAgB,EAAU,EAAE,CACzC,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,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S,CAAC,MAAM,CAAC,CAAA;IACvB,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare class ThreadException extends Error {
|
|
2
|
+
readonly code: string;
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class NotFoundError extends ThreadException {
|
|
6
|
+
readonly code: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class InputError extends ThreadException {
|
|
9
|
+
readonly code: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class ConfigurationError extends ThreadException {
|
|
12
|
+
readonly code: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class ForbiddenError extends ThreadException {
|
|
15
|
+
readonly code: string;
|
|
16
|
+
}
|
|
17
|
+
export declare class StorageError extends ThreadException {
|
|
18
|
+
readonly code: string;
|
|
19
|
+
}
|
|
20
|
+
export declare class TransportError extends ThreadException {
|
|
21
|
+
readonly code: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function raised(code: string, message: string): ThreadException;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export class ThreadException extends Error {
|
|
2
|
+
code = 'internal';
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = new.target.name;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export class NotFoundError extends ThreadException {
|
|
9
|
+
code = 'not_found';
|
|
10
|
+
}
|
|
11
|
+
export class InputError extends ThreadException {
|
|
12
|
+
code = 'input';
|
|
13
|
+
}
|
|
14
|
+
export class ConfigurationError extends ThreadException {
|
|
15
|
+
code = 'configuration';
|
|
16
|
+
}
|
|
17
|
+
export class ForbiddenError extends ThreadException {
|
|
18
|
+
code = 'forbidden';
|
|
19
|
+
}
|
|
20
|
+
export class StorageError extends ThreadException {
|
|
21
|
+
code = 'storage';
|
|
22
|
+
}
|
|
23
|
+
export class TransportError extends ThreadException {
|
|
24
|
+
code = 'transport';
|
|
25
|
+
}
|
|
26
|
+
const CLASSES = {
|
|
27
|
+
internal: ThreadException,
|
|
28
|
+
not_found: NotFoundError,
|
|
29
|
+
input: InputError,
|
|
30
|
+
configuration: ConfigurationError,
|
|
31
|
+
forbidden: ForbiddenError,
|
|
32
|
+
storage: StorageError,
|
|
33
|
+
transport: TransportError,
|
|
34
|
+
};
|
|
35
|
+
export function raised(code, message) {
|
|
36
|
+
return new (CLASSES[code] ?? ThreadException)(message);
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAC/B,IAAI,GAAW,UAAU,CAAA;IAElC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,IAAI,MAAM,CAAC,IAAI,CAAA;IAC7B,CAAC;CACF;AAED,MAAM,OAAO,aAAc,SAAQ,eAAe;IAC9B,IAAI,GAAW,WAAW,CAAA;CAC7C;AAED,MAAM,OAAO,UAAW,SAAQ,eAAe;IAC3B,IAAI,GAAW,OAAO,CAAA;CACzC;AAED,MAAM,OAAO,kBAAmB,SAAQ,eAAe;IACnC,IAAI,GAAW,eAAe,CAAA;CACjD;AAED,MAAM,OAAO,cAAe,SAAQ,eAAe;IAC/B,IAAI,GAAW,WAAW,CAAA;CAC7C;AAED,MAAM,OAAO,YAAa,SAAQ,eAAe;IAC7B,IAAI,GAAW,SAAS,CAAA;CAC3C;AAED,MAAM,OAAO,cAAe,SAAQ,eAAe;IAC/B,IAAI,GAAW,WAAW,CAAA;CAC7C;AAED,MAAM,OAAO,GAA6D;IACxE,QAAQ,EAAE,eAAe;IACzB,SAAS,EAAE,aAAa;IACxB,KAAK,EAAE,UAAU;IACjB,aAAa,EAAE,kBAAkB;IACjC,SAAS,EAAE,cAAc;IACzB,OAAO,EAAE,YAAY;IACrB,SAAS,EAAE,cAAc;CAC1B,CAAA;AAED,MAAM,UAAU,MAAM,CAAC,IAAY,EAAE,OAAe;IAClD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,eAAe,CAAC,CAAC,OAAO,CAAC,CAAA;AACxD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { ConnectOptions, Listener, Protocols, SendOptions, StepOptions, StreamOptions, WriteOptions, } from './client.js';
|
|
2
|
+
export { Client, connect, Stream } from './client.js';
|
|
3
|
+
export { ConfigurationError, ForbiddenError, InputError, NotFoundError, StorageError, ThreadException, TransportError, } from './errors.js';
|
|
4
|
+
export { resolve } from './resolve.js';
|
|
5
|
+
export type * from './types.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { Client, connect, Stream } from './client.js';
|
|
2
|
+
export { ConfigurationError, ForbiddenError, InputError, NotFoundError, StorageError, ThreadException, TransportError, } from './errors.js';
|
|
3
|
+
export { resolve } from './resolve.js';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,aAAa,EACb,YAAY,EACZ,eAAe,EACf,cAAc,GACf,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA"}
|
package/dist/outbox.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type Payload = Record<string, unknown>;
|
|
2
|
+
export type OutboxHooks = {
|
|
3
|
+
isConnected(): boolean;
|
|
4
|
+
isClosed(): boolean;
|
|
5
|
+
waitConnected(ms: number): Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare class Outbox {
|
|
8
|
+
private readonly deliver;
|
|
9
|
+
private readonly hooks;
|
|
10
|
+
private readonly tails;
|
|
11
|
+
constructor(deliver: (payload: Payload) => Promise<Payload>, hooks: OutboxHooks);
|
|
12
|
+
send(threadId: string, payload: Payload): Promise<Payload>;
|
|
13
|
+
private attempt;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
package/dist/outbox.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { TransportError } from './errors.js';
|
|
2
|
+
import { timing } from './timing.js';
|
|
3
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
4
|
+
export class Outbox {
|
|
5
|
+
deliver;
|
|
6
|
+
hooks;
|
|
7
|
+
tails = new Map();
|
|
8
|
+
constructor(deliver, hooks) {
|
|
9
|
+
this.deliver = deliver;
|
|
10
|
+
this.hooks = hooks;
|
|
11
|
+
}
|
|
12
|
+
send(threadId, payload) {
|
|
13
|
+
const previous = this.tails.get(threadId) ?? Promise.resolve();
|
|
14
|
+
const run = () => this.attempt(threadId, payload);
|
|
15
|
+
const result = previous.then(run, run);
|
|
16
|
+
this.tails.set(threadId, result.catch(() => undefined));
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
async attempt(threadId, payload) {
|
|
20
|
+
const started = Date.now();
|
|
21
|
+
for (let attempt = 0;; attempt++) {
|
|
22
|
+
try {
|
|
23
|
+
return await this.deliver(payload);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (!(error instanceof TransportError) || this.hooks.isClosed())
|
|
27
|
+
throw error;
|
|
28
|
+
const elapsed = Date.now() - started;
|
|
29
|
+
if (elapsed >= timing.deadlineMs) {
|
|
30
|
+
throw new TransportError(`client: event '${String(payload.client_id)}' for thread '${threadId}' was not acknowledged within ${timing.deadlineMs / 1000}s`);
|
|
31
|
+
}
|
|
32
|
+
const delay = Math.min(timing.backoffMs * 2 ** attempt, timing.backoffCapMs, timing.deadlineMs - elapsed);
|
|
33
|
+
await (this.hooks.isConnected() ? sleep(delay) : this.hooks.waitConnected(delay));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=outbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outbox.js","sourceRoot":"","sources":["../src/outbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAUpC,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAA;AAErF,MAAM,OAAO,MAAM;IAIE,OAAO;IACP,KAAK;IAJP,KAAK,GAAG,IAAI,GAAG,EAA4B,CAAA;IAE5D,YACmB,OAA+C,EAC/C,KAAkB;uBADlB,OAAO;qBACP,KAAK;IACrB,CAAC;IAEJ,IAAI,CAAC,QAAgB,EAAE,OAAgB;QACrC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE,CAAA;QAC9D,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;QACjD,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;QACtC,IAAI,CAAC,KAAK,CAAC,GAAG,CACZ,QAAQ,EACR,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAC9B,CAAA;QACD,OAAO,MAAM,CAAA;IACf,CAAC;IAEO,KAAK,CAAC,OAAO,CAAC,QAAgB,EAAE,OAAgB;QACtD,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAC1B,KAAK,IAAI,OAAO,GAAG,CAAC,GAAI,OAAO,EAAE,EAAE,CAAC;YAClC,IAAI,CAAC;gBACH,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;YACpC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,CAAC,KAAK,YAAY,cAAc,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;oBAAE,MAAM,KAAK,CAAA;gBAC5E,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAA;gBACpC,IAAI,OAAO,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;oBACjC,MAAM,IAAI,cAAc,CACtB,kBAAkB,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,iBAAiB,QAAQ,iCAAiC,MAAM,CAAC,UAAU,GAAG,IAAI,GAAG,CACjI,CAAA;gBACH,CAAC;gBACD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CACpB,MAAM,CAAC,SAAS,GAAG,CAAC,IAAI,OAAO,EAC/B,MAAM,CAAC,YAAY,EACnB,MAAM,CAAC,UAAU,GAAG,OAAO,CAC5B,CAAA;gBACD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAA;YACnF,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export declare const PROTOCOL = 1;
|
|
2
|
+
export declare const HELLO = "hello";
|
|
3
|
+
export declare const CLOSE_REFUSED = 1008;
|
|
4
|
+
type Payload = Record<string, unknown>;
|
|
5
|
+
export type Hello = {
|
|
6
|
+
type: 'hello';
|
|
7
|
+
protocol: number;
|
|
8
|
+
};
|
|
9
|
+
export type Request = {
|
|
10
|
+
type: 'request';
|
|
11
|
+
id: string;
|
|
12
|
+
method: string;
|
|
13
|
+
payload: Payload;
|
|
14
|
+
};
|
|
15
|
+
export type Response = {
|
|
16
|
+
type: 'response';
|
|
17
|
+
id: string;
|
|
18
|
+
payload: Payload;
|
|
19
|
+
};
|
|
20
|
+
export type ErrorFrame = {
|
|
21
|
+
type: 'error';
|
|
22
|
+
id: string;
|
|
23
|
+
error: {
|
|
24
|
+
code: string;
|
|
25
|
+
message: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export type Push = {
|
|
29
|
+
type: 'push';
|
|
30
|
+
name: 'event' | 'signal' | 'joined';
|
|
31
|
+
payload: Payload;
|
|
32
|
+
};
|
|
33
|
+
export type Notify = {
|
|
34
|
+
type: 'notify';
|
|
35
|
+
method: string;
|
|
36
|
+
payload: Payload;
|
|
37
|
+
};
|
|
38
|
+
export type Frame = Hello | Request | Response | ErrorFrame | Push | Notify;
|
|
39
|
+
export declare function encode(frame: Frame): string;
|
|
40
|
+
export declare function decode(text: string): Frame;
|
|
41
|
+
export {};
|
package/dist/protocol.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { InputError } from './errors.js';
|
|
2
|
+
export const PROTOCOL = 1;
|
|
3
|
+
export const HELLO = 'hello';
|
|
4
|
+
export const CLOSE_REFUSED = 1008;
|
|
5
|
+
const TYPES = new Set(['hello', 'request', 'response', 'error', 'push', 'notify']);
|
|
6
|
+
export function encode(frame) {
|
|
7
|
+
return JSON.stringify(frame);
|
|
8
|
+
}
|
|
9
|
+
export function decode(text) {
|
|
10
|
+
let frame;
|
|
11
|
+
try {
|
|
12
|
+
frame = JSON.parse(text);
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
throw new InputError(`protocol: malformed frame: ${error.message.toLowerCase()}`);
|
|
16
|
+
}
|
|
17
|
+
if (typeof frame !== 'object' ||
|
|
18
|
+
frame === null ||
|
|
19
|
+
!TYPES.has(frame.type ?? '')) {
|
|
20
|
+
throw new InputError('protocol: malformed frame: unknown type');
|
|
21
|
+
}
|
|
22
|
+
return frame;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAA;AACzB,MAAM,CAAC,MAAM,KAAK,GAAG,OAAO,CAAA;AAC5B,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAA;AAWjC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAA;AAElF,MAAM,UAAU,MAAM,CAAC,KAAY;IACjC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;AAC9B,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,IAAY;IACjC,IAAI,KAAc,CAAA;IAClB,IAAI,CAAC;QACH,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC1B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,UAAU,CAAC,8BAA+B,KAAe,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;IAC9F,CAAC;IACD,IACE,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,CAAC,KAAK,CAAC,GAAG,CAAE,KAA2B,CAAC,IAAI,IAAI,EAAE,CAAC,EACnD,CAAC;QACD,MAAM,IAAI,UAAU,CAAC,yCAAyC,CAAC,CAAA;IACjE,CAAC;IACD,OAAO,KAAc,CAAA;AACvB,CAAC"}
|
package/dist/resolve.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function resolve(events) {
|
|
2
|
+
const ordered = [...events].sort((a, b) => a.seq - b.seq);
|
|
3
|
+
const edits = new Map();
|
|
4
|
+
const retracted = new Set();
|
|
5
|
+
for (const event of ordered) {
|
|
6
|
+
if (event.kind === 'edit')
|
|
7
|
+
edits.set(event.target, event);
|
|
8
|
+
else if (event.kind === 'retract')
|
|
9
|
+
retracted.add(event.target);
|
|
10
|
+
}
|
|
11
|
+
const view = [];
|
|
12
|
+
for (const event of ordered) {
|
|
13
|
+
if (event.kind === 'edit' || event.kind === 'retract' || retracted.has(event.id))
|
|
14
|
+
continue;
|
|
15
|
+
const edit = edits.get(event.id);
|
|
16
|
+
view.push(event.kind === 'message' && edit ? { ...event, content: edit.content } : event);
|
|
17
|
+
}
|
|
18
|
+
return view;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,OAAO,CAAC,MAAe;IACrC,MAAM,OAAO,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAA;IACzD,MAAM,KAAK,GAAG,IAAI,GAAG,EAAgB,CAAA;IACrC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAU,CAAA;IACnC,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM;YAAE,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;aACpD,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS;YAAE,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IAChE,CAAC;IACD,MAAM,IAAI,GAAY,EAAE,CAAA;IACxB,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAAE,SAAQ;QAC1F,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAChC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;IAC3F,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/dist/timing.d.ts
ADDED
package/dist/timing.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timing.js","sourceRoot":"","sources":["../src/timing.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,WAAW,EAAE,MAAM;IACnB,WAAW,EAAE,GAAG;IAChB,cAAc,EAAE,MAAM;IACtB,UAAU,EAAE,MAAM;IAClB,SAAS,EAAE,GAAG;IACd,YAAY,EAAE,KAAK;CACpB,CAAA"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
export type Identity = {
|
|
2
|
+
role: 'user' | 'assistant' | 'system';
|
|
3
|
+
id: string;
|
|
4
|
+
name?: string | null;
|
|
5
|
+
metadata?: Record<string, unknown>;
|
|
6
|
+
};
|
|
7
|
+
export type Text = {
|
|
8
|
+
type: 'text';
|
|
9
|
+
text: string;
|
|
10
|
+
};
|
|
11
|
+
type Media = {
|
|
12
|
+
media_type: string;
|
|
13
|
+
data?: string | null;
|
|
14
|
+
url?: string | null;
|
|
15
|
+
};
|
|
16
|
+
export type Image = Media & {
|
|
17
|
+
type: 'image';
|
|
18
|
+
};
|
|
19
|
+
export type Audio = Media & {
|
|
20
|
+
type: 'audio';
|
|
21
|
+
};
|
|
22
|
+
export type Document = Media & {
|
|
23
|
+
type: 'document';
|
|
24
|
+
name?: string | null;
|
|
25
|
+
};
|
|
26
|
+
export type Part = Text | Image | Audio | Document;
|
|
27
|
+
export type Content = string | Part[];
|
|
28
|
+
export type Thread = {
|
|
29
|
+
id: string;
|
|
30
|
+
scope: string;
|
|
31
|
+
metadata: Record<string, unknown>;
|
|
32
|
+
created_at: string;
|
|
33
|
+
last_seq?: number;
|
|
34
|
+
last_message_at?: string;
|
|
35
|
+
marked?: number;
|
|
36
|
+
unread?: number;
|
|
37
|
+
last_message?: Message;
|
|
38
|
+
};
|
|
39
|
+
export type Member = {
|
|
40
|
+
thread_id: string;
|
|
41
|
+
identity: Identity;
|
|
42
|
+
added_at: string;
|
|
43
|
+
added_by: Identity;
|
|
44
|
+
};
|
|
45
|
+
type Envelope = {
|
|
46
|
+
id: string;
|
|
47
|
+
thread_id: string;
|
|
48
|
+
seq: number;
|
|
49
|
+
author: Identity;
|
|
50
|
+
created_at: string;
|
|
51
|
+
client_id: string;
|
|
52
|
+
in_reply_to: string | null;
|
|
53
|
+
triggered_by: Identity | null;
|
|
54
|
+
};
|
|
55
|
+
export type Message = Envelope & {
|
|
56
|
+
kind: 'message';
|
|
57
|
+
content: Part[];
|
|
58
|
+
metadata: Record<string, unknown>;
|
|
59
|
+
};
|
|
60
|
+
export type Step = Envelope & {
|
|
61
|
+
kind: 'step';
|
|
62
|
+
name: string;
|
|
63
|
+
input: Record<string, unknown>;
|
|
64
|
+
output: Part[];
|
|
65
|
+
is_error: boolean;
|
|
66
|
+
duration_ms: number | null;
|
|
67
|
+
};
|
|
68
|
+
export type Edit = Envelope & {
|
|
69
|
+
kind: 'edit';
|
|
70
|
+
target: string;
|
|
71
|
+
content: Part[];
|
|
72
|
+
};
|
|
73
|
+
export type Retract = Envelope & {
|
|
74
|
+
kind: 'retract';
|
|
75
|
+
target: string;
|
|
76
|
+
};
|
|
77
|
+
export type Read = Envelope & {
|
|
78
|
+
kind: 'read';
|
|
79
|
+
up_to_seq: number;
|
|
80
|
+
};
|
|
81
|
+
export type MemberAdded = Envelope & {
|
|
82
|
+
kind: 'member_added';
|
|
83
|
+
identity: Identity;
|
|
84
|
+
};
|
|
85
|
+
export type MemberRemoved = Envelope & {
|
|
86
|
+
kind: 'member_removed';
|
|
87
|
+
identity: Identity;
|
|
88
|
+
};
|
|
89
|
+
export type ThreadUpdated = Envelope & {
|
|
90
|
+
kind: 'thread_updated';
|
|
91
|
+
metadata: Record<string, unknown>;
|
|
92
|
+
};
|
|
93
|
+
export type Custom = Envelope & {
|
|
94
|
+
kind: 'custom';
|
|
95
|
+
name: string;
|
|
96
|
+
payload: Record<string, unknown>;
|
|
97
|
+
};
|
|
98
|
+
export type Event = Message | Step | Edit | Retract | Read | MemberAdded | MemberRemoved | ThreadUpdated | Custom;
|
|
99
|
+
type Sent = {
|
|
100
|
+
thread_id: string;
|
|
101
|
+
sender: Identity;
|
|
102
|
+
};
|
|
103
|
+
export type Working = Sent & {
|
|
104
|
+
kind: 'working';
|
|
105
|
+
label: string | null;
|
|
106
|
+
};
|
|
107
|
+
export type Idle = Sent & {
|
|
108
|
+
kind: 'idle';
|
|
109
|
+
};
|
|
110
|
+
export type StreamStart = Sent & {
|
|
111
|
+
kind: 'stream.start';
|
|
112
|
+
stream_id: string;
|
|
113
|
+
in_reply_to: string | null;
|
|
114
|
+
};
|
|
115
|
+
export type StreamDelta = Sent & {
|
|
116
|
+
kind: 'stream.delta';
|
|
117
|
+
stream_id: string;
|
|
118
|
+
index: number;
|
|
119
|
+
text: string;
|
|
120
|
+
};
|
|
121
|
+
export type StreamEnd = Sent & {
|
|
122
|
+
kind: 'stream.end';
|
|
123
|
+
stream_id: string;
|
|
124
|
+
};
|
|
125
|
+
export type Cancel = Sent & {
|
|
126
|
+
kind: 'cancel';
|
|
127
|
+
to: Identity;
|
|
128
|
+
};
|
|
129
|
+
export type Present = Sent & {
|
|
130
|
+
kind: 'present';
|
|
131
|
+
};
|
|
132
|
+
export type Left = Sent & {
|
|
133
|
+
kind: 'left';
|
|
134
|
+
};
|
|
135
|
+
export type Invited = Sent & {
|
|
136
|
+
kind: 'invited';
|
|
137
|
+
thread: Thread;
|
|
138
|
+
};
|
|
139
|
+
export type ThreadDeleted = Sent & {
|
|
140
|
+
kind: 'thread.deleted';
|
|
141
|
+
};
|
|
142
|
+
export type Marked = Sent & {
|
|
143
|
+
kind: 'marked';
|
|
144
|
+
seq: number;
|
|
145
|
+
unread: number;
|
|
146
|
+
};
|
|
147
|
+
export type Signal = Working | Idle | StreamStart | StreamDelta | StreamEnd | Cancel | Present | Left | Invited | ThreadDeleted | Marked;
|
|
148
|
+
export type Joined = {
|
|
149
|
+
thread: Thread;
|
|
150
|
+
seq: number;
|
|
151
|
+
truncated: boolean;
|
|
152
|
+
};
|
|
153
|
+
export type Status = 'open' | 'reconnecting' | 'closed';
|
|
154
|
+
export type StatusChanged = {
|
|
155
|
+
kind: 'status';
|
|
156
|
+
status: Status;
|
|
157
|
+
};
|
|
158
|
+
export type Item = Event | Signal | Joined | StatusChanged;
|
|
159
|
+
export {};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rfnry/thread",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Conversational text interfaces for humans and machines",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": { "type": "git", "url": "git+https://github.com/rfnry/thread.git", "directory": "packages/typescript" },
|
|
8
|
+
"homepage": "https://github.com/rfnry/thread/blob/main/docs/thread.md",
|
|
9
|
+
"bugs": "https://github.com/rfnry/thread/issues",
|
|
10
|
+
"engines": { "node": ">=22.12.0" },
|
|
11
|
+
"exports": { ".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" } },
|
|
12
|
+
"files": ["dist"],
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc -p tsconfig.build.json",
|
|
16
|
+
"format": "biome format --write .",
|
|
17
|
+
"check": "biome check .",
|
|
18
|
+
"check:fix": "biome check --write .",
|
|
19
|
+
"typecheck": "tsc --noEmit",
|
|
20
|
+
"test": "vitest run --exclude 'tests/e2e/**'",
|
|
21
|
+
"test:e2e": "vitest run tests/e2e"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@biomejs/biome": "^2.5.2",
|
|
25
|
+
"@types/node": "^26.6.2",
|
|
26
|
+
"typescript": "^7.0.2",
|
|
27
|
+
"vitest": "^5.0.1"
|
|
28
|
+
}
|
|
29
|
+
}
|