@arcforge/types 2.0.87 → 2.0.88

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcforge/types",
3
- "version": "2.0.87",
3
+ "version": "2.0.88",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "main": "./src/index.ts",
package/src/define.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { AxonConfig } from "./config"
2
2
  import type { BenchConfig, BenchDefinition } from "./bench"
3
- import type { ModuleConfig, ModuleOptionSchema } from "./module"
3
+ import type { ModuleConfig, ModuleEmitMap, ModuleOptionSchema } from "./module"
4
4
  import type { AxonPlugin } from "./plugin"
5
5
  import type { AxonHandle } from "./handle"
6
6
 
@@ -114,7 +114,10 @@ export function defineBench(config: BenchConfig): BenchDefinition {
114
114
  * `configPath`. The static half (`env`, `options`, `emits`, `policy`) is read
115
115
  * by the scanner from the file's AST.
116
116
  */
117
- export function defineModule<O extends Record<string, ModuleOptionSchema>>(config: ModuleConfig<O>): ModuleConfig<O> {
117
+ export function defineModule<
118
+ O extends Record<string, ModuleOptionSchema>,
119
+ E extends ModuleEmitMap,
120
+ >(config: ModuleConfig<O, E>): ModuleConfig<O, E> {
118
121
  return config
119
122
  }
120
123
 
package/src/handle.ts CHANGED
@@ -2,7 +2,7 @@ import type { AxonEntry } from "./session"
2
2
  import type { AxonScript } from "./scripts"
3
3
  import type { AxonPrompt } from "./prompts"
4
4
  import type { AxonPartialBlueprint } from "./blueprint"
5
- import type { AxonHookName, AxonHooks } from "./hooks"
5
+ import type { AxonHookName, AxonHooks, AxonModuleEvents } from "./hooks"
6
6
  import type { AxonAmbient } from "./session/events/activity"
7
7
 
8
8
  /**
@@ -77,13 +77,25 @@ export type EngineConnection = {
77
77
 
78
78
  // ── Lifecycle hooks surface ────────────────────────────────────────────────────
79
79
 
80
+ /** Handler for a module domain event — receives the module's declared payload. */
81
+ export type AxonModuleEventHandler<N extends keyof AxonModuleEvents> =
82
+ (payload: AxonModuleEvents[N]) => void | Promise<void>
83
+
80
84
  /**
81
85
  * The hooks surface exposed on AxonHandle — register-only. Firing (`callHook`)
82
86
  * is runtime-internal; agent code and plugins only ever register.
87
+ *
88
+ * Two families, one `hook()`:
89
+ * - Runtime LIFECYCLE hooks (AxonHooks) — a fixed, closed set, function-typed.
90
+ * - Module domain EVENTS (AxonModuleEvents) — open, augmented per-agent by
91
+ * typegen from installed modules' `emits`, so `hook("discord:message.received",
92
+ * ({ content }) => ...)` is fully typed with no imports.
83
93
  */
84
94
  export type AxonHooksSurface = {
85
95
  hook<N extends AxonHookName>(name: N, fn: AxonHooks[N]): () => void
96
+ hook<N extends keyof AxonModuleEvents>(name: N, fn: AxonModuleEventHandler<N>): () => void
86
97
  removeHook<N extends AxonHookName>(name: N, fn: AxonHooks[N]): void
98
+ removeHook<N extends keyof AxonModuleEvents>(name: N, fn: AxonModuleEventHandler<N>): void
87
99
  }
88
100
 
89
101
  // ── AxonHandle ────────────────────────────────────────────────────────────────
package/src/hooks.ts CHANGED
@@ -29,3 +29,23 @@ export type AxonHooks = {
29
29
  }
30
30
 
31
31
  export type AxonHookName = keyof AxonHooks
32
+
33
+ /**
34
+ * Module event payloads — an OPEN interface, augmented per-agent by typegen.
35
+ *
36
+ * A module declares `emits: { "discord:message.received": {} as { ... } }`;
37
+ * `axon prepare` merges each installed module's emit payloads into this
38
+ * interface (declaration merging, in `.agent/axon.d.ts`). That makes
39
+ * `axon.hooks.hook("discord:message.received", ({ content }) => ...)` fully
40
+ * typed in userland — the event name autocompletes and the payload is inferred
41
+ * — with no imports and no generics.
42
+ *
43
+ * Distinct from AxonHooks: those are the fixed runtime lifecycle call points
44
+ * (a closed set, function-typed). Module events are domain events with a
45
+ * payload the handler receives; the name space is open because it depends on
46
+ * which modules the agent installed.
47
+ */
48
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
49
+ export interface AxonModuleEvents {}
50
+
51
+ export type AxonModuleEventName = keyof AxonModuleEvents
package/src/module.ts CHANGED
@@ -58,7 +58,10 @@ export type OptionTypeMap = {
58
58
  * Module authoring configuration — the object passed to `defineModule()`
59
59
  * in `module.config.ts`.
60
60
  */
61
- export type ModuleConfig<O extends Record<string, ModuleOptionSchema> = Record<string, ModuleOptionSchema>> = {
61
+ export type ModuleConfig<
62
+ O extends Record<string, ModuleOptionSchema> = Record<string, ModuleOptionSchema>,
63
+ E extends ModuleEmitMap = ModuleEmitMap,
64
+ > = {
62
65
  /**
63
66
  * Identity — name, version, description — lives in package.json, not
64
67
  * here. It is what the registry publishes, what `bun install` resolves,
@@ -70,8 +73,13 @@ export type ModuleConfig<O extends Record<string, ModuleOptionSchema> = Record<s
70
73
  */
71
74
  /** Environment variables this module expects the host agent to provide. */
72
75
  env?: Record<string, { required: boolean; description?: string }>
73
- /** Event payloads this module may emit. */
74
- emits?: ModuleEmitMap
76
+ /**
77
+ * Event payloads this module may emit. Declared inline as `{} as { ... }`;
78
+ * the payload types are PRESERVED through the `E` generic (not widened to
79
+ * unknown), so typegen can recover them via `typeof Module.emits` and give
80
+ * subscribers typed payloads at `axon.hooks.hook("event", ...)`.
81
+ */
82
+ emits?: E
75
83
  /** Advisory sandbox permissions this module needs. */
76
84
  policy?: ModulePolicyNeeds
77
85
  /** User-configurable options accepted under `modules.<name>` in `axon.config.ts`. */