@lushly-dev/afd-server 1.0.0 → 2.0.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.
Files changed (112) hide show
  1. package/README.md +297 -14
  2. package/dist/bootstrap/afd-context.d.ts +11 -2
  3. package/dist/bootstrap/afd-context.d.ts.map +1 -1
  4. package/dist/bootstrap/afd-context.js +56 -11
  5. package/dist/bootstrap/afd-context.js.map +1 -1
  6. package/dist/bootstrap/afd-docs.d.ts +6 -3
  7. package/dist/bootstrap/afd-docs.d.ts.map +1 -1
  8. package/dist/bootstrap/afd-docs.js +14 -9
  9. package/dist/bootstrap/afd-docs.js.map +1 -1
  10. package/dist/bootstrap/afd-help.d.ts +6 -3
  11. package/dist/bootstrap/afd-help.d.ts.map +1 -1
  12. package/dist/bootstrap/afd-help.js +10 -8
  13. package/dist/bootstrap/afd-help.js.map +1 -1
  14. package/dist/bootstrap/afd-schema.d.ts +8 -4
  15. package/dist/bootstrap/afd-schema.d.ts.map +1 -1
  16. package/dist/bootstrap/afd-schema.js +55 -42
  17. package/dist/bootstrap/afd-schema.js.map +1 -1
  18. package/dist/bootstrap/described-command.d.ts +32 -0
  19. package/dist/bootstrap/described-command.d.ts.map +1 -0
  20. package/dist/bootstrap/described-command.js +12 -0
  21. package/dist/bootstrap/described-command.js.map +1 -0
  22. package/dist/bootstrap/index.d.ts +1 -0
  23. package/dist/bootstrap/index.d.ts.map +1 -1
  24. package/dist/bootstrap/index.js.map +1 -1
  25. package/dist/bootstrap/json-schema-to-ts.d.ts +27 -0
  26. package/dist/bootstrap/json-schema-to-ts.d.ts.map +1 -0
  27. package/dist/bootstrap/json-schema-to-ts.js +154 -0
  28. package/dist/bootstrap/json-schema-to-ts.js.map +1 -0
  29. package/dist/bootstrap/registry.d.ts +17 -6
  30. package/dist/bootstrap/registry.d.ts.map +1 -1
  31. package/dist/bootstrap/registry.js +32 -5
  32. package/dist/bootstrap/registry.js.map +1 -1
  33. package/dist/command-names.d.ts +19 -0
  34. package/dist/command-names.d.ts.map +1 -0
  35. package/dist/command-names.js +33 -0
  36. package/dist/command-names.js.map +1 -0
  37. package/dist/command-routing.d.ts +47 -0
  38. package/dist/command-routing.d.ts.map +1 -0
  39. package/dist/command-routing.js +75 -0
  40. package/dist/command-routing.js.map +1 -0
  41. package/dist/context-scope.d.ts +26 -0
  42. package/dist/context-scope.d.ts.map +1 -0
  43. package/dist/context-scope.js +31 -0
  44. package/dist/context-scope.js.map +1 -0
  45. package/dist/define.d.ts +42 -0
  46. package/dist/define.d.ts.map +1 -0
  47. package/dist/define.js +41 -0
  48. package/dist/define.js.map +1 -0
  49. package/dist/direct-registry.d.ts +103 -0
  50. package/dist/direct-registry.d.ts.map +1 -0
  51. package/dist/direct-registry.js +102 -0
  52. package/dist/direct-registry.js.map +1 -0
  53. package/dist/execution.d.ts +9 -0
  54. package/dist/execution.d.ts.map +1 -1
  55. package/dist/execution.js +105 -321
  56. package/dist/execution.js.map +1 -1
  57. package/dist/http-handler.d.ts +24 -17
  58. package/dist/http-handler.d.ts.map +1 -1
  59. package/dist/http-handler.js +282 -253
  60. package/dist/http-handler.js.map +1 -1
  61. package/dist/http-security.d.ts +23 -0
  62. package/dist/http-security.d.ts.map +1 -0
  63. package/dist/http-security.js +101 -0
  64. package/dist/http-security.js.map +1 -0
  65. package/dist/http-sessions.d.ts +33 -0
  66. package/dist/http-sessions.d.ts.map +1 -0
  67. package/dist/http-sessions.js +65 -0
  68. package/dist/http-sessions.js.map +1 -0
  69. package/dist/http-sse.d.ts +30 -0
  70. package/dist/http-sse.d.ts.map +1 -0
  71. package/dist/http-sse.js +70 -0
  72. package/dist/http-sse.js.map +1 -0
  73. package/dist/index.d.ts +4 -3
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +3 -1
  76. package/dist/index.js.map +1 -1
  77. package/dist/json-rpc.d.ts +56 -0
  78. package/dist/json-rpc.d.ts.map +1 -0
  79. package/dist/json-rpc.js +73 -0
  80. package/dist/json-rpc.js.map +1 -0
  81. package/dist/lazy-tools.d.ts +2 -12
  82. package/dist/lazy-tools.d.ts.map +1 -1
  83. package/dist/lazy-tools.js +9 -14
  84. package/dist/lazy-tools.js.map +1 -1
  85. package/dist/meta-tools.d.ts +122 -0
  86. package/dist/meta-tools.d.ts.map +1 -0
  87. package/dist/meta-tools.js +156 -0
  88. package/dist/meta-tools.js.map +1 -0
  89. package/dist/middleware.d.ts +34 -7
  90. package/dist/middleware.d.ts.map +1 -1
  91. package/dist/middleware.js +82 -40
  92. package/dist/middleware.js.map +1 -1
  93. package/dist/schema.d.ts +27 -6
  94. package/dist/schema.d.ts.map +1 -1
  95. package/dist/schema.js +17 -12
  96. package/dist/schema.js.map +1 -1
  97. package/dist/server-types.d.ts +90 -14
  98. package/dist/server-types.d.ts.map +1 -1
  99. package/dist/server-types.js.map +1 -1
  100. package/dist/server.d.ts +1 -1
  101. package/dist/server.d.ts.map +1 -1
  102. package/dist/server.js +103 -21
  103. package/dist/server.js.map +1 -1
  104. package/dist/tool-router.d.ts +6 -5
  105. package/dist/tool-router.d.ts.map +1 -1
  106. package/dist/tool-router.js +104 -120
  107. package/dist/tool-router.js.map +1 -1
  108. package/dist/tools.d.ts +10 -420
  109. package/dist/tools.d.ts.map +1 -1
  110. package/dist/tools.js +99 -208
  111. package/dist/tools.js.map +1 -1
  112. package/package.json +13 -8
