@ouraihub/llm 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @ouraihub/llm — Skill Loader.
3
+ *
4
+ * Loads skill files (SKILL.md format) and assembles them into structured
5
+ * system prompts. Skills provide domain-specific knowledge, workflows,
6
+ * and behavioral constraints for LLM completions.
7
+ *
8
+ * Usage:
9
+ * const loader = new SkillLoader();
10
+ * loader.add('gzh-design', skillMarkdownContent);
11
+ * const systemPrompt = loader.toSystemPrompt();
12
+ * await llm.complete({ system: systemPrompt, user: '...' }, schema);
13
+ */
14
+ import type { LLMPrompt } from './interfaces.js';
15
+ /** A loaded skill entry */
16
+ export interface SkillEntry {
17
+ /** Unique identifier (e.g. 'gzh-design') */
18
+ readonly id: string;
19
+ /** Skill name from frontmatter */
20
+ readonly name: string;
21
+ /** Skill description from frontmatter */
22
+ readonly description: string;
23
+ /** Full body content (markdown) */
24
+ readonly body: string;
25
+ }
26
+ /** Options for system prompt assembly */
27
+ export interface SkillPromptOptions {
28
+ /** Max total characters for all skills combined (default: no limit) */
29
+ readonly maxChars?: number;
30
+ /** Prefix before skill content (role/persona instruction) */
31
+ readonly preamble?: string;
32
+ /** Suffix after skill content (output format instructions) */
33
+ readonly postamble?: string;
34
+ }
35
+ /**
36
+ * SkillLoader — manages loading and composing skills into LLM prompts.
37
+ *
38
+ * Design:
39
+ * - Skills are added as raw SKILL.md content (frontmatter + body)
40
+ * - Frontmatter is parsed for metadata (name, description)
41
+ * - Body becomes the instruction block in the system prompt
42
+ * - Multiple skills compose into sections with clear boundaries
43
+ */
44
+ export declare class SkillLoader {
45
+ private skills;
46
+ /** Add a skill from raw SKILL.md content */
47
+ add(id: string, rawContent: string): this;
48
+ /** Add a skill from pre-parsed entry */
49
+ addEntry(entry: SkillEntry): this;
50
+ /** Remove a skill by id */
51
+ remove(id: string): this;
52
+ /** Check if a skill is loaded */
53
+ has(id: string): boolean;
54
+ /** Get loaded skill ids */
55
+ ids(): string[];
56
+ /** Clear all loaded skills */
57
+ clear(): this;
58
+ /**
59
+ * Assemble all loaded skills into a system prompt string.
60
+ *
61
+ * Format:
62
+ * ```
63
+ * {preamble}
64
+ *
65
+ * === SKILL: {name} ===
66
+ * {body}
67
+ *
68
+ * === SKILL: {name2} ===
69
+ * {body2}
70
+ *
71
+ * {postamble}
72
+ * ```
73
+ */
74
+ toSystemPrompt(options?: SkillPromptOptions): string;
75
+ /**
76
+ * Build a complete LLMPrompt with skills as system context.
77
+ *
78
+ * Convenience method that combines skill system prompt with user message.
79
+ */
80
+ buildPrompt(userMessage: string, options?: SkillPromptOptions): LLMPrompt;
81
+ }
82
+ //# sourceMappingURL=skill-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skill-loader.d.ts","sourceRoot":"","sources":["../../src/skill-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,2BAA2B;AAC3B,MAAM,WAAW,UAAU;IACzB,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,kCAAkC;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,yCAAyC;IACzC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,mCAAmC;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,yCAAyC;AACzC,MAAM,WAAW,kBAAkB;IACjC,uEAAuE;IACvE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,6DAA6D;IAC7D,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,8DAA8D;IAC9D,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;;;;GAQG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAsC;IAEpD,4CAA4C;IAC5C,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;IAMzC,wCAAwC;IACxC,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAKjC,2BAA2B;IAC3B,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAKxB,iCAAiC;IACjC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAIxB,2BAA2B;IAC3B,GAAG,IAAI,MAAM,EAAE;IAIf,8BAA8B;IAC9B,KAAK,IAAI,IAAI;IAKb;;;;;;;;;;;;;;;OAeG;IACH,cAAc,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,MAAM;IA0BpD;;;;OAIG;IACH,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,SAAS;CAM1E"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @ouraihub/llm — Tool Executor.
3
+ *
4
+ * Manages the multi-round tool calling loop using proper multi-turn
5
+ * message history (assistant tool_calls → tool results → assistant response).
6
+ *
7
+ * Flow:
8
+ * 1. Send prompt to LLM with tool definitions
9
+ * 2. If model requests tool calls:
10
+ * a. Execute each tool handler
11
+ * b. Append assistant message (with tool_calls) + tool result messages
12
+ * c. Re-send full conversation history to LLM
13
+ * 3. Repeat until model produces final text response (no more tool calls)
14
+ * 4. Validate final content against Zod schema
15
+ */
16
+ import type { z } from 'zod';
17
+ import type { ILLMProvider, IToolExecutor, LLMPrompt, ToolRegistration } from './interfaces.js';
18
+ import type { ILogger } from './logger.js';
19
+ /** Options for tool execution */
20
+ export interface ToolExecutorOptions {
21
+ readonly maxRounds?: number;
22
+ readonly logger?: ILogger;
23
+ }
24
+ export declare class ToolExecutor implements IToolExecutor {
25
+ private readonly tools;
26
+ private readonly logger;
27
+ constructor(options?: {
28
+ logger?: ILogger;
29
+ });
30
+ register(tools: readonly ToolRegistration[]): void;
31
+ completeWithTools<T>(provider: ILLMProvider, prompt: LLMPrompt, schema: z.ZodSchema<T>, options?: {
32
+ maxRounds?: number;
33
+ }): Promise<T>;
34
+ private executeTool;
35
+ /**
36
+ * Call LLM with native multi-turn messages API.
37
+ */
38
+ private callWithMessages;
39
+ private validateOutput;
40
+ }
41
+ //# sourceMappingURL=tool-executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-executor.d.ts","sourceRoot":"","sources":["../../src/tool-executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,SAAS,EAKT,gBAAgB,EACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAM3C,iCAAiC;AACjC,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,qBAAa,YAAa,YAAW,aAAa;IAChD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA4C;IAClE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;gBAErB,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE;IAI1C,QAAQ,CAAC,KAAK,EAAE,SAAS,gBAAgB,EAAE,GAAG,IAAI;IAO5C,iBAAiB,CAAC,CAAC,EACvB,QAAQ,EAAE,YAAY,EACtB,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EACtB,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAC/B,OAAO,CAAC,CAAC,CAAC;YA4DC,WAAW;IAoBzB;;OAEG;YACW,gBAAgB;IAgB9B,OAAO,CAAC,cAAc;CAwBvB"}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@ouraihub/llm",
3
+ "version": "0.2.0",
4
+ "description": "LLM provider abstraction — OpenAI-compatible & Anthropic, with structured output, tool calling, and timeout control",
5
+ "type": "module",
6
+ "main": "./dist/cjs/index.cjs",
7
+ "module": "./dist/esm/index.mjs",
8
+ "types": "./dist/types/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/types/index.d.ts",
12
+ "import": "./dist/esm/index.mjs",
13
+ "require": "./dist/cjs/index.cjs"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "keywords": [
20
+ "llm",
21
+ "openai",
22
+ "anthropic",
23
+ "ai",
24
+ "structured-output",
25
+ "cloudflare-workers"
26
+ ],
27
+ "author": "OurAI Hub",
28
+ "license": "MIT",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/ouraihub/ui-library.git",
32
+ "directory": "packages/llm"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "peerDependencies": {
38
+ "zod": "^3.22.0"
39
+ },
40
+ "devDependencies": {
41
+ "esbuild": "^0.28.1",
42
+ "typescript": "^6.0.3",
43
+ "vitest": "^4.1.10",
44
+ "zod": "^4.4.3"
45
+ },
46
+ "scripts": {
47
+ "build": "node build.js && tsc --emitDeclarationOnly",
48
+ "dev": "node build.js --watch",
49
+ "test": "vitest run",
50
+ "test:watch": "vitest",
51
+ "typecheck": "tsc --noEmit",
52
+ "clean": "rm -rf dist"
53
+ }
54
+ }