@tomradex/dispatch 0.0.0-stage → 0.30.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 +204 -0
- package/dist/index.d.ts +5 -0
- package/dist/match.d.ts +91 -0
- package/dist/policy.d.ts +76 -0
- package/dist/queue.d.ts +167 -0
- package/dist/runtime.js +1 -0
- package/dist/service.d.ts +106 -0
- package/dist/tools.d.ts +9 -0
- package/dist/words.d.ts +18 -0
- package/package.json +44 -4
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
Copyright 2026 Haoyuan Tang
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
Apache License
|
|
5
|
+
Version 2.0, January 2004
|
|
6
|
+
http://www.apache.org/licenses/
|
|
7
|
+
|
|
8
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
9
|
+
|
|
10
|
+
1. Definitions.
|
|
11
|
+
|
|
12
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
13
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
14
|
+
|
|
15
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
16
|
+
the copyright owner that is granting the License.
|
|
17
|
+
|
|
18
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
19
|
+
other entities that control, are controlled by, or are under common
|
|
20
|
+
control with that entity. For the purposes of this definition,
|
|
21
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
22
|
+
direction or management of such entity, whether by contract or
|
|
23
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
24
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
25
|
+
|
|
26
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
27
|
+
exercising permissions granted by this License.
|
|
28
|
+
|
|
29
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
30
|
+
including but not limited to software source code, documentation
|
|
31
|
+
source, and configuration files.
|
|
32
|
+
|
|
33
|
+
"Object" form shall mean any form resulting from mechanical
|
|
34
|
+
transformation or translation of a Source form, including but
|
|
35
|
+
not limited to compiled object code, generated documentation,
|
|
36
|
+
and conversions to other media types.
|
|
37
|
+
|
|
38
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
39
|
+
Object form, made available under the License, as indicated by a
|
|
40
|
+
copyright notice that is included in or attached to the work
|
|
41
|
+
(an example is provided in the Appendix below).
|
|
42
|
+
|
|
43
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
44
|
+
form, that is based on (or derived from) the Work and for which the
|
|
45
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
46
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
47
|
+
of this License, Derivative Works shall not include works that remain
|
|
48
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
49
|
+
the Work and Derivative Works thereof.
|
|
50
|
+
|
|
51
|
+
"Contribution" shall mean any work of authorship, including
|
|
52
|
+
the original version of the Work and any modifications or additions
|
|
53
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
54
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
55
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
56
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
57
|
+
means any form of electronic, verbal, or written communication sent
|
|
58
|
+
to the Licensor or its representatives, including but not limited to
|
|
59
|
+
communication on electronic mailing lists, source code control systems,
|
|
60
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
61
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
62
|
+
excluding communication that is conspicuously marked or otherwise
|
|
63
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
64
|
+
|
|
65
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
66
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
67
|
+
subsequently incorporated within the Work.
|
|
68
|
+
|
|
69
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
70
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
71
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
72
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
73
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
74
|
+
Work and such Derivative Works in Source or Object form.
|
|
75
|
+
|
|
76
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
77
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
78
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
79
|
+
(except as stated in this section) patent license to make, have made,
|
|
80
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
81
|
+
where such license applies only to those patent claims licensable
|
|
82
|
+
by such Contributor that are necessarily infringed by their
|
|
83
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
84
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
85
|
+
institute patent litigation against any entity (including a
|
|
86
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
87
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
88
|
+
or contributory patent infringement, then any patent licenses
|
|
89
|
+
granted to You under this License for that Work shall terminate
|
|
90
|
+
as of the date such litigation is filed.
|
|
91
|
+
|
|
92
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
93
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
94
|
+
modifications, and in Source or Object form, provided that You
|
|
95
|
+
meet the following conditions:
|
|
96
|
+
|
|
97
|
+
(a) You must give any other recipients of the Work or
|
|
98
|
+
Derivative Works a copy of this License; and
|
|
99
|
+
|
|
100
|
+
(b) You must cause any modified files to carry prominent notices
|
|
101
|
+
stating that You changed the files; and
|
|
102
|
+
|
|
103
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
104
|
+
that You distribute, all copyright, patent, trademark, and
|
|
105
|
+
attribution notices from the Source form of the Work,
|
|
106
|
+
excluding those notices that do not pertain to any part of
|
|
107
|
+
the Derivative Works; and
|
|
108
|
+
|
|
109
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
110
|
+
distribution, then any Derivative Works that You distribute must
|
|
111
|
+
include a readable copy of the attribution notices contained
|
|
112
|
+
within such NOTICE file, excluding those notices that do not
|
|
113
|
+
pertain to any part of the Derivative Works, in at least one
|
|
114
|
+
of the following places: within a NOTICE text file distributed
|
|
115
|
+
as part of the Derivative Works; within the Source form or
|
|
116
|
+
documentation, if provided along with the Derivative Works; or,
|
|
117
|
+
within a display generated by the Derivative Works, if and
|
|
118
|
+
wherever such third-party notices normally appear. The contents
|
|
119
|
+
of the NOTICE file are for informational purposes only and
|
|
120
|
+
do not modify the License. You may add Your own attribution
|
|
121
|
+
notices within Derivative Works that You distribute, alongside
|
|
122
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
123
|
+
that such additional attribution notices cannot be construed
|
|
124
|
+
as modifying the License.
|
|
125
|
+
|
|
126
|
+
You may add Your own copyright statement to Your modifications and
|
|
127
|
+
may provide additional or different license terms and conditions
|
|
128
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
129
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
130
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
131
|
+
the conditions stated in this License.
|
|
132
|
+
|
|
133
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
134
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
135
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
136
|
+
this License, without any additional terms or conditions.
|
|
137
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
138
|
+
the terms of any separate license agreement you may have executed
|
|
139
|
+
with Licensor regarding such Contributions.
|
|
140
|
+
|
|
141
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
142
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
143
|
+
except as required for reasonable and customary use in describing the
|
|
144
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
145
|
+
|
|
146
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
147
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
148
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
149
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
150
|
+
implied, including, without limitation, any warranties or conditions
|
|
151
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
152
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
153
|
+
appropriateness of using or redistributing the Work and assume any
|
|
154
|
+
risks associated with Your exercise of permissions under this License.
|
|
155
|
+
|
|
156
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
157
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
158
|
+
unless required by applicable law (such as deliberate and grossly
|
|
159
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
160
|
+
liable to You for damages, including any direct, indirect, special,
|
|
161
|
+
incidental, or consequential damages of any character arising as a
|
|
162
|
+
result of this License or out of the use or inability to use the
|
|
163
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
164
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
165
|
+
other commercial damages or losses), even if such Contributor
|
|
166
|
+
has been advised of the possibility of such damages.
|
|
167
|
+
|
|
168
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
169
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
170
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
171
|
+
or other liability obligations and/or rights consistent with this
|
|
172
|
+
License. However, in accepting such obligations, You may act only
|
|
173
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
174
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
175
|
+
defend, and hold each Contributor harmless for any liability
|
|
176
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
177
|
+
of your accepting any such warranty or additional liability.
|
|
178
|
+
|
|
179
|
+
END OF TERMS AND CONDITIONS
|
|
180
|
+
|
|
181
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
182
|
+
|
|
183
|
+
To apply the Apache License to your work, attach the following
|
|
184
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
185
|
+
replaced with your own identifying information. (Don't include
|
|
186
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
187
|
+
comment syntax for the file format. We also recommend that a
|
|
188
|
+
file or class name and description of purpose be included on the
|
|
189
|
+
same "printed page" as the copyright notice for easier
|
|
190
|
+
identification within third-party archives.
|
|
191
|
+
|
|
192
|
+
Copyright [yyyy] [name of copyright owner]
|
|
193
|
+
|
|
194
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
195
|
+
you may not use this file except in compliance with the License.
|
|
196
|
+
You may obtain a copy of the License at
|
|
197
|
+
|
|
198
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
199
|
+
|
|
200
|
+
Unless required by applicable law or agreed to in writing, software
|
|
201
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
202
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
203
|
+
See the License for the specific language governing permissions and
|
|
204
|
+
limitations under the License.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Dispatch, Dispatch as default, DispatchConfig, type DispatchDecision } from "./service.js";
|
|
2
|
+
export type { DeviceShare, DispatchInput, DispatchState, DispatchView, SharedDevice } from "./queue.js";
|
|
3
|
+
export { AcceptPolicy, CEILINGS, IDLE_SECONDS, POLICY_DEFAULTS, admit, levelOf, modeWithin, published, type Admission, type Ceiling, type DispatchRequest, type MachineState, type Refusal } from "./policy.js";
|
|
4
|
+
export { PLATFORM_LABELS, deviceLabel, match, unfit, type Match, type MatchDevice, type MatchTicket, type Unfit } from "./match.js";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/match.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { type Ceiling } from "@tomradex/roles/permission";
|
|
2
|
+
/** A role, as much as matching reads of it: the agents it names, the most it lets them do, and what it asks of a machine. */
|
|
3
|
+
export interface MatchRole {
|
|
4
|
+
engines: readonly string[];
|
|
5
|
+
permission: Ceiling | null;
|
|
6
|
+
needs: {
|
|
7
|
+
platform?: string;
|
|
8
|
+
device?: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/** A machine of the account, as much as matching reads of it. */
|
|
12
|
+
export interface MatchDevice {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
self: boolean;
|
|
16
|
+
online: boolean;
|
|
17
|
+
platform: string;
|
|
18
|
+
agents: {
|
|
19
|
+
id: string;
|
|
20
|
+
ready: boolean;
|
|
21
|
+
}[];
|
|
22
|
+
repos: string[];
|
|
23
|
+
accept?: {
|
|
24
|
+
on: boolean;
|
|
25
|
+
projects: "all" | string[];
|
|
26
|
+
concurrent: number;
|
|
27
|
+
ceiling?: Ceiling;
|
|
28
|
+
};
|
|
29
|
+
/** What it works on now, as it last said. */
|
|
30
|
+
sessions: unknown[];
|
|
31
|
+
}
|
|
32
|
+
/** A ticket, as much as matching reads of it. */
|
|
33
|
+
export interface MatchTicket {
|
|
34
|
+
projectId: string;
|
|
35
|
+
labels: string[];
|
|
36
|
+
/** The repository its workstream stands for, when it has one. */
|
|
37
|
+
remote?: string | null;
|
|
38
|
+
/** The role it is to be worked as, when one is named: a machine must have one of its agents and allow what it allows. */
|
|
39
|
+
role?: MatchRole | null;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Why a machine cannot be sent a ticket at all, or not right now. `role-agent`: none of the role's agents is ready
|
|
43
|
+
* there. `role-limit`: it lets a session from another machine do less than the role allows.
|
|
44
|
+
*/
|
|
45
|
+
export type Unfit = "excluded" | "not-accepting" | "project" | "no-agent" | "role-agent" | "role-limit" | "offline" | "busy";
|
|
46
|
+
/**
|
|
47
|
+
* Where a ticket should run.
|
|
48
|
+
* - `here`: on this machine — nothing says otherwise, or this machine is what its label asks for.
|
|
49
|
+
* - `send`: on another machine that can take it now. `clone`: it has no checkout of the repository yet.
|
|
50
|
+
* - `wait`: the right machine is off or full: sent, it waits there.
|
|
51
|
+
* - `none`: its label asks for a machine nobody has, or one that cannot take it: it stays here, with why.
|
|
52
|
+
*/
|
|
53
|
+
export type Match = {
|
|
54
|
+
kind: "here";
|
|
55
|
+
by: "none" | "label";
|
|
56
|
+
} | {
|
|
57
|
+
kind: "send";
|
|
58
|
+
device: string;
|
|
59
|
+
name: string;
|
|
60
|
+
by: "label" | "model";
|
|
61
|
+
clone: boolean;
|
|
62
|
+
} | {
|
|
63
|
+
kind: "wait";
|
|
64
|
+
device: string;
|
|
65
|
+
name: string;
|
|
66
|
+
by: "label";
|
|
67
|
+
why: "offline" | "busy";
|
|
68
|
+
} | {
|
|
69
|
+
kind: "none";
|
|
70
|
+
by: "label";
|
|
71
|
+
wanted: string;
|
|
72
|
+
why: Unfit | "nobody";
|
|
73
|
+
name?: string;
|
|
74
|
+
};
|
|
75
|
+
/** The label that says a ticket runs on any machine of a platform. */
|
|
76
|
+
export declare const PLATFORM_LABELS: Record<string, string>;
|
|
77
|
+
/** The label that names one machine for a ticket. */
|
|
78
|
+
export declare const deviceLabel: (name: string) => string;
|
|
79
|
+
/** Why a machine cannot take a ticket of this project, hard reasons first; null when it can, now. */
|
|
80
|
+
export declare function unfit(device: MatchDevice, projectId: string, excluded?: readonly string[], role?: MatchRole | null): Unfit | null;
|
|
81
|
+
/**
|
|
82
|
+
* Where a ticket should run, by rules alone: its labels (`device:<name>`, or a platform's), which machines accept
|
|
83
|
+
* work for its project, have a ready agent, are on and have room, and which have its repository. `excluded`: machines
|
|
84
|
+
* the project's rules keep work away from. `model`: a machine a model would pick — heard only when no label speaks,
|
|
85
|
+
* and only for a machine the rules allow.
|
|
86
|
+
*/
|
|
87
|
+
export declare function match(ticket: MatchTicket, devices: readonly MatchDevice[], opts?: {
|
|
88
|
+
excluded?: readonly string[];
|
|
89
|
+
model?: string | null;
|
|
90
|
+
}): Match;
|
|
91
|
+
//# sourceMappingURL=match.d.ts.map
|
package/dist/policy.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { CEILINGS, levelOf, modeWithin, type Ceiling } from "@tomradex/roles";
|
|
3
|
+
export { CEILINGS, levelOf, modeWithin, type Ceiling };
|
|
4
|
+
/** What this machine takes from the account's other machines. Off until the person says so. */
|
|
5
|
+
export declare const AcceptPolicy: z.ZodObject<{
|
|
6
|
+
accept: z.ZodDefault<z.ZodBoolean>;
|
|
7
|
+
allProjects: z.ZodDefault<z.ZodBoolean>;
|
|
8
|
+
projects: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
9
|
+
ceiling: z.ZodDefault<z.ZodEnum<{
|
|
10
|
+
read: "read";
|
|
11
|
+
ask: "ask";
|
|
12
|
+
edits: "edits";
|
|
13
|
+
full: "full";
|
|
14
|
+
}>>;
|
|
15
|
+
maxConcurrent: z.ZodDefault<z.ZodNumber>;
|
|
16
|
+
onlyWhenIdle: z.ZodDefault<z.ZodBoolean>;
|
|
17
|
+
onlyOnPower: z.ZodDefault<z.ZodBoolean>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
export type AcceptPolicy = z.infer<typeof AcceptPolicy>;
|
|
20
|
+
export declare const POLICY_DEFAULTS: AcceptPolicy;
|
|
21
|
+
/** Nobody has touched the machine for this long: it counts as idle. */
|
|
22
|
+
export declare const IDLE_SECONDS = 180;
|
|
23
|
+
/** What another machine asks for. Everything in it is a wish: the limits are this machine's own. */
|
|
24
|
+
export interface DispatchRequest {
|
|
25
|
+
/** The machine that asks. */
|
|
26
|
+
from: string;
|
|
27
|
+
projectId: string;
|
|
28
|
+
/** The ticket, by its key. */
|
|
29
|
+
key: string;
|
|
30
|
+
/** The permission mode it would like; absent leaves the choice to this machine. */
|
|
31
|
+
permissionMode?: string | null;
|
|
32
|
+
/** The most the ticket's role lets a session do, as this machine's own copy of the role says; the lower of it and this machine's limit holds. */
|
|
33
|
+
limit?: Ceiling | null;
|
|
34
|
+
/**
|
|
35
|
+
* The person at this machine said yes to this very request: one from another account, which the machine's owner
|
|
36
|
+
* let in for it alone. The switch that lets the account's own machines send work unasked says nothing of it.
|
|
37
|
+
*/
|
|
38
|
+
byHand?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/** How this machine stands right now. */
|
|
41
|
+
export interface MachineState {
|
|
42
|
+
/** The projects it has. */
|
|
43
|
+
projects: readonly string[];
|
|
44
|
+
/** Sessions it runs for other machines at this moment. */
|
|
45
|
+
running: number;
|
|
46
|
+
idleSeconds: number;
|
|
47
|
+
onBattery: boolean;
|
|
48
|
+
/** The permission modes of the engine that would take the work; null when that is not known yet. */
|
|
49
|
+
modes?: readonly string[] | null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Why a request was turned away. The first seven are this machine's settings and state; `no-agent` and `start`
|
|
53
|
+
* are what the work itself lacked: no coding agent ready here, or a Start that would not go.
|
|
54
|
+
*/
|
|
55
|
+
export type Refusal = "off" | "project-not-allowed" | "project-missing" | "permission" | "busy" | "not-idle" | "on-battery" | "no-agent" | "start";
|
|
56
|
+
export type Admission = {
|
|
57
|
+
ok: true;
|
|
58
|
+
permissionMode: string | null;
|
|
59
|
+
} | {
|
|
60
|
+
ok: false;
|
|
61
|
+
reason: Refusal;
|
|
62
|
+
detail?: string;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Whether this machine takes a request, by its own settings and state alone. A permission mode above the
|
|
66
|
+
* ceiling is refused, not lowered: the machine that asked is told, and can ask for less.
|
|
67
|
+
*/
|
|
68
|
+
export declare function admit(policy: AcceptPolicy, request: DispatchRequest, state: MachineState): Admission;
|
|
69
|
+
/** What the account's other machines read of this policy, to know before asking: never more than this. */
|
|
70
|
+
export declare function published(policy: AcceptPolicy): {
|
|
71
|
+
on: boolean;
|
|
72
|
+
projects: "all" | string[];
|
|
73
|
+
ceiling: Ceiling;
|
|
74
|
+
concurrent: number;
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=policy.d.ts.map
|
package/dist/queue.d.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import type { Context } from "cordis";
|
|
2
|
+
import { type Ceiling } from "@tomradex/roles";
|
|
3
|
+
import type { Admission, DispatchRequest, Refusal } from "./policy.js";
|
|
4
|
+
/** How a request stands. `done`: the session it started is over, however it went; `reason` says when it went badly. */
|
|
5
|
+
export type DispatchState = "queued" | "accepted" | "running" | "done" | "refused" | "cancelled";
|
|
6
|
+
/** A ticket one of the account's machines asked another to work on. */
|
|
7
|
+
export interface DispatchView {
|
|
8
|
+
id: string;
|
|
9
|
+
fromDevice: string;
|
|
10
|
+
/** The machine it is for; null when any machine of `toPlatform` may take it. */
|
|
11
|
+
toDevice: string | null;
|
|
12
|
+
toPlatform: string | null;
|
|
13
|
+
projectId: string;
|
|
14
|
+
key: string;
|
|
15
|
+
title: string;
|
|
16
|
+
/** What the asking machine would like; the taking machine decides. `role`: the project's role to work the ticket as, by its id. */
|
|
17
|
+
wish: {
|
|
18
|
+
engine?: string;
|
|
19
|
+
permissionMode?: string;
|
|
20
|
+
role?: string;
|
|
21
|
+
};
|
|
22
|
+
state: DispatchState;
|
|
23
|
+
/** Refused: a reason code, then what more there is to say (`permission: …`). Done: why it stopped, when it did not finish. */
|
|
24
|
+
reason: string | null;
|
|
25
|
+
/** The machine that took it. */
|
|
26
|
+
claimedBy: string | null;
|
|
27
|
+
createdAt: number;
|
|
28
|
+
updatedAt: number;
|
|
29
|
+
expiresAt: number;
|
|
30
|
+
/** From another account, to a machine its owner shared with that person: their address. Null between an account's own machines. */
|
|
31
|
+
fromEmail: string | null;
|
|
32
|
+
/** It was made to wait for the owner's yes on the machine it is for. */
|
|
33
|
+
needsYes: boolean;
|
|
34
|
+
/** The owner has said yes, or none was needed. */
|
|
35
|
+
approved: boolean;
|
|
36
|
+
/** The most the owner lets that person's tickets do there; null between an account's own machines. */
|
|
37
|
+
ceiling: Ceiling | null;
|
|
38
|
+
}
|
|
39
|
+
/** A machine another person shares with this account, as much as choosing one reads of it. */
|
|
40
|
+
export interface SharedDevice {
|
|
41
|
+
/** What a ticket is sent to. */
|
|
42
|
+
share: string;
|
|
43
|
+
/** Its owner, by the address of their account. */
|
|
44
|
+
owner: string;
|
|
45
|
+
deviceId: string;
|
|
46
|
+
name: string;
|
|
47
|
+
platform: string;
|
|
48
|
+
agents: {
|
|
49
|
+
id: string;
|
|
50
|
+
title: string;
|
|
51
|
+
ready: boolean;
|
|
52
|
+
}[];
|
|
53
|
+
/** Whether it takes work sent to it unasked, and for which projects; null on a machine that does not say. */
|
|
54
|
+
accept: {
|
|
55
|
+
on: boolean;
|
|
56
|
+
projects: "all" | string[];
|
|
57
|
+
ceiling: Ceiling;
|
|
58
|
+
} | null;
|
|
59
|
+
/** The most a ticket of this account's may do there. */
|
|
60
|
+
ceiling: Ceiling;
|
|
61
|
+
/** False: each ticket waits for the owner's yes on that machine. */
|
|
62
|
+
auto: boolean;
|
|
63
|
+
lastSeenAt: number;
|
|
64
|
+
}
|
|
65
|
+
/** A person this machine is shared with. */
|
|
66
|
+
export interface DeviceShare {
|
|
67
|
+
email: string;
|
|
68
|
+
ceiling: Ceiling;
|
|
69
|
+
auto: boolean;
|
|
70
|
+
}
|
|
71
|
+
/** What a machine sends: a ticket, and where it should run. */
|
|
72
|
+
export interface DispatchInput {
|
|
73
|
+
projectId: string;
|
|
74
|
+
itemId: string;
|
|
75
|
+
/** One machine, by its id; or any machine of a platform (`win32`, `darwin`, `linux`); or a machine another person shares, by its share. */
|
|
76
|
+
to?: string;
|
|
77
|
+
platform?: string;
|
|
78
|
+
share?: string;
|
|
79
|
+
engine?: string;
|
|
80
|
+
permissionMode?: string;
|
|
81
|
+
/** The project's role to work the ticket as (a role's id). With no machine or platform named, the role's own requirement names one. */
|
|
82
|
+
role?: string;
|
|
83
|
+
}
|
|
84
|
+
/** What the queue asks of the service that owns this machine's limits. */
|
|
85
|
+
export interface Gate {
|
|
86
|
+
peek(request: DispatchRequest, modes?: readonly string[] | null): Admission;
|
|
87
|
+
admit(request: DispatchRequest, modes?: readonly string[] | null): Admission;
|
|
88
|
+
/** Turned away for a reason beyond the settings: no agent, a Start that would not go. */
|
|
89
|
+
refuse(request: DispatchRequest, reason: Refusal, detail?: string): void;
|
|
90
|
+
began(id: string): void;
|
|
91
|
+
ended(id: string): void;
|
|
92
|
+
changed(): void;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The account's queue of tickets sent between its machines, as this machine takes part in it: it sends and
|
|
96
|
+
* cancels its own, and takes the ones meant for it — by its own limits, starting them as its own Start does.
|
|
97
|
+
*/
|
|
98
|
+
export declare class Queue {
|
|
99
|
+
private readonly home;
|
|
100
|
+
private readonly gate;
|
|
101
|
+
private readonly tickMs;
|
|
102
|
+
private rows;
|
|
103
|
+
/** The requests this machine runs now, each with the session it started. */
|
|
104
|
+
private readonly live;
|
|
105
|
+
/**
|
|
106
|
+
* Requests for any machine of this platform that this one could not take, each with when it last looked: left for
|
|
107
|
+
* another, and looked at again after a while — or at once when this machine's settings change or a ticket it ran is over.
|
|
108
|
+
*/
|
|
109
|
+
private readonly passed;
|
|
110
|
+
private working;
|
|
111
|
+
private again;
|
|
112
|
+
private timer;
|
|
113
|
+
private interval;
|
|
114
|
+
constructor(home: Context, gate: Gate, tickMs: number);
|
|
115
|
+
start(): void;
|
|
116
|
+
stop(): void;
|
|
117
|
+
private get me();
|
|
118
|
+
private cloud;
|
|
119
|
+
private code;
|
|
120
|
+
private items;
|
|
121
|
+
/** The account's recent requests, newest first. */
|
|
122
|
+
list(): DispatchView[];
|
|
123
|
+
private soon;
|
|
124
|
+
/** One look at the queue; a look asked for while one runs follows it. */
|
|
125
|
+
tick(): Promise<void>;
|
|
126
|
+
private call;
|
|
127
|
+
private read;
|
|
128
|
+
private take;
|
|
129
|
+
private look;
|
|
130
|
+
/** A request on offer: taken if this machine's limits allow it and it has what the work needs; otherwise told why, or left for another. */
|
|
131
|
+
private consider;
|
|
132
|
+
/**
|
|
133
|
+
* The agent the asking machine named when it is ready here; otherwise the first of the role's agents that is, in the
|
|
134
|
+
* role's order and no other; with no role naming any, the first that is ready.
|
|
135
|
+
*/
|
|
136
|
+
private engine;
|
|
137
|
+
/** The repository has no checkout here: one is cloned into the Hub's own folder for cloned code. */
|
|
138
|
+
private clone;
|
|
139
|
+
/** A request this machine took: done once its session is over, and found again after a restart. */
|
|
140
|
+
private follow;
|
|
141
|
+
/** Whether a session this machine started for a request is over, by what this machine itself knows: nothing is asked of the account. */
|
|
142
|
+
private ended;
|
|
143
|
+
/** Taken back by the machine that asked: the session it started here is stopped. */
|
|
144
|
+
private halt;
|
|
145
|
+
/** A ticket this machine ran is over: there is room for one it stepped aside from while it was busy. */
|
|
146
|
+
private free;
|
|
147
|
+
/** Asks another machine — one by its id, or any of a platform — to work a ticket. */
|
|
148
|
+
send(input: DispatchInput): Promise<DispatchView>;
|
|
149
|
+
/** Takes a request back; the machine that runs it stops its session when it hears. */
|
|
150
|
+
cancel(id: string): Promise<DispatchView[]>;
|
|
151
|
+
/** Requests from other people for this machine that wait on its owner's yes, oldest first. */
|
|
152
|
+
asks(): DispatchView[];
|
|
153
|
+
/** The owner says yes here: the request is then taken like any other, at once. */
|
|
154
|
+
approve(id: string): Promise<void>;
|
|
155
|
+
/** The owner says no: the person who asked reads that it was turned away. */
|
|
156
|
+
decline(id: string): Promise<void>;
|
|
157
|
+
private ask;
|
|
158
|
+
/** The people this machine is shared with. Empty where nobody is signed in. */
|
|
159
|
+
shares(): Promise<DeviceShare[]>;
|
|
160
|
+
/** Lets one person send tickets to this machine, or changes how far theirs may go and whether each needs a yes. */
|
|
161
|
+
share(input: DeviceShare): Promise<DeviceShare[]>;
|
|
162
|
+
/** Takes a share back. What that person still has going here is cancelled, and the session it runs is stopped. */
|
|
163
|
+
unshare(email: string): Promise<DeviceShare[]>;
|
|
164
|
+
/** The machines other people share with this account. Asked for when someone chooses where a ticket runs: nothing reads it on a timer. */
|
|
165
|
+
shared(): Promise<SharedDevice[]>;
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=queue.d.ts.map
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
throw new Error("@tomradex/dispatch is Tomrade's own code: a full-mode plugin gets the running app's copy, so load the plugin in Tomrade");
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { Context, Service } from "cordis";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { AcceptPolicy, type Admission, type DispatchRequest, type Refusal } from "./policy.js";
|
|
4
|
+
import { Queue, type DeviceShare, type DispatchInput, type DispatchView, type SharedDevice } from "./queue.js";
|
|
5
|
+
/** One request from another machine, and what this machine said to it. */
|
|
6
|
+
export interface DispatchDecision {
|
|
7
|
+
at: number;
|
|
8
|
+
/** The machine that asked. */
|
|
9
|
+
from: string;
|
|
10
|
+
projectId: string;
|
|
11
|
+
key: string;
|
|
12
|
+
accepted: boolean;
|
|
13
|
+
/** Accepted: the permission mode it runs under, when one was settled. */
|
|
14
|
+
permissionMode?: string | null;
|
|
15
|
+
reason?: Refusal;
|
|
16
|
+
detail?: string;
|
|
17
|
+
}
|
|
18
|
+
declare module "cordis" {
|
|
19
|
+
interface Context {
|
|
20
|
+
dispatch: Dispatch;
|
|
21
|
+
}
|
|
22
|
+
interface Events {
|
|
23
|
+
/** This machine took or turned away a request from another of the account's machines. */
|
|
24
|
+
"dispatch/decided"(decision: DispatchDecision): void;
|
|
25
|
+
/** The queue as this machine reads it changed: for main-process observers; the renderer hears dispatch.changed. */
|
|
26
|
+
"dispatch/changed"(): void;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
declare module "@tomradex/ipc" {
|
|
30
|
+
interface Channels {
|
|
31
|
+
/** The requests this machine took or turned away, newest first. */
|
|
32
|
+
"dispatch.decisions": (limit?: number) => DispatchDecision[];
|
|
33
|
+
/** The account's recent tickets sent between its machines, newest first. */
|
|
34
|
+
"dispatch.list": () => DispatchView[];
|
|
35
|
+
/** Asks another machine to work a ticket. */
|
|
36
|
+
"dispatch.send": (input: DispatchInput) => DispatchView;
|
|
37
|
+
/** Takes a sent ticket back; the machine that runs it stops. */
|
|
38
|
+
"dispatch.cancel": (id: string) => DispatchView[];
|
|
39
|
+
/** The people this machine is shared with. */
|
|
40
|
+
"dispatch.shares": () => DeviceShare[];
|
|
41
|
+
/** Shares this machine with one person, or changes their share. */
|
|
42
|
+
"dispatch.share": (input: DeviceShare) => DeviceShare[];
|
|
43
|
+
"dispatch.unshare": (email: string) => DeviceShare[];
|
|
44
|
+
/** The machines other people share with this account. */
|
|
45
|
+
"dispatch.shared": () => SharedDevice[];
|
|
46
|
+
/** Requests from other people for this machine that wait on its owner's yes. */
|
|
47
|
+
"dispatch.asks": () => DispatchView[];
|
|
48
|
+
"dispatch.approve": (id: string) => void;
|
|
49
|
+
"dispatch.decline": (id: string) => void;
|
|
50
|
+
}
|
|
51
|
+
interface Broadcasts {
|
|
52
|
+
"dispatch.changed": () => void;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export declare const DispatchConfig: z.ZodPreprocess<z.ZodObject<{
|
|
56
|
+
logFile: z.ZodOptional<z.ZodString>;
|
|
57
|
+
idleSeconds: z.ZodOptional<z.ZodCustom<() => number, () => number>>;
|
|
58
|
+
onBattery: z.ZodOptional<z.ZodCustom<() => boolean, () => boolean>>;
|
|
59
|
+
tickMs: z.ZodDefault<z.ZodNumber>;
|
|
60
|
+
}, z.core.$strip>>;
|
|
61
|
+
export type DispatchConfig = z.infer<typeof DispatchConfig>;
|
|
62
|
+
/**
|
|
63
|
+
* Whether this machine takes work from the account's other machines. Every request is decided here, by this
|
|
64
|
+
* machine's settings and state, whatever the request says of itself; and every decision is kept, with who asked.
|
|
65
|
+
*/
|
|
66
|
+
export declare class Dispatch extends Service {
|
|
67
|
+
readonly config: DispatchConfig;
|
|
68
|
+
static provide: string;
|
|
69
|
+
static inject: string[];
|
|
70
|
+
static Config: z.ZodPreprocess<z.ZodObject<{
|
|
71
|
+
logFile: z.ZodOptional<z.ZodString>;
|
|
72
|
+
idleSeconds: z.ZodOptional<z.ZodCustom<() => number, () => number>>;
|
|
73
|
+
onBattery: z.ZodOptional<z.ZodCustom<() => boolean, () => boolean>>;
|
|
74
|
+
tickMs: z.ZodDefault<z.ZodNumber>;
|
|
75
|
+
}, z.core.$strip>>;
|
|
76
|
+
private readonly home;
|
|
77
|
+
private decisions;
|
|
78
|
+
/** Sessions this machine runs for other machines right now, by whatever names them. */
|
|
79
|
+
private readonly running;
|
|
80
|
+
/** The account's queue of tickets sent between its machines, as this machine takes part in it. */
|
|
81
|
+
queue: Queue;
|
|
82
|
+
constructor(ctx: Context, config: DispatchConfig);
|
|
83
|
+
[Service.init](): void;
|
|
84
|
+
/** What this machine takes, as its settings say now. Settings that do not read mean nothing is taken. */
|
|
85
|
+
policy(): AcceptPolicy;
|
|
86
|
+
/**
|
|
87
|
+
* Decides one request and keeps the decision. `modes`: the permission modes of the engine that would take the
|
|
88
|
+
* work here, once the caller knows it. Nothing the request says loosens a limit.
|
|
89
|
+
*/
|
|
90
|
+
admit(request: DispatchRequest, modes?: readonly string[] | null): Admission;
|
|
91
|
+
/** What `admit` would say, with nothing kept: for looking before a request is taken. */
|
|
92
|
+
peek(request: DispatchRequest, modes?: readonly string[] | null): Admission;
|
|
93
|
+
private state;
|
|
94
|
+
/** A session taken for another machine began, or is over: what counts against "sessions at once". */
|
|
95
|
+
began(id: string): void;
|
|
96
|
+
ended(id: string): void;
|
|
97
|
+
/** What waits on the person at this machine: requests from people it is shared with that need their yes. */
|
|
98
|
+
notices(): {
|
|
99
|
+
key: string;
|
|
100
|
+
projectId: string;
|
|
101
|
+
text: string;
|
|
102
|
+
}[];
|
|
103
|
+
recent(limit?: number): DispatchDecision[];
|
|
104
|
+
private keep;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=service.d.ts.map
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Context } from "cordis";
|
|
2
|
+
import type { Queue } from "./queue.js";
|
|
3
|
+
/**
|
|
4
|
+
* The account's machines and the queue between them, for an agent: which computers there are and which could take
|
|
5
|
+
* a ticket, sending one with the person's yes, and taking it back. Whether this machine accepts work is not here:
|
|
6
|
+
* that stays the person's own switch.
|
|
7
|
+
*/
|
|
8
|
+
export declare function registerTools(ctx: Context, queue: () => Queue): void;
|
|
9
|
+
//# sourceMappingURL=tools.d.ts.map
|
package/dist/words.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const DISPATCH_WORDS: import("@tomradex/domain").WordBook<{
|
|
2
|
+
readonly sectionTitle: "Work from my other devices";
|
|
3
|
+
readonly sectionDescription: "Whether this computer takes tickets sent from the other computers signed in to your account, and within which limits. Taking one means an agent runs here and changes code here. Off unless you turn it on.";
|
|
4
|
+
readonly acceptTitle: "Accept work from my other devices";
|
|
5
|
+
readonly acceptDescription: "Lets your other computers start an agent on this one.";
|
|
6
|
+
readonly allProjectsTitle: "For every project";
|
|
7
|
+
readonly projectsTitle: "Only these projects";
|
|
8
|
+
readonly ceilingTitle: "Most a sent session may do without asking";
|
|
9
|
+
readonly maxConcurrentTitle: "Sessions at once";
|
|
10
|
+
readonly onlyWhenIdleTitle: "Only while this computer is idle";
|
|
11
|
+
readonly onlyOnPowerTitle: "Only while plugged in";
|
|
12
|
+
readonly askSend: "Send {{key}} “{{title}}” to {{where}}? A coding agent starts on it there, with that computer's own sign-in and within the limits that computer set.";
|
|
13
|
+
readonly anyPlatform: "any {{platform}} computer";
|
|
14
|
+
readonly askYes: "Send";
|
|
15
|
+
readonly askNo: "Don't send";
|
|
16
|
+
readonly askedHere: "{{who}} asks to run {{key}} “{{title}}” on this computer. It waits for your yes.";
|
|
17
|
+
}>;
|
|
18
|
+
//# sourceMappingURL=words.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomradex/dispatch",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.30.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"author": "Haoyuan Tang",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=22"
|
|
8
|
+
},
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"description": "Work from the account's other machines: whether this machine takes it, within which limits, and a record of every request it took or turned away — declarations for full-mode plugins; Tomrade provides the code at run time",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"tomrade",
|
|
16
|
+
"tomrade-plugin",
|
|
17
|
+
"types"
|
|
18
|
+
],
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"default": "./dist/runtime.js"
|
|
24
|
+
},
|
|
25
|
+
"./match": {
|
|
26
|
+
"types": "./dist/match.d.ts",
|
|
27
|
+
"default": "./dist/runtime.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@tomradex/code-link": "0.30.0",
|
|
35
|
+
"@tomradex/contracts": "0.30.0",
|
|
36
|
+
"@tomradex/domain": "0.2.33",
|
|
37
|
+
"@tomradex/hub": "0.30.0",
|
|
38
|
+
"@tomradex/hub-cloud": "0.30.0",
|
|
39
|
+
"@tomradex/ipc": "0.30.0",
|
|
40
|
+
"@tomradex/roles": "0.30.0",
|
|
41
|
+
"@tomradex/settings": "0.30.0",
|
|
42
|
+
"@tomradex/tools": "0.30.0",
|
|
43
|
+
"cordis": "4.0.0-rc.8",
|
|
44
|
+
"zod": "^4.4.3"
|
|
45
|
+
}
|
|
46
|
+
}
|
package/README.md
DELETED