Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

1.1 KB
Raw Blame
import { assert, describe, it } from "@effect/vitest"
import { Schema } from "effect"
import { Tool } from "effect/unstable/ai"

describe("Tool representation v2", () => {
  it("projects the encoded side before JSON Schema generation", () => {
    assert.strictEqual(Tool.getJsonSchemaFromSchema(Schema.FiniteFromString).type, "string")
  })

  it("uses custom JSON Schema compiler annotations for schema parameters", () => {
    const schema = Schema.Struct({
      value: Schema.String.check(Schema.makeFilter<string>((value) => value.length >= 2, {
        representation: {
          id: "test/ai/tool/minTwoCharacters",
          payload: null
        },
        toJsonSchema: () => ({ minLength: 2 })
      }))
    })
    const tool = Tool.make("CustomCheck", { parameters: schema })

    assert.deepStrictEqual(Tool.getJsonSchema(tool), Tool.getJsonSchemaFromSchema(schema))
    assert.deepStrictEqual(Tool.getJsonSchema(tool), {
      type: "object",
      properties: {
        value: {
          type: "string",
          allOf: [{ minLength: 2 }]
        }
      },
      required: ["value"],
      additionalProperties: false
    })
  })
})