@x12i/assistant-functions
v1.2.0
Published
Folder-based JSON-returning AI assistants — callable as simple functions with a router and test()
Readme
@x12i/assistant-functions
Folder-based assistant functions: load instructions + knowledge from disk (or in-code config), call an LLM via FuncX askJson, and return parsed JSON.
Consumes (and scaffolds) this layout (default root .assistants-functions):
.assistants-functions/
README.md
create-data/
.assistant.json # hidden model/config (preferred)
instructions.md
knowledge/
data-fixtures.md
hard-rules.md
knowx.md
generate-metadata/
.assistant.json
instructions.md
knowledge/
…Optional root registry: .assistants.json (preferred) or assistants.json.
Legacy plain assistant.json is still read if present; .assistant.json wins when both exist.
Root resolution (CLI and when rootDir is omitted):
- Explicit
--root/rootDir/ request body ASSISTANTS_ROOTenv- Existing
.assistants-functions(default name) - Existing legacy
ai-assistants(still supported) - Otherwise default path
.assistants-functions
Install
npm install @x12i/assistant-functionsRequires Node ≥ 20 and an OpenRouter / FuncX-compatible LLM key (OPENROUTER_API_KEY).
Config merge
- Registry defaults (
.assistants.json/assistants.json) - Registry entry for that assistant name
- Per-folder
.assistant.json/assistant.json— last wins
.assistant.json example:
{
"description": "Create synthetic data records as JSON",
"model": "cheap/default",
"temperature": 0.1,
"maxTokens": 2048,
"testPrompt": { "count": 1 }
}API
import {
createAssistantRouter,
createAssistantFunction,
stringifyPrompt,
} from "@x12i/assistant-functions";
// Omit rootDir to use .assistants-functions (or ASSISTANTS_ROOT / legacy ai-assistants)
const router = await createAssistantRouter({
rootDir: "./.assistants-functions",
config: { defaults: { model: "cheap/default" } }, // optional; file wins on overlap
});
router.list(); // ["create-data", "generate-metadata"]
await router.run("create-data", { count: 2 });
await router.test("create-data"); // boolean
const fn = createAssistantFunction(router, "create-data");
await fn({ count: 2 });stringifyPrompt(input): strings as-is; null/undefined → ""; otherwise JSON.stringify (never [object Object]).
CLI
assistant-functions init --name create-data
# default root ./.assistants-functions — writes .assistants.json, README.md, and create-data/ with:
# instructions.md, knowledge/overview.md (empty), .assistant.json
# (.assistant.json includes model, temperature, maxTokens, testPrompt: {})
assistant-functions list
assistant-functions run create-data --prompt '{"count":1}'
assistant-functions test create-data
# Explicit root still works (incl. legacy ai-assistants):
assistant-functions list --root ./ai-assistantsScripts
npm run build
npm testFixture used by tests: fixtures/ai-assistants.
