@tooluminati/forms 0.1.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.
- package/LICENSE +21 -0
- package/dist/create-form-tools.d.ts +6 -0
- package/dist/create-form-tools.d.ts.map +1 -0
- package/dist/create-form-tools.js +96 -0
- package/dist/create-form-tools.test.d.ts +2 -0
- package/dist/create-form-tools.test.d.ts.map +1 -0
- package/dist/create-form-tools.test.js +45 -0
- package/dist/errors.d.ts +7 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +9 -0
- package/dist/form-tool-definition.d.ts +11 -0
- package/dist/form-tool-definition.d.ts.map +1 -0
- package/dist/form-tool-definition.js +1 -0
- package/dist/formik.d.ts +16 -0
- package/dist/formik.d.ts.map +1 -0
- package/dist/formik.js +35 -0
- package/dist/index.cjs +413 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +375 -0
- package/dist/infer-schema.d.ts +3 -0
- package/dist/infer-schema.d.ts.map +1 -0
- package/dist/infer-schema.js +42 -0
- package/dist/infer-schema.test.d.ts +2 -0
- package/dist/infer-schema.test.d.ts.map +1 -0
- package/dist/infer-schema.test.js +27 -0
- package/dist/native-form.d.ts +8 -0
- package/dist/native-form.d.ts.map +1 -0
- package/dist/native-form.js +41 -0
- package/dist/react-hook-form.d.ts +21 -0
- package/dist/react-hook-form.d.ts.map +1 -0
- package/dist/react-hook-form.js +53 -0
- package/dist/react-hook-form.test.d.ts +2 -0
- package/dist/react-hook-form.test.d.ts.map +1 -0
- package/dist/react-hook-form.test.js +28 -0
- package/dist/tanstack-form.d.ts +17 -0
- package/dist/tanstack-form.d.ts.map +1 -0
- package/dist/tanstack-form.js +33 -0
- package/dist/types.d.ts +41 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/useWebMcpFormTool.d.ts +5 -0
- package/dist/useWebMcpFormTool.d.ts.map +1 -0
- package/dist/useWebMcpFormTool.js +14 -0
- package/package.json +54 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useWebMcpFormTool } from './useWebMcpFormTool';
|
|
2
|
+
function flattenTanStackErrors(errors = []) {
|
|
3
|
+
return errors.map((error, index) => ({
|
|
4
|
+
path: typeof error === 'object' && error && 'path' in error
|
|
5
|
+
? String(error.path)
|
|
6
|
+
: String(index),
|
|
7
|
+
message: typeof error === 'object' && error && 'message' in error
|
|
8
|
+
? String(error.message)
|
|
9
|
+
: String(error),
|
|
10
|
+
}));
|
|
11
|
+
}
|
|
12
|
+
export function useTanStackFormWebMcpTool({ form, ...options }) {
|
|
13
|
+
useWebMcpFormTool({
|
|
14
|
+
...options,
|
|
15
|
+
getValues: () => form.state.values,
|
|
16
|
+
setValues: (values) => {
|
|
17
|
+
for (const [field, value] of Object.entries(values)) {
|
|
18
|
+
form.setFieldValue?.(field, value);
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
getErrors: () => flattenTanStackErrors(form.state.errors),
|
|
22
|
+
getSummary: () => ({
|
|
23
|
+
submitting: form.state.isSubmitting,
|
|
24
|
+
validating: form.state.isValidating,
|
|
25
|
+
dirty: form.state.isDirty,
|
|
26
|
+
}),
|
|
27
|
+
submit: async () => {
|
|
28
|
+
await form.handleSubmit();
|
|
29
|
+
const errors = flattenTanStackErrors(form.state.errors);
|
|
30
|
+
return errors.length > 0 ? { success: false, errors } : { success: true };
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { JsonSchema, WebMcpToolAnnotations } from '@tooluminati/core';
|
|
2
|
+
export interface FormError {
|
|
3
|
+
path: string;
|
|
4
|
+
message: string;
|
|
5
|
+
kind?: string | undefined;
|
|
6
|
+
}
|
|
7
|
+
export interface FormDiagnosticSummary {
|
|
8
|
+
name: string;
|
|
9
|
+
submitting?: boolean | undefined;
|
|
10
|
+
validating?: boolean | undefined;
|
|
11
|
+
dirty?: boolean | undefined;
|
|
12
|
+
touched?: boolean | undefined;
|
|
13
|
+
errors: FormError[];
|
|
14
|
+
schema?: JsonSchema | undefined;
|
|
15
|
+
values?: unknown;
|
|
16
|
+
}
|
|
17
|
+
export type FormSubmitResult = {
|
|
18
|
+
success: true;
|
|
19
|
+
message?: string;
|
|
20
|
+
data?: unknown;
|
|
21
|
+
} | {
|
|
22
|
+
success: false;
|
|
23
|
+
message?: string;
|
|
24
|
+
errors?: FormError[];
|
|
25
|
+
};
|
|
26
|
+
export interface WebMcpFormToolOptions<TValues> {
|
|
27
|
+
name: string;
|
|
28
|
+
description: string;
|
|
29
|
+
schema?: JsonSchema;
|
|
30
|
+
getValues: () => TValues;
|
|
31
|
+
setValues: (values: TValues) => void | Promise<void>;
|
|
32
|
+
submit: () => FormSubmitResult | Promise<FormSubmitResult>;
|
|
33
|
+
getErrors?: () => FormError[];
|
|
34
|
+
getSummary?: () => Partial<FormDiagnosticSummary>;
|
|
35
|
+
validateArgs?: ((args: unknown) => TValues) | undefined;
|
|
36
|
+
annotations?: WebMcpToolAnnotations | undefined;
|
|
37
|
+
redactValues?: ((values: TValues) => unknown) | undefined;
|
|
38
|
+
redactResult?: ((result: unknown) => unknown) | undefined;
|
|
39
|
+
includeValidationSummary?: boolean | undefined;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,qBAAqB,EACtB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3B;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAA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AAG,SAAS,CAAC;IAC1D,YAAY,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,GAAG,SAAS,CAAC;IAC1D,wBAAwB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChD"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type DependencyList } from 'react';
|
|
2
|
+
import type { WebMcpFormToolOptions } from './types';
|
|
3
|
+
export { createFormValidationSummaryTool } from './create-form-tools';
|
|
4
|
+
export declare function useWebMcpFormTool<TValues>(options: WebMcpFormToolOptions<TValues>, deps?: DependencyList): void;
|
|
5
|
+
//# sourceMappingURL=useWebMcpFormTool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useWebMcpFormTool.d.ts","sourceRoot":"","sources":["../src/useWebMcpFormTool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,cAAc,EAAE,MAAM,OAAO,CAAC;AAKrD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAErD,OAAO,EAAE,+BAA+B,EAAE,MAAM,qBAAqB,CAAC;AAEtE,wBAAgB,iBAAiB,CAAC,OAAO,EACvC,OAAO,EAAE,qBAAqB,CAAC,OAAO,CAAC,EACvC,IAAI,GAAE,cAAmB,GACxB,IAAI,CAmBN"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useWebMcpTools } from '@tooluminati/react';
|
|
3
|
+
import { createWebMcpFormTools } from './create-form-tools';
|
|
4
|
+
import { inferSchemaFromValue } from './infer-schema';
|
|
5
|
+
export { createFormValidationSummaryTool } from './create-form-tools';
|
|
6
|
+
export function useWebMcpFormTool(options, deps = []) {
|
|
7
|
+
const schema = useMemo(() => options.schema ?? inferSchemaFromValue(options.getValues()), [options]);
|
|
8
|
+
if (!schema) {
|
|
9
|
+
throw new Error(`Could not infer WebMCP schema for form "${options.name}". ` +
|
|
10
|
+
'Provide an explicit schema or use concrete non-null defaults.');
|
|
11
|
+
}
|
|
12
|
+
const tools = useMemo(() => createWebMcpFormTools(options), [options]);
|
|
13
|
+
useWebMcpTools(tools, deps, { source: 'form' });
|
|
14
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tooluminati/forms",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Form diagnostics and submission adapters for Tooluminati.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@tooluminati/core": "0.1.0"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"react": ">=18.0.0",
|
|
22
|
+
"@tooluminati/react": "0.1.0"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/jitterbox/Tooluminati.git",
|
|
34
|
+
"directory": "packages/forms"
|
|
35
|
+
},
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/jitterbox/Tooluminati/issues"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/jitterbox/Tooluminati#readme",
|
|
40
|
+
"keywords": [
|
|
41
|
+
"tooluminati",
|
|
42
|
+
"webmcp",
|
|
43
|
+
"react",
|
|
44
|
+
"forms",
|
|
45
|
+
"react-hook-form"
|
|
46
|
+
],
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=18"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsup src/index.ts --format esm,cjs && tsc -p tsconfig.json --emitDeclarationOnly",
|
|
52
|
+
"typecheck": "tsc --noEmit"
|
|
53
|
+
}
|
|
54
|
+
}
|