@arcforge/types 2.0.85 → 2.0.87
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/package.json +1 -1
- package/src/define.ts +22 -40
- package/src/handle.ts +1 -0
- package/src/module.ts +22 -9
- package/src/plugin.ts +7 -1
- package/src/session/events/runtime.ts +11 -0
package/package.json
CHANGED
package/src/define.ts
CHANGED
|
@@ -99,45 +99,23 @@ export function defineBench(config: BenchConfig): BenchDefinition {
|
|
|
99
99
|
return { _kind: "bench", config }
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Defines a reusable Axon module. The default export of `module.config.ts`.
|
|
104
|
+
*
|
|
105
|
+
* Pure identity — it returns the config unchanged. A module's file path (its
|
|
106
|
+
* `configPath`) is NOT recovered here: the blueprint scanner resolves it
|
|
107
|
+
* statically from the `import` statements in the agent config that declares
|
|
108
|
+
* the module, so there is no runtime stack to walk and no bundler-renamed
|
|
109
|
+
* filename to match. `defineModule` exists purely for editor inference and to
|
|
110
|
+
* mark intent; it does no work.
|
|
111
|
+
*
|
|
112
|
+
* The config's executable half (`setup`, and any hooks it registers) is run
|
|
113
|
+
* at agent boot by the core runtime, which imports the module by its resolved
|
|
114
|
+
* `configPath`. The static half (`env`, `options`, `emits`, `policy`) is read
|
|
115
|
+
* by the scanner from the file's AST.
|
|
116
|
+
*/
|
|
102
117
|
export function defineModule<O extends Record<string, ModuleOptionSchema>>(config: ModuleConfig<O>): ModuleConfig<O> {
|
|
103
|
-
|
|
104
|
-
// root from a live ModuleConfig object without re-importing or filesystem scanning.
|
|
105
|
-
//
|
|
106
|
-
// We use Error().stack to capture the call site (module.config.ts) rather than
|
|
107
|
-
// import.meta.url which would always point to this file (define.ts).
|
|
108
|
-
let sourcePath: string | undefined
|
|
109
|
-
try {
|
|
110
|
-
const stack = new Error().stack ?? ""
|
|
111
|
-
// Stack lines vary by runtime:
|
|
112
|
-
// Node/V8: " at Object.<anonymous> (file:///path/to/module.config.ts:5:20)"
|
|
113
|
-
// Bun: " at defineModule (/path/to/module.config.ts:2:23)"
|
|
114
|
-
// " at /path/to/module.config.ts:8" (top-level, no function name)
|
|
115
|
-
// We skip the first frame (this function) and find the first frame
|
|
116
|
-
// that is NOT define.ts — that is the module.config.ts caller.
|
|
117
|
-
const lines = stack.split("\n")
|
|
118
|
-
for (const line of lines.slice(1)) {
|
|
119
|
-
// Bare filesystem path (Bun), optionally wrapped in parens after a function name.
|
|
120
|
-
const bare = line.match(/\(?(\/[^():]+\.[jt]sx?):\d+(?::\d+)?\)?/)
|
|
121
|
-
// file:// URL (Node/V8).
|
|
122
|
-
const url = line.match(/\(?(file:\/\/[^)]+)\)?/)
|
|
123
|
-
|
|
124
|
-
const raw = url?.[1] ?? bare?.[1]
|
|
125
|
-
if (!raw) continue
|
|
126
|
-
if (raw.includes("define.ts")) continue
|
|
127
|
-
if (raw.startsWith("native:")) continue
|
|
128
|
-
|
|
129
|
-
try {
|
|
130
|
-
sourcePath = raw.startsWith("file://") ? new URL(raw).pathname : raw
|
|
131
|
-
} catch {
|
|
132
|
-
sourcePath = raw.replace(/^file:\/\//, "").split("?")[0]
|
|
133
|
-
}
|
|
134
|
-
break
|
|
135
|
-
}
|
|
136
|
-
} catch {
|
|
137
|
-
// Stack introspection failed — proceed without _sourcePath.
|
|
138
|
-
// The manifest generator will warn and skip this module.
|
|
139
|
-
}
|
|
140
|
-
return sourcePath ? { ...config, _sourcePath: sourcePath } : config
|
|
118
|
+
return config
|
|
141
119
|
}
|
|
142
120
|
|
|
143
121
|
/**
|
|
@@ -195,17 +173,21 @@ export function defineProps<T extends Record<string, unknown>>(): T {
|
|
|
195
173
|
*
|
|
196
174
|
* ```ts
|
|
197
175
|
* export default defineAxonPlugin(async (axon) => {
|
|
198
|
-
* axon.hooks.
|
|
176
|
+
* axon.hooks.hook("telegram:message", async ({ text, reply }) => {
|
|
199
177
|
* const result = await axon.request({ prompt: text })
|
|
200
178
|
* await reply(result.text)
|
|
201
179
|
* })
|
|
202
180
|
* })
|
|
203
181
|
* ```
|
|
204
182
|
*
|
|
183
|
+
* The `axon` handle is passed in by the runtime that boots the plugin — never
|
|
184
|
+
* read from a global — so a plugin is always bound to its own Axon() instance
|
|
185
|
+
* even when a host runs several at once.
|
|
186
|
+
*
|
|
205
187
|
* @see https://axon.arclabs.it/docs/v2/agent/server
|
|
206
188
|
*/
|
|
207
189
|
export function defineAxonPlugin(fn: (axon: AxonHandle) => void | Promise<void>): AxonPlugin {
|
|
208
|
-
return { name: fn.name || "plugin", fn
|
|
190
|
+
return { name: fn.name || "plugin", fn }
|
|
209
191
|
}
|
|
210
192
|
|
|
211
193
|
/** Handle returned by the test-runtime spawner `Axon()`. */
|
package/src/handle.ts
CHANGED
package/src/module.ts
CHANGED
|
@@ -21,6 +21,13 @@ export type AxonModule = {
|
|
|
21
21
|
version?: string
|
|
22
22
|
/** Absolute path to the module root. */
|
|
23
23
|
root: string
|
|
24
|
+
/**
|
|
25
|
+
* Absolute path to the module's `module.config.ts`. The core runtime
|
|
26
|
+
* imports this at boot to run the module's `setup()`. Resolved statically
|
|
27
|
+
* by the scanner from the agent config's import of this module — never
|
|
28
|
+
* from a runtime stack.
|
|
29
|
+
*/
|
|
30
|
+
configPath: string
|
|
24
31
|
/** Whether module files are auto-discovered and merged. Default true. */
|
|
25
32
|
automerge: boolean
|
|
26
33
|
/** Declared env variables and their requirements. */
|
|
@@ -69,21 +76,19 @@ export type ModuleConfig<O extends Record<string, ModuleOptionSchema> = Record<s
|
|
|
69
76
|
policy?: ModulePolicyNeeds
|
|
70
77
|
/** User-configurable options accepted under `modules.<name>` in `axon.config.ts`. */
|
|
71
78
|
options?: O
|
|
72
|
-
/**
|
|
73
|
-
|
|
74
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Boot-time setup, run by the core runtime when the agent boots. Receives
|
|
81
|
+
* a narrow `axon` handle (hooks, env, policy) and the module's validated
|
|
82
|
+
* options. This is the ONE place a module registers behaviour: lifecycle
|
|
83
|
+
* hooks go through `ctx.axon.hook(...)`, not a separate declarative field.
|
|
84
|
+
* Runs again on hot-reload, after the previous setup's disposers.
|
|
85
|
+
*/
|
|
75
86
|
setup?: (ctx: ModuleSetupCtx<InferOptions<O>>) => void | Promise<void>
|
|
76
87
|
/**
|
|
77
88
|
* Sub-modules this module depends on. Flattened and prepended before the agent's
|
|
78
89
|
* own module list at manifest generation time. First declaration wins on collision.
|
|
79
90
|
*/
|
|
80
91
|
modules?: ModuleEntry[]
|
|
81
|
-
/**
|
|
82
|
-
* Injected by `defineModule()` at call time — absolute path of the
|
|
83
|
-
* module.config.ts file. Never set manually.
|
|
84
|
-
* @internal
|
|
85
|
-
*/
|
|
86
|
-
_sourcePath?: string
|
|
87
92
|
}
|
|
88
93
|
|
|
89
94
|
/** Event payloads a module may emit. */
|
|
@@ -164,6 +169,14 @@ export type ModuleSetupAxon = {
|
|
|
164
169
|
hook(name: string, handler: (...args: any[]) => void | Promise<void>): void
|
|
165
170
|
/** Emit a hook — fires all registered handlers for this name. */
|
|
166
171
|
callHook(name: string, ...args: any[]): Promise<void>
|
|
172
|
+
/**
|
|
173
|
+
* Register teardown for this module's live resources (connections, timers,
|
|
174
|
+
* sockets). Disposers run in REVERSE module order on shutdown, and on
|
|
175
|
+
* hot-reload before setup re-runs — so a reloaded agent is identical to a
|
|
176
|
+
* freshly-booted one. Call it once per resource; they run in reverse
|
|
177
|
+
* registration order within the module too.
|
|
178
|
+
*/
|
|
179
|
+
onDispose(fn: () => void | Promise<void>): void
|
|
167
180
|
env: {
|
|
168
181
|
get(key: string): string | undefined
|
|
169
182
|
require(key: string): string
|
package/src/plugin.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import type { AxonHandle } from "./handle"
|
|
1
2
|
|
|
2
3
|
/**
|
|
3
4
|
* Boot-time plugin. Runs once, after middleware and before routes are
|
|
4
5
|
* mounted. A throwing plugin aborts boot — plugin failure is always fatal.
|
|
6
|
+
*
|
|
7
|
+
* `fn` receives THIS runtime's `axon` handle as an argument — not the injected
|
|
8
|
+
* global. A process may host several Axon() instances at once (the TUI runs
|
|
9
|
+
* one per conversation), and a bare `globalThis.axon` is whichever booted
|
|
10
|
+
* last. Passing the handle binds each plugin to its own runtime.
|
|
5
11
|
*/
|
|
6
12
|
export type AxonPlugin = {
|
|
7
13
|
name: string
|
|
8
|
-
fn: () => void | Promise<void>
|
|
14
|
+
fn: (axon: AxonHandle) => void | Promise<void>
|
|
9
15
|
}
|
|
@@ -53,6 +53,17 @@ export type AxonRuntimeEvent = AxonLogEvents<"axon"> & {
|
|
|
53
53
|
"axon:uninstall:complete": { name: string; durationMs: number }
|
|
54
54
|
"axon:uninstall:failed": { name: string; error: AxonError }
|
|
55
55
|
|
|
56
|
+
// ── Module setup/teardown (boot-time defineModule() setup execution) ─────
|
|
57
|
+
// The determinism ledger: one start/complete (or failed) per module,
|
|
58
|
+
// in blueprint order, carrying the config content hash so two boots of
|
|
59
|
+
// the same blueprint are provably the same wiring.
|
|
60
|
+
"module:setup:start": { name: string; configHash: string; options: Record<string, unknown> }
|
|
61
|
+
"module:setup:complete": { name: string; durationMs: number }
|
|
62
|
+
"module:setup:failed": { name: string; error: AxonError }
|
|
63
|
+
"module:dispose:start": { name: string }
|
|
64
|
+
"module:dispose:complete": { name: string; durationMs: number }
|
|
65
|
+
"module:dispose:failed": { name: string; error: AxonError }
|
|
66
|
+
|
|
56
67
|
// ── Session continuity ───────────────────────────────────────────────────
|
|
57
68
|
"axon:session:start": {}
|
|
58
69
|
"axon:session:restored": {}
|