typeai icon indicating copy to clipboard operation
typeai copied to clipboard

Does not work in Cloud Functions environment

Open zallesov opened this issue 6 months ago • 0 comments

First of all - great idea and great library. If it works it works great! but I'm having a hard time making it run inside a cloud function. This is my function for reference

/** @description Given `cities` a list of city names with country codes, 
 * returns a the same list with added latitude, longitude. */
function hidrateCitiesCoordinates(cities: TripPoint[]): (TripPoint & { lat: number, lng: number })[] | void { }
export const hidrateCitiesCoordinatesAI = toAIFunction(hidrateCitiesCoordinates)

I could make it work locally in plain typescript app ran with tsup-node or ts-node

Describe the bug I attempted to run it in the Google Cloud Functions environment which is "compiled" to javascript. I get this error

TypeError: Cannot read properties of undefined (reading 'type')
    at toAIFunction (file:///Users/username/Projects/air/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]/node_modules/@typeai/core/dist/index.js:4186:40)

and Indeed in the js files there is no implementation of the function

import { toAIFunction } from "@typeai/core";
function hidrateCitiesCoordinates(cities) {
}
var hidrateCitiesCoordinatesAI = toAIFunction(hidrateCitiesCoordinates);

tsconfig.json

  "compilerOptions": {
    "outDir": "dist",
    "target": "ES2022",
    "module": "ESNext",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "lib": [
      "esnext"
    ],
    "sourceMap": true,
    "types": [
      "node"
    ],
    "baseUrl": ".",
    "paths": {
      "~/*": [
        "src/*"
      ]
    },
    "experimentalDecorators": true
  },
  "reflection": true,
  "include": [
    "src"
  ]
}

I also did the step with deepkit-type-install

Is it even possible to achieve this?

Thank you.

zallesov avatar Sep 01 '24 15:09 zallesov