@juspay/neurolink
Version:
The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002
44 lines (43 loc) • 1.83 kB
JavaScript
/**
* Tool and schema primitives.
*
* These were re-exported from the `ai` package. They are implemented here now,
* against the local type algebra in `types/aiCompat.ts`. The function and the
* type had to move together: replacing `tool()` alone leaves it producing an
* upstream `Tool` that no longer matches the local one, which is how the first
* attempt failed.
*
* Upstream behaviour, reproduced exactly:
* - `tool()` is identity. It exists for inference, not for runtime.
* - `jsonSchema()` wraps a raw JSON Schema in the duck-typed shape the rest of
* this repo reads — `convertZodToJsonSchema` looks for the `jsonSchema`
* property, not for the brand — and still stamps
* `Symbol.for("vercel.ai.schema")` so anything that does check it keeps
* working.
* - `stepCountIs(n)` returns `({steps}) => steps.length === n`.
*/
const SCHEMA_MARKER = Symbol.for("vercel.ai.schema");
/* eslint-disable no-redeclare, @typescript-eslint/no-explicit-any --
TypeScript overload implementation signature. It must be assignable from
both exported overloads above, which only `any` expresses; the exported
signatures themselves stay precise. */
export function tool(definition) {
return definition;
}
/* eslint-enable no-redeclare, @typescript-eslint/no-explicit-any */
export function jsonSchema(schema, options = {}) {
let resolved = schema;
const wrapper = {
[SCHEMA_MARKER]: true,
_type: undefined,
get jsonSchema() {
if (typeof resolved === "function") {
resolved = resolved();
}
return resolved;
},
...(options.validate ? { validate: options.validate } : {}),
};
return wrapper;
}
export const stepCountIs = (stepCount) => ({ steps }) => steps.length === stepCount;