@jaypie/fabric 0.1.1 → 0.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.
Files changed (50) hide show
  1. package/dist/cjs/ServiceSuite.d.ts +58 -0
  2. package/dist/cjs/commander/index.cjs +7 -7
  3. package/dist/cjs/commander/index.cjs.map +1 -1
  4. package/dist/cjs/data/index.cjs.map +1 -1
  5. package/dist/cjs/http/index.cjs.map +1 -1
  6. package/dist/cjs/index.cjs +159 -7
  7. package/dist/cjs/index.cjs.map +1 -1
  8. package/dist/cjs/index.d.ts +3 -1
  9. package/dist/cjs/lambda/index.cjs +7 -7
  10. package/dist/cjs/lambda/index.cjs.map +1 -1
  11. package/dist/cjs/llm/index.cjs +7 -7
  12. package/dist/cjs/llm/index.cjs.map +1 -1
  13. package/dist/cjs/mcp/FabricMcpServer.d.ts +44 -0
  14. package/dist/cjs/mcp/index.cjs +156 -7
  15. package/dist/cjs/mcp/index.cjs.map +1 -1
  16. package/dist/cjs/mcp/index.d.ts +2 -1
  17. package/dist/cjs/mcp/types.d.ts +66 -0
  18. package/dist/cjs/service.d.ts +5 -0
  19. package/dist/esm/ServiceSuite.d.ts +58 -0
  20. package/dist/esm/commander/index.js +7 -7
  21. package/dist/esm/commander/index.js.map +1 -1
  22. package/dist/esm/data/index.js.map +1 -1
  23. package/dist/esm/http/index.js.map +1 -1
  24. package/dist/esm/index.d.ts +2 -0
  25. package/dist/esm/index.js +158 -8
  26. package/dist/esm/index.js.map +1 -1
  27. package/dist/esm/lambda/index.js +7 -7
  28. package/dist/esm/lambda/index.js.map +1 -1
  29. package/dist/esm/llm/index.js +7 -7
  30. package/dist/esm/llm/index.js.map +1 -1
  31. package/dist/esm/mcp/FabricMcpServer.d.ts +44 -0
  32. package/dist/esm/mcp/index.d.ts +2 -1
  33. package/dist/esm/mcp/index.js +155 -8
  34. package/dist/esm/mcp/index.js.map +1 -1
  35. package/dist/esm/mcp/types.d.ts +66 -0
  36. package/package.json +1 -1
  37. package/dist/cjs/commander/registerServiceCommand.d.ts +0 -43
  38. package/dist/cjs/convert-date.d.ts +0 -47
  39. package/dist/cjs/convert.d.ts +0 -69
  40. package/dist/cjs/lambda/createLambdaService.d.ts +0 -33
  41. package/dist/cjs/llm/createLlmTool.d.ts +0 -40
  42. package/dist/cjs/mcp/registerMcpTool.d.ts +0 -38
  43. package/dist/cjs/types/fieldCategory.d.ts +0 -20
  44. package/dist/esm/commander/registerServiceCommand.d.ts +0 -43
  45. package/dist/esm/convert-date.d.ts +0 -47
  46. package/dist/esm/convert.d.ts +0 -69
  47. package/dist/esm/lambda/createLambdaService.d.ts +0 -33
  48. package/dist/esm/llm/createLlmTool.d.ts +0 -40
  49. package/dist/esm/mcp/registerMcpTool.d.ts +0 -38
  50. package/dist/esm/types/fieldCategory.d.ts +0 -20
