@arona/devtools 0.0.0-stage → 0.0.1-nightly.20261203.1.3
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 +69 -2
- package/bin/devtools.js +7 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.js +12 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +460 -0
- package/dist/node.d.ts +32 -0
- package/dist/node.js +50 -0
- package/dist/rolldown-runtime-D8jQpDG7.js +12 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +1 -0
- package/package.json +61 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 Djobbo Maïga
|
|
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,70 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @arona/devtools
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Development transport and control host for Arona.
|
|
4
|
+
|
|
5
|
+
## Run a bot with DevTools
|
|
6
|
+
|
|
7
|
+
Add the DevTools plugin beside the Arona plugin, then run the usual watch
|
|
8
|
+
build. It starts the server, sets `ARONA_DEVTOOLS_URL` for the bot, and stops
|
|
9
|
+
the server with the watcher:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import Arona from "@arona/core/vite";
|
|
13
|
+
import { DevToolsVite } from "@arona/devtools/node";
|
|
14
|
+
import { defineConfig } from "vite-plus";
|
|
15
|
+
|
|
16
|
+
export default defineConfig({
|
|
17
|
+
plugins: [Arona.plugin({ entry: "./src/index.ts" }), DevToolsVite.plugin({ dispatch: true })],
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
vp build --watch --mode development
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`DevToolsVite.plugin` mirrors `DevToolsVite.plugin` from
|
|
26
|
+
`@effect/ui-devtools/node`: it accepts the `DevToolsServer` options (`port`,
|
|
27
|
+
`size`, `keep`, `dispatch`, `fields`), keeps the server in a scoped fiber, and
|
|
28
|
+
warns instead of failing when the port is taken.
|
|
29
|
+
|
|
30
|
+
The bot entry must provide the layer:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { layerFromEnv } from "@arona/devtools";
|
|
34
|
+
import { Effect, Layer } from "effect";
|
|
35
|
+
|
|
36
|
+
program.pipe(Effect.provide(Layer.merge(appLayer, layerFromEnv())));
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`layerFromEnv` is `Layer.empty` unless `NODE_ENV=development` and
|
|
40
|
+
`ARONA_DEVTOOLS_URL` is set. `Controllables` has a disabled default, so a
|
|
41
|
+
production bot registers no DevTools roots.
|
|
42
|
+
|
|
43
|
+
## Time travel and dispatch
|
|
44
|
+
|
|
45
|
+
Pause and time travel send `Show`/`Resume` to the app's control host through
|
|
46
|
+
the DevTools server's `/rpc` route. When a mount passes an application `layer`
|
|
47
|
+
that needs services, also pass a self-contained `paintLayer`; paint runs
|
|
48
|
+
outside the mount and cannot supply application requirements.
|
|
49
|
+
|
|
50
|
+
The host builds the recorded state at that entry, including query results from
|
|
51
|
+
`QueryChanged`, and asks the platform target to paint it; Discord and Slack
|
|
52
|
+
both edit the real message. Controls in the painted copy render disabled, so a
|
|
53
|
+
preview button cannot route to the live root. While paused, live snapshots are
|
|
54
|
+
held and platform interactions are dropped, so the shown message cannot move
|
|
55
|
+
under you. `Resume` repaints the live tree even when no live edit arrived while
|
|
56
|
+
paused.
|
|
57
|
+
|
|
58
|
+
Dispatch runs the app's real `update` and Commands, so it is enabled only by
|
|
59
|
+
`arona-devtools serve` and `DevToolsVite.plugin` (which start the server
|
|
60
|
+
with dispatch on), and the
|
|
61
|
+
server listens on loopback only.
|
|
62
|
+
|
|
63
|
+
## Server only
|
|
64
|
+
|
|
65
|
+
```sh
|
|
66
|
+
arona-devtools serve --port 4774
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The server serves the web inspector and MCP endpoint once the local
|
|
70
|
+
`@effect/ui-devtools` viewer is built.
|
package/bin/devtools.js
ADDED
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Effect, Layer } from "effect";
|
|
2
|
+
import { DevToolsServer } from "@effect/ui-devtools/node";
|
|
3
|
+
import { Command, Flag } from "effect/cli";
|
|
4
|
+
// src/cli/index.ts
|
|
5
|
+
const port = Flag.Int("port").pipe(Flag.withDefault(4774), Flag.withDescription("Port for the DevTools server."));
|
|
6
|
+
const serve = Command.make("serve", { port }, ({ port }) => Layer.build(DevToolsServer.layer({
|
|
7
|
+
port,
|
|
8
|
+
dispatch: true
|
|
9
|
+
})).pipe(Effect.andThen(Effect.logInfo("Arona DevTools: " + DevToolsServer.url({ port }))), Effect.andThen(Effect.logInfo("Arona DevTools MCP: " + DevToolsServer.url({ port }) + "/mcp")), Effect.andThen(Effect.never), Effect.scoped)).pipe(Command.withDescription("Run the DevTools server."));
|
|
10
|
+
/** The `arona-devtools` command. */
|
|
11
|
+
const main = Effect.suspend(() => Command.runWith(Command.make("arona-devtools").pipe(Command.withDescription("Inspect an Arona bot in development."), Command.withSubcommands([serve])), { version: "0.0.0-dev" })(process.argv.slice(2)));
|
|
12
|
+
export { main };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Layer } from "effect";
|
|
2
|
+
import * as MessageLog from "effect/ui/MessageLog";
|
|
3
|
+
/** Where to send a bot's MessageLog. */
|
|
4
|
+
interface Options {
|
|
5
|
+
/** The DevTools server, `http://127.0.0.1:4774` by default. */
|
|
6
|
+
readonly server?: string | undefined;
|
|
7
|
+
/** The host a session reports, `"server"` for an Arona bot. */
|
|
8
|
+
readonly host?: MessageLog.WireHost | undefined;
|
|
9
|
+
/** The entries kept for replay, 1,000 by default. */
|
|
10
|
+
readonly size?: number | undefined;
|
|
11
|
+
/** The largest Model or message sent, in bytes. */
|
|
12
|
+
readonly maxEntryBytes?: number | undefined;
|
|
13
|
+
}
|
|
14
|
+
/** Streams a bot's MessageLog to a DevTools server and controls its roots. */
|
|
15
|
+
export declare const layer: (options?: Options) => Layer.Layer<never>;
|
|
16
|
+
/**
|
|
17
|
+
* `layer` when `NODE_ENV` is `development` and `ARONA_DEVTOOLS_URL` is set.
|
|
18
|
+
*
|
|
19
|
+
* Production and tests get `Layer.empty`: `Controllables` has a disabled
|
|
20
|
+
* default, so the log and the control registry stay no-ops.
|
|
21
|
+
*/
|
|
22
|
+
export declare const layerFromEnv: (env?: NodeJS.ProcessEnv) => Layer.Layer<never>;
|
|
23
|
+
export type { Options };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
import * as DevToolsHeadless from "@effect/ui-devtools/DevToolsHeadless";
|
|
2
|
+
import { Clock, Duration, Effect, Layer, Match, Option, Predicate, PubSub, Record, Schedule, Schema, Stream } from "effect";
|
|
3
|
+
import { Controllables, Dispatched } from "@arona/core";
|
|
4
|
+
import * as Control from "@effect/ui-devtools/Control";
|
|
5
|
+
import * as Watch from "@effect/ui-devtools/Watch";
|
|
6
|
+
import * as Socket from "effect/socket/Socket";
|
|
7
|
+
import * as MessageLog from "effect/ui/MessageLog";
|
|
8
|
+
// src/schema.ts
|
|
9
|
+
const isObject = Schema.is(Schema.JsonObject);
|
|
10
|
+
const resolve = (schema, definitions) => isObject(schema) && typeof schema.$ref === "string" ? definitions[schema.$ref.slice(schema.$ref.lastIndexOf("/") + 1).replaceAll("~1", "/").replaceAll("~0", "~")] : schema;
|
|
11
|
+
const literalOf = (schema) => isObject(schema) ? schema.const ?? (Array.isArray(schema.enum) && schema.enum.length === 1 ? schema.enum[0] : void 0) : void 0;
|
|
12
|
+
const tagOf = (schema, definitions) => {
|
|
13
|
+
const resolved = resolve(schema, definitions);
|
|
14
|
+
return isObject(resolved) && isObject(resolved.properties) ? literalOf(resolved.properties._tag) : void 0;
|
|
15
|
+
};
|
|
16
|
+
const most = 64;
|
|
17
|
+
const holdsPlaceholder = (value) => Predicate.isObjectOrArray(value) && (isObject(value) && Object.keys(value).length === 1 && value["~redacted"] === true || Object.values(value).some(holdsPlaceholder));
|
|
18
|
+
const isPlaceholderSchema = (schema) => isObject(schema) && isObject(schema.properties) && Object.keys(schema.properties).length === 1 && literalOf(schema.properties["~redacted"]) === true;
|
|
19
|
+
/**
|
|
20
|
+
* Builds a candidate, not a validated payload. Prefers the first usable union
|
|
21
|
+
* member and nonempty arrays; recursive references may fall back to [] or None.
|
|
22
|
+
* In redacting mode, rejects annotations that could expose redacted values.
|
|
23
|
+
*/
|
|
24
|
+
const exampleOf = (root, definitions, redacting = false) => {
|
|
25
|
+
const open = /* @__PURE__ */ new Set();
|
|
26
|
+
let unmasked = false;
|
|
27
|
+
const masks = (node, seen) => {
|
|
28
|
+
const schema = resolve(node, definitions);
|
|
29
|
+
if (typeof schema !== "object" || schema === null || seen.has(schema)) return false;
|
|
30
|
+
seen.add(schema);
|
|
31
|
+
return isPlaceholderSchema(schema) || Object.values(schema).some((child) => masks(child, seen));
|
|
32
|
+
};
|
|
33
|
+
const walk = (schema) => {
|
|
34
|
+
if (!isObject(schema)) return void 0;
|
|
35
|
+
if (typeof schema.$ref === "string") {
|
|
36
|
+
const target = resolve(schema, definitions);
|
|
37
|
+
if (open.has(schema.$ref) || target === void 0) return void 0;
|
|
38
|
+
open.add(schema.$ref);
|
|
39
|
+
const out = walk(target);
|
|
40
|
+
open.delete(schema.$ref);
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
if ("const" in schema) return schema.const;
|
|
44
|
+
if (Array.isArray(schema.enum)) return schema.enum[0];
|
|
45
|
+
const examples = Array.isArray(schema.examples) ? schema.examples : void 0;
|
|
46
|
+
const annotated = examples !== void 0 && examples.length > 0;
|
|
47
|
+
if (annotated || "default" in schema) {
|
|
48
|
+
if (redacting && masks(schema, /* @__PURE__ */ new Set())) unmasked = true;
|
|
49
|
+
return annotated ? examples[0] : schema.default;
|
|
50
|
+
}
|
|
51
|
+
const members = schema.anyOf ?? schema.oneOf;
|
|
52
|
+
if (Array.isArray(members)) {
|
|
53
|
+
for (const member of members) {
|
|
54
|
+
const out = walk(member);
|
|
55
|
+
if (out !== void 0) return out;
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const allOf = schema.allOf;
|
|
60
|
+
if (Array.isArray(allOf)) {
|
|
61
|
+
const { allOf: _, ...rest } = schema;
|
|
62
|
+
return walk(Object.assign(rest, ...allOf));
|
|
63
|
+
}
|
|
64
|
+
if (isObject(schema.not)) return void 0;
|
|
65
|
+
const number = (key) => typeof schema[key] === "number" ? schema[key] : void 0;
|
|
66
|
+
switch (schema.type) {
|
|
67
|
+
case "string": return "a".repeat(Math.min(number("minLength") ?? 0, most));
|
|
68
|
+
case "number":
|
|
69
|
+
case "integer": {
|
|
70
|
+
let out = Math.max(0, number("minimum") ?? -Infinity);
|
|
71
|
+
const above = number("exclusiveMinimum");
|
|
72
|
+
if (above !== void 0 && out <= above) out = above + 1;
|
|
73
|
+
out = Math.min(out, number("maximum") ?? Infinity);
|
|
74
|
+
const below = number("exclusiveMaximum");
|
|
75
|
+
if (below !== void 0 && out >= below) out = below - 1;
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
case "boolean": return false;
|
|
79
|
+
case "array": {
|
|
80
|
+
const out = [];
|
|
81
|
+
for (const item of Array.isArray(schema.prefixItems) ? schema.prefixItems : []) {
|
|
82
|
+
const value = walk(item);
|
|
83
|
+
if (value === void 0) return void 0;
|
|
84
|
+
out.push(value);
|
|
85
|
+
}
|
|
86
|
+
const minItems = number("minItems") ?? 0;
|
|
87
|
+
const length = Math.min(Math.max(out.length + 1, minItems), number("maxItems") ?? Infinity, out.length + most);
|
|
88
|
+
if (out.length < length) {
|
|
89
|
+
const value = walk(schema.items ?? {});
|
|
90
|
+
if (value === void 0) return out.length < minItems ? void 0 : out;
|
|
91
|
+
while (out.length < length) out.push(value);
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
case "object": {
|
|
96
|
+
const out = {};
|
|
97
|
+
const required = Array.isArray(schema.required) ? schema.required : [];
|
|
98
|
+
const properties = isObject(schema.properties) ? schema.properties : {};
|
|
99
|
+
for (const key of Object.keys(properties)) {
|
|
100
|
+
const value = walk(properties[key]);
|
|
101
|
+
if (value !== void 0) out[key] = value;
|
|
102
|
+
else if (required.includes(key)) return void 0;
|
|
103
|
+
}
|
|
104
|
+
if (Object.keys(properties).length === 0 && isObject(schema.additionalProperties)) {
|
|
105
|
+
const value = walk(schema.additionalProperties);
|
|
106
|
+
if (value !== void 0) out.key = value;
|
|
107
|
+
}
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
default: return null;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const out = walk(root);
|
|
114
|
+
return unmasked ? void 0 : out;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* The JSON codec `dispatch` decodes with.
|
|
118
|
+
*
|
|
119
|
+
* The assertion only erases `Schema.Top`'s service channel. A JSON codec
|
|
120
|
+
* decodes and encodes without services, and this stays the single place that
|
|
121
|
+
* depends on that erasure.
|
|
122
|
+
*/
|
|
123
|
+
const codecOf = (schema) => Schema.toCodecJson(schema);
|
|
124
|
+
/** The JSON Schema document for a message Schema. */
|
|
125
|
+
const documentOf = (schema) => {
|
|
126
|
+
const document = Schema.toJsonSchemaDocument(Schema.toCodecJson(schema));
|
|
127
|
+
return {
|
|
128
|
+
schema: Schema.decodeUnknownSync(Schema.Json)(document.schema),
|
|
129
|
+
definitions: Record.map(document.definitions, (definition) => Schema.decodeUnknownSync(Schema.Json)(definition))
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
/** The union members of a Schema, or the schema itself when it is not a union. */
|
|
133
|
+
const membersOf = (document) => {
|
|
134
|
+
const root = resolve(document.schema, document.definitions);
|
|
135
|
+
return isObject(root) && Array.isArray(root.anyOf) ? root.anyOf : [document.schema];
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Builds the dispatch schema and a candidate example per message `_tag`,
|
|
139
|
+
* validating each with the same decoder that `Dispatch` uses.
|
|
140
|
+
*/
|
|
141
|
+
const messageSchema = (schema, tag) => Effect.suspend(() => {
|
|
142
|
+
const document = documentOf(schema);
|
|
143
|
+
const members = membersOf(document);
|
|
144
|
+
const tags = members.map((member) => tagOf(member, document.definitions));
|
|
145
|
+
const index = tag === void 0 ? -1 : tags.indexOf(tag);
|
|
146
|
+
if (tag !== void 0 && index === -1) return Effect.fail("No message _tag " + tag + ". The tags are " + tags.filter((candidate) => typeof candidate === "string").join(", ") + ".");
|
|
147
|
+
const decode = Schema.decodeUnknownEffect(codecOf(schema));
|
|
148
|
+
const redactedSchema = MessageLog.redactSchema(schema);
|
|
149
|
+
const encodeRedacted = redactedSchema === schema ? void 0 : Schema.encodeUnknownEffect(codecOf(redactedSchema));
|
|
150
|
+
let redacted;
|
|
151
|
+
const example = (i) => {
|
|
152
|
+
const name = tags[i];
|
|
153
|
+
const none = (invalid) => ({
|
|
154
|
+
...typeof name === "string" ? { tag: name } : {},
|
|
155
|
+
invalid
|
|
156
|
+
});
|
|
157
|
+
const candidate = exampleOf(members[i], document.definitions);
|
|
158
|
+
if (candidate === void 0) return Effect.succeed(none("No value fits this schema."));
|
|
159
|
+
const message = Schema.decodeSync(Schema.fromJsonString(Schema.Json))(JSON.stringify(candidate));
|
|
160
|
+
const tagged = typeof name === "string" ? { tag: name } : {};
|
|
161
|
+
const entry = (shown, status) => {
|
|
162
|
+
if (shown === void 0) return none("No safe example: a Schema.Redacted's value here comes from an example or default that can't be redacted.");
|
|
163
|
+
if (holdsPlaceholder(shown)) {
|
|
164
|
+
const encoded = Schema.decodeUnknownOption(Schema.Json)(shown);
|
|
165
|
+
return Option.isSome(encoded) ? {
|
|
166
|
+
...tagged,
|
|
167
|
+
message: encoded.value,
|
|
168
|
+
redacted: true,
|
|
169
|
+
...status
|
|
170
|
+
} : none("No JSON example for a redacted value.");
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
...tagged,
|
|
174
|
+
message,
|
|
175
|
+
...status
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
const walked = (status) => {
|
|
179
|
+
if (encodeRedacted === void 0) return {
|
|
180
|
+
message,
|
|
181
|
+
...status
|
|
182
|
+
};
|
|
183
|
+
redacted ??= documentOf(redactedSchema);
|
|
184
|
+
return entry(exampleOf(membersOf(redacted)[i], redacted.definitions, true), status);
|
|
185
|
+
};
|
|
186
|
+
return decode(message, { errors: "all" }).pipe(Effect.matchEffect({
|
|
187
|
+
onFailure: (error) => Effect.succeed(walked({ invalid: error.message })),
|
|
188
|
+
onSuccess: (value) => encodeRedacted === void 0 ? Effect.succeed({
|
|
189
|
+
...tagged,
|
|
190
|
+
message
|
|
191
|
+
}) : Effect.match(encodeRedacted(value), {
|
|
192
|
+
onFailure: () => walked(),
|
|
193
|
+
onSuccess: (shown) => entry(shown)
|
|
194
|
+
})
|
|
195
|
+
}));
|
|
196
|
+
};
|
|
197
|
+
return Effect.map(Effect.forEach(tag === void 0 ? members.map((_, i) => i) : [index], example), (examples) => ({
|
|
198
|
+
schema: tag === void 0 ? document.schema : members[index],
|
|
199
|
+
definitions: document.definitions,
|
|
200
|
+
examples
|
|
201
|
+
}));
|
|
202
|
+
});
|
|
203
|
+
// src/control.ts
|
|
204
|
+
/** A control request could not be answered on this host. */
|
|
205
|
+
var ControlError = class extends Schema.TaggedError()("ControlError", { message: Schema.String }) {};
|
|
206
|
+
const [UpdatedOutcome, FailedOutcome, IgnoredOutcome, UnknownOutcome] = Control.Outcome.members;
|
|
207
|
+
const [StateMessage, ReplyMessage] = Control.ToServer.members;
|
|
208
|
+
const outcomeOf = (outcome) => Dispatched.$match(outcome, {
|
|
209
|
+
Updated: ({ seq }) => UpdatedOutcome.make({ seq }),
|
|
210
|
+
Failed: ({ seq }) => FailedOutcome.make({ seq }),
|
|
211
|
+
Ignored: ({ reason }) => IgnoredOutcome.make({ reason })
|
|
212
|
+
});
|
|
213
|
+
const resultsOf = (value) => {
|
|
214
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
|
|
215
|
+
const results = {};
|
|
216
|
+
for (const [name, result] of Object.entries(value)) results[name] = result;
|
|
217
|
+
return results;
|
|
218
|
+
};
|
|
219
|
+
const stateAt = (session, seq) => {
|
|
220
|
+
const states = /* @__PURE__ */ new Map();
|
|
221
|
+
const place = (entry, inheritQueries) => {
|
|
222
|
+
const prior = states.get(entry.path);
|
|
223
|
+
const inherited = inheritQueries && prior?.instance === entry.instance ? prior.queries : void 0;
|
|
224
|
+
const queries = resultsOf(entry.queries) ?? inherited;
|
|
225
|
+
states.set(entry.path, {
|
|
226
|
+
instance: entry.instance,
|
|
227
|
+
model: entry.model,
|
|
228
|
+
props: entry.props,
|
|
229
|
+
...queries === void 0 ? {} : { queries }
|
|
230
|
+
});
|
|
231
|
+
};
|
|
232
|
+
const applyEntry = Match.type().pipe(Match.tags({
|
|
233
|
+
Waiting: (entry) => {
|
|
234
|
+
place(entry, false);
|
|
235
|
+
},
|
|
236
|
+
Mounted: (entry) => {
|
|
237
|
+
place(entry, false);
|
|
238
|
+
},
|
|
239
|
+
Update: (entry) => {
|
|
240
|
+
place(entry, true);
|
|
241
|
+
},
|
|
242
|
+
PropsChanged: (entry) => {
|
|
243
|
+
const prior = states.get(entry.path);
|
|
244
|
+
if (prior !== void 0 && prior.instance === entry.instance) states.set(entry.path, {
|
|
245
|
+
...prior,
|
|
246
|
+
props: entry.props
|
|
247
|
+
});
|
|
248
|
+
},
|
|
249
|
+
QueryChanged: (entry) => {
|
|
250
|
+
const prior = states.get(entry.path);
|
|
251
|
+
if (prior === void 0 || prior.instance !== entry.instance) return;
|
|
252
|
+
states.set(entry.path, {
|
|
253
|
+
...prior,
|
|
254
|
+
queries: {
|
|
255
|
+
...prior.queries,
|
|
256
|
+
[entry.name]: entry.result
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
},
|
|
260
|
+
Unmounted: (entry) => {
|
|
261
|
+
if (states.get(entry.path)?.instance === entry.instance) states.delete(entry.path);
|
|
262
|
+
}
|
|
263
|
+
}), Match.orElse(() => {}));
|
|
264
|
+
for (const entry of session.entries()) {
|
|
265
|
+
if (entry.seq > seq) break;
|
|
266
|
+
if ("excluded" in entry && entry.excluded === true) continue;
|
|
267
|
+
applyEntry(entry);
|
|
268
|
+
}
|
|
269
|
+
return (path) => {
|
|
270
|
+
const found = states.get(path);
|
|
271
|
+
if (found === void 0) return void 0;
|
|
272
|
+
return {
|
|
273
|
+
model: found.model,
|
|
274
|
+
...found.props === void 0 ? {} : { props: found.props },
|
|
275
|
+
...found.queries === void 0 ? {} : { queries: found.queries }
|
|
276
|
+
};
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
const notify = (state) => {
|
|
280
|
+
PubSub.publishUnsafe(state.changes, void 0);
|
|
281
|
+
};
|
|
282
|
+
const paintedJson = (painted) => ({
|
|
283
|
+
fellBack: [...painted.fellBack],
|
|
284
|
+
fallbacks: [...painted.fallbacks],
|
|
285
|
+
skipped: [...painted.skipped]
|
|
286
|
+
});
|
|
287
|
+
const handle = (state, request) => {
|
|
288
|
+
const fail = (message) => Effect.fail(new ControlError({ message }));
|
|
289
|
+
const instanceOf = (session, instance) => {
|
|
290
|
+
const root = state.roots.get(session);
|
|
291
|
+
if (root === void 0) return void 0;
|
|
292
|
+
return {
|
|
293
|
+
root,
|
|
294
|
+
instance: root.instance(instance)
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
return Match.value(request).pipe(Match.tagsExhaustive({
|
|
298
|
+
Show: (request) => Effect.gen(function* () {
|
|
299
|
+
const root = state.roots.get(request.session);
|
|
300
|
+
if (root === void 0) return yield* fail("Session " + request.session + " has no root on this host.");
|
|
301
|
+
if (root.paint === void 0) return yield* fail("This host cannot paint a historical state.");
|
|
302
|
+
const session = state.watch.inspector.sessions().find((known) => known.id === request.session);
|
|
303
|
+
if (session === void 0) return yield* fail("Session " + request.session + " is unknown.");
|
|
304
|
+
if (!session.entries().some((entry) => entry.seq === request.seq)) return yield* fail("#" + request.seq + " is not among the entries this host keeps to paint from.");
|
|
305
|
+
const previous = state.paused();
|
|
306
|
+
if (previous !== void 0 && previous.session !== request.session) state.roots.get(previous.session)?.resume?.();
|
|
307
|
+
root.pause?.();
|
|
308
|
+
const painted = yield* root.paint(stateAt(session, request.seq)).pipe(Effect.mapError((error) => new ControlError({ message: error.message })), Effect.tapError(() => Effect.sync(() => root.resume?.())), Effect.catchCause((cause) => fail(String(cause))));
|
|
309
|
+
state.setPaused({
|
|
310
|
+
session: request.session,
|
|
311
|
+
seq: request.seq,
|
|
312
|
+
painted
|
|
313
|
+
});
|
|
314
|
+
notify(state);
|
|
315
|
+
return paintedJson(painted);
|
|
316
|
+
}),
|
|
317
|
+
Resume: (request) => Effect.gen(function* () {
|
|
318
|
+
const previous = state.paused();
|
|
319
|
+
const session = request.session ?? previous?.session;
|
|
320
|
+
if (previous !== void 0 && previous.session !== session) state.roots.get(previous.session)?.resume?.();
|
|
321
|
+
if (session === void 0) for (const each of state.roots.values()) each.resume?.();
|
|
322
|
+
else {
|
|
323
|
+
const root = state.roots.get(session);
|
|
324
|
+
if (root === void 0) return yield* fail("Session " + session + " has no root on this host.");
|
|
325
|
+
root.resume?.();
|
|
326
|
+
}
|
|
327
|
+
state.setPaused(void 0);
|
|
328
|
+
notify(state);
|
|
329
|
+
return null;
|
|
330
|
+
}),
|
|
331
|
+
SetRecording: () => fail("Recording rules are applied by the app's MessageLog, not by this host."),
|
|
332
|
+
Find: () => fail("Find needs a document; this host renders to a chat platform."),
|
|
333
|
+
MessageSchema: (request) => Effect.gen(function* () {
|
|
334
|
+
const found = instanceOf(request.session, request.instance);
|
|
335
|
+
if (found === void 0) return yield* fail("Session " + request.session + " has no root on this host.");
|
|
336
|
+
if (found.instance === void 0) return yield* fail("Instance " + request.instance + " is not mounted in " + request.session);
|
|
337
|
+
const value = yield* messageSchema(found.instance.message, request.tag).pipe(Effect.mapError((message) => new ControlError({ message })));
|
|
338
|
+
return yield* Schema.decodeUnknownEffect(Schema.Json)(value).pipe(Effect.mapError((error) => new ControlError({ message: error.message })));
|
|
339
|
+
}),
|
|
340
|
+
Dispatch: (request) => Effect.gen(function* () {
|
|
341
|
+
const found = instanceOf(request.session, request.instance);
|
|
342
|
+
if (found === void 0) return yield* fail("Session " + request.session + " has no root on this host.");
|
|
343
|
+
if (found.instance === void 0) return yield* fail("Instance " + request.instance + " is not mounted in " + request.session);
|
|
344
|
+
const decode = Schema.decodeUnknownEffect(codecOf(found.instance.message));
|
|
345
|
+
const messages = yield* Effect.forEach(request.messages, (message, index) => Effect.mapError(decode(message), (error) => new ControlError({ message: "Message " + index + " does not decode: " + error.message })));
|
|
346
|
+
const deadline = (yield* Clock.currentTimeMillis) + request.within;
|
|
347
|
+
const outcomes = [];
|
|
348
|
+
for (const message of messages) {
|
|
349
|
+
const left = deadline - (yield* Clock.currentTimeMillis);
|
|
350
|
+
if (left <= 0) break;
|
|
351
|
+
const outcome = yield* found.instance.dispatch(message).pipe(Effect.map(outcomeOf), Effect.timeoutOrElse({
|
|
352
|
+
duration: Duration.millis(left),
|
|
353
|
+
orElse: () => Effect.succeed(UnknownOutcome.make({}))
|
|
354
|
+
}));
|
|
355
|
+
outcomes.push(outcome);
|
|
356
|
+
if (!Schema.is(UpdatedOutcome)(outcome)) break;
|
|
357
|
+
}
|
|
358
|
+
const paused = state.paused();
|
|
359
|
+
return {
|
|
360
|
+
outcomes,
|
|
361
|
+
paused: paused?.session === request.session ? paused.seq : null
|
|
362
|
+
};
|
|
363
|
+
})
|
|
364
|
+
}));
|
|
365
|
+
};
|
|
366
|
+
const connect = (state) => Effect.gen(function* () {
|
|
367
|
+
const socket = yield* Socket.makeWebSocket(Control.socketUrl(state.server, "/control"));
|
|
368
|
+
const writer = yield* socket.writer;
|
|
369
|
+
const pull = yield* Socket.readerString(socket);
|
|
370
|
+
const sendState = () => {
|
|
371
|
+
const paused = state.paused();
|
|
372
|
+
return writer.write(Control.encodeToServer(StateMessage.make({
|
|
373
|
+
sessions: Array.from(state.roots.keys()),
|
|
374
|
+
paused: paused === void 0 ? null : {
|
|
375
|
+
session: paused.session,
|
|
376
|
+
seq: paused.seq,
|
|
377
|
+
...paintedJson(paused.painted)
|
|
378
|
+
},
|
|
379
|
+
notRecording: [],
|
|
380
|
+
picks: []
|
|
381
|
+
})));
|
|
382
|
+
};
|
|
383
|
+
yield* Stream.fromPubSub(state.changes).pipe(Stream.runForEach(() => sendState()), Effect.forkScoped);
|
|
384
|
+
yield* sendState();
|
|
385
|
+
return yield* Effect.forever(Effect.flatMap(pull, (chunks) => Effect.forEach(chunks, (chunk) => {
|
|
386
|
+
const decoded = Control.decodeToPage(chunk);
|
|
387
|
+
if (Option.isNone(decoded)) return Effect.void;
|
|
388
|
+
const message = decoded.value;
|
|
389
|
+
return handle(state, message.request).pipe(Effect.match({
|
|
390
|
+
onFailure: (error) => ({
|
|
391
|
+
ok: false,
|
|
392
|
+
value: error.message
|
|
393
|
+
}),
|
|
394
|
+
onSuccess: (value) => ({
|
|
395
|
+
ok: true,
|
|
396
|
+
value
|
|
397
|
+
})
|
|
398
|
+
}), Effect.flatMap((reply) => writer.write(Control.encodeToServer(ReplyMessage.make({
|
|
399
|
+
id: message.id,
|
|
400
|
+
...reply
|
|
401
|
+
})))));
|
|
402
|
+
}, { discard: true })));
|
|
403
|
+
}).pipe(Effect.scoped, Effect.provide(Socket.layerWebSocketConstructorGlobal));
|
|
404
|
+
/**
|
|
405
|
+
* Provides `Controllables` for Arona message roots and keeps a `/control`
|
|
406
|
+
* connection to the DevTools server.
|
|
407
|
+
*/
|
|
408
|
+
const layer$1 = (options = {}) => Layer.effect(Controllables, Effect.gen(function* () {
|
|
409
|
+
const server = options.server ?? Control.serverUrl();
|
|
410
|
+
const roots = /* @__PURE__ */ new Map();
|
|
411
|
+
let paused;
|
|
412
|
+
const changes = yield* PubSub.sliding(1);
|
|
413
|
+
const state = {
|
|
414
|
+
server,
|
|
415
|
+
roots,
|
|
416
|
+
watch: yield* Watch.make({
|
|
417
|
+
server,
|
|
418
|
+
...options.size === void 0 ? {} : { size: options.size }
|
|
419
|
+
}),
|
|
420
|
+
changes,
|
|
421
|
+
paused: () => paused,
|
|
422
|
+
setPaused: (value) => {
|
|
423
|
+
paused = value;
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
const controllables = {
|
|
427
|
+
enabled: true,
|
|
428
|
+
register: (root) => {
|
|
429
|
+
roots.set(root.session, root);
|
|
430
|
+
notify(state);
|
|
431
|
+
return () => {
|
|
432
|
+
if (roots.get(root.session) !== root) return;
|
|
433
|
+
roots.delete(root.session);
|
|
434
|
+
if (paused?.session === root.session) paused = void 0;
|
|
435
|
+
notify(state);
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
yield* connect(state).pipe(Effect.retry(Schedule.min([Schedule.exponential("200 millis"), Schedule.spaced("5 seconds")])), Effect.forkScoped);
|
|
440
|
+
return controllables;
|
|
441
|
+
}));
|
|
442
|
+
// src/layer.ts
|
|
443
|
+
/** Streams a bot's MessageLog to a DevTools server and controls its roots. */
|
|
444
|
+
const layer = (options = {}) => Layer.mergeAll(DevToolsHeadless.layer({
|
|
445
|
+
server: options.server,
|
|
446
|
+
host: options.host ?? "server",
|
|
447
|
+
size: options.size,
|
|
448
|
+
maxEntryBytes: options.maxEntryBytes
|
|
449
|
+
}), layer$1({
|
|
450
|
+
server: options.server,
|
|
451
|
+
size: options.size
|
|
452
|
+
}));
|
|
453
|
+
/**
|
|
454
|
+
* `layer` when `NODE_ENV` is `development` and `ARONA_DEVTOOLS_URL` is set.
|
|
455
|
+
*
|
|
456
|
+
* Production and tests get `Layer.empty`: `Controllables` has a disabled
|
|
457
|
+
* default, so the log and the control registry stay no-ops.
|
|
458
|
+
*/
|
|
459
|
+
const layerFromEnv = (env = process.env) => env.NODE_ENV === "development" && env.ARONA_DEVTOOLS_URL !== void 0 ? layer({ server: env.ARONA_DEVTOOLS_URL }) : Layer.empty;
|
|
460
|
+
export { layer, layerFromEnv };
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { DevToolsServer, DevToolsServer as DevToolsServer$1 } from "@effect/ui-devtools/node";
|
|
2
|
+
declare namespace DevToolsVite_d_exports {
|
|
3
|
+
export { Options, Plugin, ViteConfig, plugin };
|
|
4
|
+
}
|
|
5
|
+
/** Server options, mirrored from `DevToolsServer` in `@effect/ui-devtools/node`. */
|
|
6
|
+
interface Options extends DevToolsServer$1.Options {}
|
|
7
|
+
/**
|
|
8
|
+
* The parts of Vite's config the plugin reads, typed without importing `vite`
|
|
9
|
+
* (mirroring `DevToolsVite` in `@effect/ui-devtools/node`).
|
|
10
|
+
*/
|
|
11
|
+
interface ViteConfig {
|
|
12
|
+
readonly build: {
|
|
13
|
+
readonly watch?: unknown;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** The parts of a Vite plugin the plugin returns. */
|
|
17
|
+
interface Plugin {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly configResolved: (config: ViteConfig) => void;
|
|
20
|
+
readonly buildStart: () => void | Promise<void>;
|
|
21
|
+
readonly closeWatcher: () => void | Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Starts the DevTools server beside a watch build and points the bot process
|
|
25
|
+
* at it through `ARONA_DEVTOOLS_URL`.
|
|
26
|
+
*
|
|
27
|
+
* Mirrors `DevToolsVite.plugin` from `@effect/ui-devtools/node`: the server
|
|
28
|
+
* lives in a scoped fiber, stops with the watcher, and a port conflict warns
|
|
29
|
+
* instead of failing the build.
|
|
30
|
+
*/
|
|
31
|
+
declare const plugin: (options?: Options) => Plugin;
|
|
32
|
+
export { DevToolsServer, DevToolsVite_d_exports as DevToolsVite };
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
|
|
2
|
+
import { Cause, Effect, Fiber, Layer } from "effect";
|
|
3
|
+
import { DevToolsServer, DevToolsServer as DevToolsServer$1 } from "@effect/ui-devtools/node";
|
|
4
|
+
// src/node/DevToolsVite.ts
|
|
5
|
+
var DevToolsVite_exports = /* @__PURE__ */ __exportAll({ plugin: () => plugin });
|
|
6
|
+
const reasonOf = (error) => error instanceof Error ? error.message : String(error);
|
|
7
|
+
/**
|
|
8
|
+
* Starts the DevTools server beside a watch build and points the bot process
|
|
9
|
+
* at it through `ARONA_DEVTOOLS_URL`.
|
|
10
|
+
*
|
|
11
|
+
* Mirrors `DevToolsVite.plugin` from `@effect/ui-devtools/node`: the server
|
|
12
|
+
* lives in a scoped fiber, stops with the watcher, and a port conflict warns
|
|
13
|
+
* instead of failing the build.
|
|
14
|
+
*/
|
|
15
|
+
const plugin = (options = {}) => {
|
|
16
|
+
let watching = false;
|
|
17
|
+
let fiber;
|
|
18
|
+
let ready;
|
|
19
|
+
const start = () => {
|
|
20
|
+
const url = DevToolsServer$1.url(options);
|
|
21
|
+
let settle = () => {};
|
|
22
|
+
ready = new Promise((resolve) => {
|
|
23
|
+
settle = resolve;
|
|
24
|
+
});
|
|
25
|
+
fiber = Layer.build(DevToolsServer$1.layer(options)).pipe(Effect.andThen(Effect.sync(() => {
|
|
26
|
+
process.env.ARONA_DEVTOOLS_URL = url;
|
|
27
|
+
settle();
|
|
28
|
+
})), Effect.andThen(Effect.logInfo(`Arona DevTools: ${url}`)), Effect.andThen(Effect.logInfo(`Arona DevTools MCP: ${url}/mcp`)), Effect.andThen(Effect.never), Effect.scoped, Effect.catchCause((cause) => Cause.hasInterruptsOnly(cause) ? Effect.void : Effect.andThen(Effect.sync(settle), Effect.logWarning(`Arona DevTools could not start on ${url}: ${reasonOf(Cause.squash(cause))}. Choose another port.`))), Effect.runFork);
|
|
29
|
+
return ready;
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
name: "arona-devtools",
|
|
33
|
+
configResolved(config) {
|
|
34
|
+
watching = Boolean(config.build.watch);
|
|
35
|
+
},
|
|
36
|
+
buildStart() {
|
|
37
|
+
if (!watching || fiber !== void 0) return;
|
|
38
|
+
return start();
|
|
39
|
+
},
|
|
40
|
+
closeWatcher() {
|
|
41
|
+
const current = fiber;
|
|
42
|
+
fiber = void 0;
|
|
43
|
+
ready = void 0;
|
|
44
|
+
delete process.env.ARONA_DEVTOOLS_URL;
|
|
45
|
+
if (current === void 0) return;
|
|
46
|
+
return Effect.runPromise(Fiber.interrupt(current));
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export { DevToolsServer, DevToolsVite_exports as DevToolsVite };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
export { __exportAll as t };
|
package/dist/server.d.ts
ADDED
package/dist/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DevToolsServer } from "@effect/ui-devtools/node";
|
package/package.json
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arona/devtools",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.1-nightly.20261203.1.3",
|
|
4
|
+
"description": "DevTools transport and control host for Arona",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/djobbo/arona.git"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"arona-devtools": "bin/devtools.js"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"bin"
|
|
16
|
+
],
|
|
17
|
+
"type": "module",
|
|
18
|
+
"module": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./server": {
|
|
26
|
+
"types": "./dist/server.d.ts",
|
|
27
|
+
"import": "./dist/server.js"
|
|
28
|
+
},
|
|
29
|
+
"./cli": {
|
|
30
|
+
"types": "./dist/cli.d.ts",
|
|
31
|
+
"import": "./dist/cli.js"
|
|
32
|
+
},
|
|
33
|
+
"./node": {
|
|
34
|
+
"types": "./dist/node.d.ts",
|
|
35
|
+
"import": "./dist/node.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@arona/core": "0.0.1-nightly.20261203.1.3",
|
|
40
|
+
"@effect/platform-node": "4.2.0",
|
|
41
|
+
"@effect/ui-devtools": "4.2.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^26.6.10",
|
|
45
|
+
"effect": "4.2.0",
|
|
46
|
+
"fast-check": "4.11.0",
|
|
47
|
+
"typescript": "^5.8.3",
|
|
48
|
+
"vite-plus": "1.8.0"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"effect": "^4.2.0",
|
|
52
|
+
"typescript": "^5.8.3"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": "^22.18.0 || ^24.11.0 || >=26.0.0"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "vp pack",
|
|
59
|
+
"dev": "vp pack --watch",
|
|
60
|
+
"test": "vp test",
|
|
61
|
+
"check:types": "effect-tsgo tsrs --noEmit",
|
|
62
|
+
"check:lint": "effect-tsgo vp lint"
|
|
63
|
+
}
|
|
6
64
|
}
|