@@ -0,0 +1,103 @@
1
+ /**
2
+ * @fileoverview Validating in-process registry for `DirectClient`.
3
+ *
4
+ * `createDirectRegistry()` runs commands through the same execution engine as
5
+ * `createMcpServer()`: Zod input validation, middleware, error sanitization and
6
+ * `onCommand`/`onError` hooks. It only lists and runs the commands exposed to
7
+ * one interface, `'agent'` by default.
8
+ */
9
+ import type { CommandContext, CommandMiddleware, CommandResult, ExposeOptions, JsonSchema } from '@lushly-dev/afd-core';
10
+ import type { ZodCommandDefinition } from './schema.js';
11
+ /** An interface a command can be exposed to (`palette`, `mcp`, `agent`, `cli`). */
12
+ export type ExposeInterface = keyof ExposeOptions;
13
+ /**
14
+ * Options for {@link createDirectRegistry}.
15
+ */
16
+ export interface DirectRegistryOptions {
17
+ /**
18
+ * The interface this registry serves. Only commands exposed to it are
19
+ * listed and executable. Default: `'agent'`, the in-app AI assistant.
20
+ */
21
+ interface?: ExposeInterface;
22
+ /** Middleware applied to every command, in onion order (same as `createMcpServer`). */
23
+ middleware?: CommandMiddleware[];
24
+ /**
25
+ * Include exception messages and stacks in failures. Default: `false`, which
26
+ * returns a generic `COMMAND_EXECUTION_ERROR` message instead.
27
+ */
28
+ devMode?: boolean;
29
+ /** Called after each command completes. A throwing hook never changes the result. */
30
+ onCommand?: (command: string, input: unknown, result: CommandResult) => void;
31
+ /** Called when a handler or input validation throws. */
32
+ onError?: (error: Error) => void;
33
+ }
34
+ /**
35
+ * Summary of a command the registry exposes, for building tool declarations.
36
+ */
37
+ export interface DirectRegistryCommand {
38
+ name: string;
39
+ description: string;
40
+ category?: string;
41
+ mutation?: boolean;
42
+ destructive?: boolean;
43
+ /** JSON Schema of the command input. */
44
+ inputSchema: JsonSchema;
45
+ }
46
+ /**
47
+ * A validating command registry. Structurally compatible with the
48
+ * `DirectRegistry` interface of `@lushly-dev/afd-client`, so it can be passed
49
+ * straight to `createDirectClient()` or `new DirectClient()`.
50
+ */
51
+ export interface DirectCommandRegistry {
52
+ /** The interface this registry serves. */
53
+ readonly interface: ExposeInterface;
54
+ /**
55
+ * Validate the input with the command's Zod schema, then run the command
56
+ * through the middleware. Returns `COMMAND_NOT_FOUND` for unknown names,
57
+ * `COMMAND_NOT_EXPOSED` for commands not exposed to this interface and
58
+ * `VALIDATION_ERROR` for invalid input; the handler does not run for any of them.
59
+ */
60
+ execute<T>(name: string, input?: unknown, context?: CommandContext): Promise<CommandResult<T>>;
61
+ /** Names of the commands exposed to this interface. */
62
+ listCommandNames(): string[];
63
+ /** Commands exposed to this interface, with their input schemas. */
64
+ listCommands(): DirectRegistryCommand[];
65
+ /** Whether a command is registered and exposed to this interface. */
66
+ hasCommand(name: string): boolean;
67
+ }
68
+ /**
69
+ * Whether a command is exposed to an interface. Each flag the command's
70
+ * `expose` leaves out falls back to `defaultExpose`, so `expose: { mcp: true }`
71
+ * keeps the default `agent` and `palette` access. Set `agent: false` to keep a
72
+ * command away from in-app agents.
73
+ */
74
+ export declare function isExposedTo(command: Pick<ZodCommandDefinition, 'expose'>, iface: ExposeInterface): boolean;
75
+ /**
76
+ * Create a validating in-process registry for `DirectClient`.
77
+ *
78
+ * Unlike a hand-written registry that calls `command.handler(input)`, this
79
+ * registry validates input with the command's Zod schema (rejecting wrong
80
+ * types, nested objects and unknown shapes before the handler runs), applies
81
+ * middleware, hides exception details outside `devMode`, and refuses commands
82
+ * that are not exposed to the chosen interface.
83
+ *
84
+ * @param commands - Commands created with `defineCommand()`
85
+ * @param options - Interface, middleware and hooks
86
+ * @throws If two commands share a name
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * import { createDirectClient } from '@lushly-dev/afd-client';
91
+ * import { createDirectRegistry, createLoggingMiddleware } from '@lushly-dev/afd-server';
92
+ *
93
+ * const registry = createDirectRegistry(commands, {
94
+ * middleware: [createLoggingMiddleware()],
95
+ * });
96
+ * const client = createDirectClient(registry);
97
+ *
98
+ * await client.call('todo-create', { title: { nested: true } });
99
+ * // → { success: false, error: { code: 'VALIDATION_ERROR', ... } }
100
+ * ```
101
+ */
102
+ export declare function createDirectRegistry(commands: ZodCommandDefinition[], options?: DirectRegistryOptions): DirectCommandRegistry;
103
+ //# sourceMappingURL=direct-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"direct-registry.d.ts","sourceRoot":"","sources":["../src/direct-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACX,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,UAAU,EACV,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEx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B,OAAO,EAAE,IAAI,CAAC,oBAAoB,EAAE,QAAQ,CAAC,EAC7C,KAAK,EAAE,eAAe,GACpB,OAAO,CAET;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,oBAAoB,CACnC,QAAQ,EAAE,oBAAoB,EAAE,EAChC,OAAO,GAAE,qBAA0B,GACjC,qBAAqB,CAmEvB"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * @fileoverview Validating in-process registry for `DirectClient`.
3
+ *
4
+ * `createDirectRegistry()` runs commands through the same execution engine as
5
+ * `createMcpServer()`: Zod input validation, middleware, error sanitization and
6
+ * `onCommand`/`onError` hooks. It only lists and runs the commands exposed to
7
+ * one interface, `'agent'` by default.
8
+ */
9
+ import { failure, isExposedTo as isCoreExposedTo } from '@lushly-dev/afd-core';
10
+ import { createExecutionEngine } from './execution.js';
11
+ /**
12
+ * Whether a command is exposed to an interface. Each flag the command's
13
+ * `expose` leaves out falls back to `defaultExpose`, so `expose: { mcp: true }`
14
+ * keeps the default `agent` and `palette` access. Set `agent: false` to keep a
15
+ * command away from in-app agents.
16
+ */
17
+ export function isExposedTo(command, iface) {
18
+ return isCoreExposedTo(command, iface);
19
+ }
20
+ /**
21
+ * Create a validating in-process registry for `DirectClient`.
22
+ *
23
+ * Unlike a hand-written registry that calls `command.handler(input)`, this
24
+ * registry validates input with the command's Zod schema (rejecting wrong
25
+ * types, nested objects and unknown shapes before the handler runs), applies
26
+ * middleware, hides exception details outside `devMode`, and refuses commands
27
+ * that are not exposed to the chosen interface.
28
+ *
29
+ * @param commands - Commands created with `defineCommand()`
30
+ * @param options - Interface, middleware and hooks
31
+ * @throws If two commands share a name
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * import { createDirectClient } from '@lushly-dev/afd-client';
36
+ * import { createDirectRegistry, createLoggingMiddleware } from '@lushly-dev/afd-server';
37
+ *
38
+ * const registry = createDirectRegistry(commands, {
39
+ * middleware: [createLoggingMiddleware()],
40
+ * });
41
+ * const client = createDirectClient(registry);
42
+ *
43
+ * await client.call('todo-create', { title: { nested: true } });
44
+ * // → { success: false, error: { code: 'VALIDATION_ERROR', ... } }
45
+ * ```
46
+ */
47
+ export function createDirectRegistry(commands, options = {}) {
48
+ const iface = options.interface ?? 'agent';
49
+ const registered = new Map();
50
+ for (const command of commands) {
51
+ if (registered.has(command.name)) {
52
+ throw new Error(`Duplicate command name: ${command.name}`);
53
+ }
54
+ registered.set(command.name, command);
55
+ }
56
+ const exposed = new Map([...registered].filter(([, command]) => isExposedTo(command, iface)));
57
+ const engine = createExecutionEngine({
58
+ commandMap: exposed,
59
+ middleware: options.middleware ?? [],
60
+ devMode: options.devMode ?? false,
61
+ onCommand: options.onCommand,
62
+ onError: options.onError,
63
+ });
64
+ return {
65
+ interface: iface,
66
+ async execute(name, input = {}, context = {}) {
67
+ if (!exposed.has(name) && registered.has(name)) {
68
+ const available = [...exposed.keys()];
69
+ return failure({
70
+ code: 'COMMAND_NOT_EXPOSED',
71
+ message: `Command '${name}' is not exposed to ${iface}`,
72
+ suggestion: available.length > 0
73
+ ? `Use one of the commands exposed to ${iface}: ${available.join(', ')}`
74
+ : `No commands are exposed to ${iface}; set expose.${iface} on the commands it should call`,
75
+ retryable: false,
76
+ });
77
+ }
78
+ // SAFETY: T is the caller's assertion about the command's data, as in DirectRegistry.
79
+ return (await engine.executeCommand(name, input, {
80
+ ...context,
81
+ interface: iface,
82
+ }));
83
+ },
84
+ listCommandNames() {
85
+ return [...exposed.keys()];
86
+ },
87
+ listCommands() {
88
+ return [...exposed.values()].map((command) => ({
89
+ name: command.name,
90
+ description: command.description,
91
+ category: command.category,
92
+ mutation: command.mutation,
93
+ destructive: command.destructive,
94
+ inputSchema: command.jsonSchema,
95
+ }));
96
+ },
97
+ hasCommand(name) {
98
+ return exposed.has(name);
99
+ },
100
+ };
101
+ }
102
+ //# sourceMappingURL=direct-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"direct-registry.js","sourceRoot":"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AAW;gBAChC,WAAW,EAAE,OAAO,CAAC,UAAU;aAC/B,CAAC,CAAC,CAAC;QACL,CAAC;QAED,UAAU,CAAC,IAAY;YACtB,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC1B,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -1,11 +1,20 @@
1
1
  /**
2
2
  * @fileoverview Command execution engine — single, batch, pipeline, and streaming execution.
3
+ *
4
+ * Single commands run here (validation, context, middleware, hooks). Batch,
5
+ * pipeline and stream execution delegate to the core executors
6
+ * (`executeBatch`, `executePipeline`, `executeStream`) with this engine's
7
+ * `executeCommand` as the callback, so their semantics are shared with the
8
+ * core registry and DirectClient.
3
9
  */
4
10
  import type { BatchRequest, BatchResult, CommandContext, CommandMiddleware, CommandResult, PipelineRequest, PipelineResult, StreamChunk } from '@lushly-dev/afd-core';
11
+ import type { ContextState } from './bootstrap/afd-context.js';
5
12
  import type { ZodCommandDefinition } from './schema.js';
6
13
  export interface ExecutionDeps {
7
14
  commandMap: Map<string, ZodCommandDefinition>;
8
15
  middleware: CommandMiddleware[];
16
+ /** Context state used when the command context carries none (stdio). */
17
+ contextState?: ContextState;
9
18
  devMode: boolean;
10
19
  onCommand?: (command: string, input: unknown, result: CommandResult) => void;
11
20
  onError?: (error: Error) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"execution.d.ts","sourceRoot":"","sources":["../src/execution.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,KAAK,EAEX,YAAY,EACZ,WAAW,EAEX,cAAc,EACd,iBAAiB,EACjB,aAAa,EAGb,eAAe,EACf,cAAc,EAEd,WAAW,EACX,MAAM,sBAAsB,CAAC;AAgB9B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAOxD,MAAM,WAAW,aAAa;IAC7B,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;IAC9C,UAAU,EAAE,iBAAiB,EAAE,CAAC;I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