{"_id":"@agemoai/codewords-client","_rev":"1-79418d658c07de4b0f2b36da7aeddc98","name":"@agemoai/codewords-client","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@agemoai/codewords-client","version":"1.0.0","keywords":["codewords","agemo","runtime","AI","client","typescript"],"author":{"name":"Agemo AI Ltd"},"license":"MIT","_id":"@agemoai/codewords-client@1.0.0","maintainers":[{"name":"agemo-regina","email":"regina@agemo.ai"},{"name":"osmanio2","email":"osman@agemo.ai"},{"name":"hassanmir","email":"hassanmir45@hotmail.com"}],"homepage":"https://codewords.ai","bugs":{"url":"https://github.com/agemoai/codewords_os/issues"},"dist":{"shasum":"6e393232d3c6fdf1678de657076f64d2b29178ff","tarball":"https://registry.npmjs.org/@agemoai/codewords-client/-/codewords-client-1.0.0.tgz","fileCount":15,"integrity":"sha512-SdwBO01gz0wFBcdEOT5dMH8Mk8ThG/gjweCrELS49Mwv5FOnmeyOIAYa9rPg90tKS37QjyQhE8Rg5SOF9GirzQ==","signatures":[{"sig":"MEYCIQDCVuRebJBkwAlJixIrtIP7KUB6rxPJBw/xcTnc7hFAAQIhAKePy3Hu3p62HY3ZwFSvp3wqYHJkGhZ38rSopwXlo47X","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":40338},"main":"dist/src/index.js","types":"dist/src/index.d.ts","gitHead":"d12a13377b6472b2829a7c5952437ec218e004cb","scripts":{"lint":"eslint .","test":"jest","build":"tsc","prepublishOnly":"npm run build"},"_npmUser":{"name":"hassanmir","email":"hassanmir45@hotmail.com"},"repository":{"url":"git+https://github.com/agemoai/codewords_os.git","type":"git"},"_npmVersion":"10.7.0","description":"A client for interacting with Codewords runtime","directories":{},"_nodeVersion":"20.14.0","dependencies":{"zod":"^3.23.8","axios":"^0.21.4"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^26.6.3","eslint":"^7.14.0","ts-jest":"^26.5.6","typescript":"^4.1.3","@types/jest":"^26.0.24","@types/axios":"^0.14.0"},"_npmOperationalInternal":{"tmp":"tmp/codewords-client_1.0.0_1728315783940_0.239357755447976","host":"s3://npm-registry-packages"}},"1.0.1":{"name":"@agemoai/codewords-client","version":"1.0.1","description":"A client for interacting with Codewords runtime","main":"dist/src/index.js","types":"dist/src/index.d.ts","scripts":{"build":"tsc","prepublishOnly":"npm run build","test":"jest","lint":"eslint ."},"repository":{"type":"git","url":"git+https://github.com/agemoai/codewords_os.git"},"keywords":["codewords","agemo","runtime","AI","client","typescript"],"author":{"name":"Agemo AI Ltd"},"license":"MIT","bugs":{"url":"https://github.com/agemoai/codewords_os/issues"},"homepage":"https://codewords.ai","publishConfig":{"access":"public"},"dependencies":{"axios":"^0.21.4","zod":"^3.23.8"},"devDependencies":{"@types/axios":"^0.14.0","@types/jest":"^26.0.24","eslint":"^7.14.0","jest":"^26.6.3","ts-jest":"^26.5.6","typescript":"^4.1.3"},"_id":"@agemoai/codewords-client@1.0.1","gitHead":"03c4adcbe4619693428a1161b1dcd91809fc9445","_nodeVersion":"20.14.0","_npmVersion":"10.7.0","dist":{"integrity":"sha512-4eV5K9vZ0uogHURJhaubOU1MCnkQIky55Uy3/swr3NPgW2usPGQEkpUNdQHgUjDpMt4/a9GlXEnahMLH8JMTpQ==","shasum":"241c591fcc52a2b16b9cd78f281f5a8df759dc7f","tarball":"https://registry.npmjs.org/@agemoai/codewords-client/-/codewords-client-1.0.1.tgz","fileCount":15,"unpackedSize":40201,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFCm5KrFvXlAhWmp6E+tDiacKyHlTFmJGEErD9DxfZ1NAiBi7masQsihVPU6TcQap8sp002oL8BiRh57eikwAP3MLQ=="}]},"_npmUser":{"name":"hassanmir","email":"hassanmir45@hotmail.com"},"directories":{},"maintainers":[{"name":"agemo-regina","email":"regina@agemo.ai"},{"name":"osmanio2","email":"osman@agemo.ai"},{"name":"hassanmir","email":"hassanmir45@hotmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/codewords-client_1.0.1_1728383219610_0.5273792250499112"},"_hasShrinkwrap":false}},"time":{"created":"2024-10-07T15:43:03.838Z","modified":"2024-10-08T10:27:00.099Z","1.0.0":"2024-10-07T15:43:04.190Z","1.0.1":"2024-10-08T10:26:59.813Z"},"bugs":{"url":"https://github.com/agemoai/codewords_os/issues"},"author":{"name":"Agemo AI Ltd"},"license":"MIT","homepage":"https://codewords.ai","keywords":["codewords","agemo","runtime","AI","client","typescript"],"repository":{"type":"git","url":"git+https://github.com/agemoai/codewords_os.git"},"description":"A client for interacting with Codewords runtime","maintainers":[{"name":"agemo-regina","email":"regina@agemo.ai"},{"name":"osmanio2","email":"osman@agemo.ai"},{"name":"hassanmir","email":"hassanmir45@hotmail.com"}],"readme":"# Agemo AI - Codewords Client\n\nA client for interacting with Codewords runtime, designed to easily plug into frontend server-side environments.\n\n## Installation\n\nInstall the package using npm:\n\n```sh\nnpm install @agemoai/codewords-client\n```\n\n## Usage\n\n### Importing the Client\n\nFirst, import the necessary classes and types from the package:\n\n```typescript\nimport { AuthDataType, AuthData, cwFunctionFactory } from \"@agemoai/codewords-client\";\n```\n\n### Authentication\n\nCreate an `AuthData` object to authenticate and authorize the user. **Note: The API key is a secret that should not be shared. It should be accessed via an environment variable. Obtain your API key from the function's CodeWords Run page.**\n\n```typescript\nconst authData: AuthData = {\n  type: AuthDataType.API_KEY,\n  data: \"your-api-key\", // Use environment variable for the API key (keep this a secret)\n};\n```\n\n### Creating a CWFunction Client\n\nUse the `cwFunctionFactory` to create a `CWFunction` client. **Note: IDs and version can be obtained on CodeWords Run page.**\n\n```typescript\nconst functionId = \"your-function-id\"; // Recommend using environment variable for function ID\nconst version = \"your-function-version\"; // Recommend using environment variable for function version\nconst runnerId = \"your-runner-id\"; // Recommend using environment variable for runner ID\nconst verbose = false; // For detailed logs\n\nconst cwFunction = await cwFunctionFactory(functionId, version, runnerId, authData, verbose);\n```\n\n### Running a Function\n\nTo run a function, use the `run` method of the `CWFunction` class. This method takes `inputs` and a `callback` function to handle WebSocket messages.\n\n```typescript\nconst inputs = {\n  input1: \"value1\", // Replace with actual inputs expected by your function\n  input2: \"value2\", // Replace with actual inputs expected by your function\n  // Add other inputs as required by your function\n};\n\ncwFunction.run(inputs, (response) => {\n  if (response.type === \"run_complete\") {\n    console.log(\"Run completed successfully:\", response);\n    \n    // Access the outputs based on the output names specified in your function\n    const output1 = response.outputs.output1;\n    const output2 = response.outputs.output2;\n    console.log(\"Output 1:\", output1);\n    console.log(\"Output 2:\", output2);\n  } else {\n    console.error(\"Run encountered an error:\", response);\n  }\n}).then((ws) => {\n  console.log(\"WebSocket connection established:\", ws);\n}).catch((error) => {\n  console.error(\"Error running function:\", error);\n});\n```\n\n### Handling WebSocket Messages\n\nThe `run` method uses a WebSocket connection to communicate with the runtime. The `callback` function will receive messages from the WebSocket. Here are the types of messages you need to handle:\n\n- **run_complete**: Indicates that the function run has completed successfully.\n- **run_error**: Indicates that there was an error during the function run.\n- **function_missing**: Indicates that the specified function could not be found.\n- **block_error**: Indicates that there was an error in one of the function blocks.\n\n## Environment Variables\n\nThe `codewords-client` package requires the following environment variables to be set:\n\n- `NEXT_PUBLIC_CWR_WS_URL`: The WebSocket URL for the runtime.\n- `NEXT_PUBLIC_CWR_HTTPS_URL`: The HTTPS URL for the runtime.\n\nIn a production environment, you should set these variables to the provided values to access CodeWords runtime:\n\n```sh\nexport NEXT_PUBLIC_CWR_WS_URL=\"wss://d21x5wziv7.execute-api.eu-west-2.amazonaws.com/prod/\"\nexport NEXT_PUBLIC_CWR_HTTPS_URL=\"https://na9ywpljw9.execute-api.eu-west-2.amazonaws.com/prod/runtime\"\n```\n\nIn a development environment, you can set these variables in a `.env` file or directly in your shell.\n\n\n## Complete Example\n\nHere is a complete example of how to use the `@agemoai/codewords-client` to run a function:\n\n```typescript\nimport { AuthDataType, AuthData, cwFunctionFactory } from \"@agemoai/codewords-client\";\n\nconst authData: AuthData = {\n  type: AuthDataType.API_KEY,\n  data: process.env.CODEWORDS_API_KEY, // Use environment variable for the API key\n};\n\nconst functionId = process.env.CODEWORDS_FUNCTION_ID; // Recommend using environment variable for function ID\nconst version = process.env.CODEWORDS_FUNCTION_VERSION; // Recommend using environment variable for function version\nconst runnerId = process.env.CODEWORDS_RUNNER_ID; // Recommend using environment variable for runner ID\nconst verbose = false;\n\nasync function runFunction() {\n  try {\n    const cwFunction = await cwFunctionFactory(functionId, version, runnerId, authData, verbose);\n\n    const inputs = {\n      input1: \"value1\", // Replace with actual inputs expected by your function\n      input2: \"value2\", // Replace with actual inputs expected by your function\n      // Add other inputs as required by your function\n    };\n\n    cwFunction.run(inputs, (response) => {\n      if (response.type === \"run_complete\") {\n        console.log(\"Run completed successfully:\", response);\n        \n        // Access the outputs based on the output names specified in your function\n        const output1 = response.outputs.output1;\n        const output2 = response.outputs.output2;\n        console.log(\"Output 1:\", output1);\n        console.log(\"Output 2:\", output2);\n      } else {\n        console.error(\"Run encountered an error:\", response);\n      }\n    }).then((ws) => {\n      console.log(\"WebSocket connection established:\", ws);\n    }).catch((error) => {\n      console.error(\"Error running function:\", error);\n    });\n  } catch (error) {\n    console.error(\"Error creating CWFunction client:\", error);\n  }\n}\n\nrunFunction();\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [`LICENSE`](command:_github.copilot.openRelativePath?%5B%7B%22scheme%22%3A%22file%22%2C%22authority%22%3A%22%22%2C%22path%22%3A%22%2Fworkspace%2FLICENSE%22%2C%22query%22%3A%22%22%2C%22fragment%22%3A%22%22%7D%2C%22957bfa84-d722-4d11-bca1-9b402e187a51%22%5D \"/workspace/LICENSE\") file for details.\n","readmeFilename":"README.md"}