@@ -1,40 +0,0 @@
1
- import type { CreateLlmToolConfig, CreateLlmToolResult } from "./types.js";
2
- /**
3
- * Create an LLM tool from a fabric service
4
- *
5
- * This function creates an LLM tool compatible with @jaypie/llm Toolkit.
6
- * It automatically:
7
- * - Uses handler.alias as the tool name (or custom name)
8
- * - Uses handler.description as the tool description (or custom)
9
- * - Converts input definitions to JSON Schema parameters
10
- * - Wraps the service as the tool's call function
11
- *
12
- * @param config - Configuration including handler and optional overrides
13
- * @returns An object containing the created LLM tool
14
- *
15
- * @example
16
- * ```typescript
17
- * import { createService } from "@jaypie/fabric";
18
- * import { createLlmTool } from "@jaypie/fabric/llm";
19
- * import { Toolkit } from "@jaypie/llm";
20
- *
21
- * const handler = createService({
22
- * alias: "greet",
23
- * description: "Greet a user by name",
24
- * input: {
25
- * userName: { type: String, description: "The user's name" },
26
- * loud: { type: Boolean, default: false, description: "Shout the greeting" },
27
- * },
28
- * service: ({ userName, loud }) => {
29
- * const greeting = `Hello, ${userName}!`;
30
- * return loud ? greeting.toUpperCase() : greeting;
31
- * },
32
- * });
33
- *
34
- * const { tool } = createLlmTool({ handler });
35
- *
36
- * // Use with Toolkit
37
- * const toolkit = new Toolkit([tool]);
38
- * ```
39
- */
40
- export declare function createLlmTool(config: CreateLlmToolConfig): CreateLlmToolResult;
@@ -1,38 +0,0 @@
1
- import type { RegisterMcpToolConfig, RegisterMcpToolResult } from "./types.js";
2
- /**
3
- * Register a fabric service as an MCP tool
4
- *
5
- * This function registers a service with an MCP server.
6
- * It automatically:
7
- * - Uses handler.alias as the tool name (or custom name)
8
- * - Uses handler.description as the tool description (or custom)
9
- * - Delegates validation to the service
10
- * - Wraps the service and formats the response
11
- *
12
- * @param config - Configuration including handler, server, and optional overrides
13
- * @returns An object containing the registered tool name
14
- *
15
- * @example
16
- * ```typescript
17
- * import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
18
- * import { createService } from "@jaypie/fabric";
19
- * import { registerMcpTool } from "@jaypie/fabric/mcp";
20
- *
21
- * const handler = createService({
22
- * alias: "greet",
23
- * description: "Greet a user by name",
24
- * input: {
25
- * userName: { type: String, description: "The user's name" },
26
- * loud: { type: Boolean, default: false, description: "Shout the greeting" },
27
- * },
28
- * service: ({ userName, loud }) => {
29
- * const greeting = `Hello, ${userName}!`;
30
- * return loud ? greeting.toUpperCase() : greeting;
31
- * },
32
- * });
33
- *
34
- * const server = new McpServer({ name: "my-server", version: "1.0.0" });
35
- * registerMcpTool({ handler, server });
36
- * ```
37
- */
38
- export declare function registerMcpTool(config: RegisterMcpToolConfig): RegisterMcpToolResult;
@@ -1,20 +0,0 @@
1
- /**
2
- * Field Categories - Semantic classification of fields
3
- *
4
- * Categories define the semantic boundary of fields within models.
5
- */
6
- /** Field categories defining semantic boundaries */
7
- export declare const FIELD_CATEGORIES: readonly ["identity", "input", "metadata", "state"];
8
- /**
9
- * Field category - semantic classification of fields
10
- *
11
- * - identity: What the model IS (immutable) - id, model, ou
12
- * - metadata: What the model is ABOUT (usually immutable) - alias, xid, class, type
13
- * - state: What the model TRACKS (mutable) - content, status, progress
14
- * - input: Request parameters (transient) - data, params, options
15
- */
16
- export type FieldCategory = (typeof FIELD_CATEGORIES)[number];
17
- /**
18
- * Check if a string is a valid field category
19
- */
20
- export declare function isFieldCategory(value: unknown): value is FieldCategory;
@@ -1,43 +0,0 @@
1
- import type { RegisterServiceCommandConfig, RegisterServiceCommandResult } from "./types.js";
2
- /**
3
- * Register a service as a Commander.js command
4
- *
5
- * This function creates a command from a service, automatically:
6
- * - Creating the command with the handler's alias (or custom name)
7
- * - Adding a description from the handler's description (or custom)
8
- * - Converting input definitions to Commander options
9
- * - Wiring up the action to call the handler with parsed input
10
- *
11
- * Error handling:
12
- * - Services can call context.onError() for recoverable errors
13
- * - Services can call context.onFatal() for fatal errors
14
- * - Any error that throws out of the service is treated as fatal
15
- *
16
- * @param config - Configuration including handler, program, and optional overrides
17
- * @returns An object containing the created command
18
- *
19
- * @example
20
- * ```typescript
21
- * import { Command } from "commander";
22
- * import { createService } from "@jaypie/fabric";
23
- * import { registerServiceCommand } from "@jaypie/fabric/commander";
24
- *
25
- * const handler = createService({
26
- * alias: "greet",
27
- * description: "Greet a user",
28
- * input: {
29
- * userName: { type: String, description: "User name" },
30
- * loud: { type: Boolean, description: "Shout greeting" },
31
- * },
32
- * service: ({ userName, loud }) => {
33
- * const greeting = `Hello, ${userName}!`;
34
- * return loud ? greeting.toUpperCase() : greeting;
35
- * },
36
- * });
37
- *
38
- * const program = new Command();
39
- * registerServiceCommand({ handler, program });
40
- * program.parse();
41
- * ```
42
- */
43
- export declare function registerServiceCommand({ description, exclude, handler, name, onComplete, onError, onFatal, onMessage, overrides, program, }: RegisterServiceCommandConfig): RegisterServiceCommandResult;
@@ -1,47 +0,0 @@
1
- /**
2
- * Date Type Conversion for @jaypie/fabric
3
- *
4
- * Adds Date as a supported type in the fabric type system.
5
- * Follows the same conversion patterns as String, Number, Boolean.
6
- */
7
- /**
8
- * Check if a value is a valid Date
9
- */
10
- export declare function isValidDate(value: unknown): value is Date;
11
- /**
12
- * Convert a value to a Date
13
- *
14
- * Supported inputs:
15
- * - Date: returned as-is (validated)
16
- * - Number: treated as Unix timestamp (milliseconds)
17
- * - String: parsed via Date constructor (ISO 8601, etc.)
18
- * - Object with value property: unwrapped and converted
19
- *
20
- * @throws BadRequestError if value cannot be converted to valid Date
21
- */
22
- export declare function fabricDate(value: unknown): Date;
23
- /**
24
- * Convert a value from a Date to another type
25
- *
26
- * @param value - Date to convert
27
- * @param targetType - Target type (String, Number)
28
- */
29
- export declare function convertFromDate(value: Date, targetType: typeof Number | typeof String): number | string;
30
- /**
31
- * Date type constant for use in fabricService input definitions
32
- *
33
- * Usage:
34
- * ```typescript
35
- * const handler = fabricService({
36
- * input: {
37
- * startDate: { type: Date },
38
- * endDate: { type: Date, default: undefined }
39
- * }
40
- * });
41
- * ```
42
- */
43
- export declare const DateType: DateConstructor;
44
- /**
45
- * Type guard for Date type in schema definitions
46
- */
47
- export declare function isDateType(type: unknown): type is typeof Date;
@@ -1,69 +0,0 @@
1
- import type { ConversionType } from "./types.js";
2
- /**
3
- * Convert a value to a boolean
4
- * - Arrays, objects, and JSON strings are unwrapped first
5
- * - String "true" becomes true
6
- * - String "false" becomes false
7
- * - Strings that parse to numbers: positive = true, zero or negative = false
8
- * - Numbers: positive = true, zero or negative = false
9
- * - Boolean passes through
10
- */
11
- export declare function fabricBoolean(value: unknown): boolean | undefined;
12
- /**
13
- * Convert a value to a number
14
- * - Arrays, objects, and JSON strings are unwrapped first
15
- * - String "" becomes undefined
16
- * - String "true" becomes 1
17
- * - String "false" becomes 0
18
- * - Strings that parse to numbers use those values
19
- * - Strings that parse to NaN throw BadRequestError
20
- * - Boolean true becomes 1, false becomes 0
21
- * - Number passes through
22
- */
23
- export declare function fabricNumber(value: unknown): number | undefined;
24
- /**
25
- * Convert a value to a string
26
- * - Arrays, objects, and JSON strings are unwrapped first
27
- * - String "" becomes undefined
28
- * - Boolean true becomes "true", false becomes "false"
29
- * - Number converts to string representation
30
- * - String passes through
31
- */
32
- export declare function fabricString(value: unknown): string | undefined;
33
- /**
34
- * Convert a value to an array
35
- * - Non-arrays become arrays containing that value
36
- * - Arrays of a single value become that value (unwrapped)
37
- * - Multi-value arrays throw BadRequestError
38
- * - undefined/null become undefined
39
- */
40
- export declare function fabricArray(value: unknown): unknown[] | undefined;
41
- /**
42
- * Convert a value from an array to a scalar
43
- * - Single-element arrays become that element
44
- * - Multi-element arrays throw BadRequestError
45
- * - Non-arrays pass through
46
- */
47
- export declare function convertFromArray(value: unknown): unknown;
48
- /**
49
- * Convert a value to an object with a value property
50
- * - Scalars become { value: scalar }
51
- * - Arrays become { value: array }
52
- * - Objects with a value attribute pass through
53
- * - Objects without a value attribute throw BadRequestError
54
- * - undefined/null become undefined
55
- */
56
- export declare function fabricObject(value: unknown): {
57
- value: unknown;
58
- } | undefined;
59
- /**
60
- * Convert a value from an object to its value property
61
- * - Objects with a value property return that value
62
- * - Objects without a value throw BadRequestError
63
- * - Scalars pass through
64
- */
65
- export declare function convertFromObject(value: unknown): unknown;
66
- /**
67
- * Fabric a value to the specified type
68
- */
69
- export declare function fabric(value: unknown, type: ConversionType): unknown;
@@ -1,33 +0,0 @@
1
- import type { Service } from "../types.js";
2
- import type { CreateLambdaServiceConfig, CreateLambdaServiceOptions, CreateLambdaServiceResult } from "./types.js";
3
- /**
4
- * Create a Lambda handler that wraps a service
5
- *
6
- * This function creates a Lambda-compatible handler that:
7
- * - Uses getMessages() to extract messages from SQS/SNS events
8
- * - Calls the service once for each message
9
- * - Returns the single response if one message, or an array of responses if multiple
10
- * - Integrates with lambdaHandler for lifecycle management (secrets, setup, teardown, etc.)
11
- *
12
- * @param handlerOrConfig - The service function or configuration object
13
- * @param options - Lambda handler options (secrets, setup, teardown, etc.)
14
- * @returns A Lambda handler function
15
- *
16
- * @example
17
- * ```typescript
18
- * import { createLambdaService } from "@jaypie/fabric/lambda";
19
- * import { myService } from "./services";
20
- *
21
- * // Config object style
22
- * export const handler = createLambdaService({
23
- * handler: myService,
24
- * secrets: ["ANTHROPIC_API_KEY", "OPENAI_API_KEY"],
25
- * });
26
- *
27
- * // Handler with options style
28
- * export const handler2 = createLambdaService(myService, {
29
- * secrets: ["ANTHROPIC_API_KEY"],
30
- * });
31
- * ```
32
- */
33
- export declare function createLambdaService<TResult = unknown>(handlerOrConfig: CreateLambdaServiceConfig | Service, options?: CreateLambdaServiceOptions): CreateLambdaServiceResult<TResult | TResult[]>;
@@ -1,40 +0,0 @@
1
- import type { CreateLlmToolConfig, CreateLlmToolResult } from "./types.js";
2
- /**
3
- * Create an LLM tool from a fabric service
4
- *
5
- * This function creates an LLM tool compatible with @jaypie/llm Toolkit.
6
- * It automatically:
7
- * - Uses handler.alias as the tool name (or custom name)
8
- * - Uses handler.description as the tool description (or custom)
9
- * - Converts input definitions to JSON Schema parameters
10
- * - Wraps the service as the tool's call function
11
- *
12
- * @param config - Configuration including handler and optional overrides
13
- * @returns An object containing the created LLM tool
14
- *
15
- * @example
16
- * ```typescript
17
- * import { createService } from "@jaypie/fabric";
18
- * import { createLlmTool } from "@jaypie/fabric/llm";
19
- * import { Toolkit } from "@jaypie/llm";
20
- *
21
- * const handler = createService({
22
- * alias: "greet",
23
- * description: "Greet a user by name",
24
- * input: {
25
- * userName: { type: String, description: "The user's name" },
26
- * loud: { type: Boolean, default: false, description: "Shout the greeting" },
27
- * },
28
- * service: ({ userName, loud }) => {
29
- * const greeting = `Hello, ${userName}!`;
30
- * return loud ? greeting.toUpperCase() : greeting;
31
- * },
32
- * });
33
- *
34
- * const { tool } = createLlmTool({ handler });
35
- *
36
- * // Use with Toolkit
37
- * const toolkit = new Toolkit([tool]);
38
- * ```
39
- */
40
- export declare function createLlmTool(config: CreateLlmToolConfig): CreateLlmToolResult;
@@ -1,38 +0,0 @@
1
- import type { RegisterMcpToolConfig, RegisterMcpToolResult } from "./types.js";
2
- /**
3
- * Register a fabric service as an MCP tool
4
- *
5
- * This function registers a service with an MCP server.
6
- * It automatically:
7
- * - Uses handler.alias as the tool name (or custom name)
8
- * - Uses handler.description as the tool description (or custom)
9
- * - Delegates validation to the service
10
- * - Wraps the service and formats the response
11
- *
12
- * @param config - Configuration including handler, server, and optional overrides
13
- * @returns An object containing the registered tool name
14
- *
15
- * @example
16
- * ```typescript
17
- * import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
18
- * import { createService } from "@jaypie/fabric";
19
- * import { registerMcpTool } from "@jaypie/fabric/mcp";
20
- *
21
- * const handler = createService({
22
- * alias: "greet",
23
- * description: "Greet a user by name",
24
- * input: {
25
- * userName: { type: String, description: "The user's name" },
26
- * loud: { type: Boolean, default: false, description: "Shout the greeting" },
27
- * },
28
- * service: ({ userName, loud }) => {
29
- * const greeting = `Hello, ${userName}!`;
30
- * return loud ? greeting.toUpperCase() : greeting;
31
- * },
32
- * });
33
- *
34
- * const server = new McpServer({ name: "my-server", version: "1.0.0" });
35
- * registerMcpTool({ handler, server });
36
- * ```
37
- */
38
- export declare function registerMcpTool(config: RegisterMcpToolConfig): RegisterMcpToolResult;
@@ -1,20 +0,0 @@
1
- /**
2
- * Field Categories - Semantic classification of fields
3
- *
4
- * Categories define the semantic boundary of fields within models.
5
- */
6
- /** Field categories defining semantic boundaries */
7
- export declare const FIELD_CATEGORIES: readonly ["identity", "input", "metadata", "state"];
8
- /**
9
- * Field category - semantic classification of fields
10
- *
11
- * - identity: What the model IS (immutable) - id, model, ou
12
- * - metadata: What the model is ABOUT (usually immutable) - alias, xid, class, type
13
- * - state: What the model TRACKS (mutable) - content, status, progress
14
- * - input: Request parameters (transient) - data, params, options
15
- */
16
- export type FieldCategory = (typeof FIELD_CATEGORIES)[number];
17
- /**
18
- * Check if a string is a valid field category
19
- */
20
- export declare function isFieldCategory(value: unknown): value is FieldCategory;