@tabbybyte/kimten 0.1.4 → 0.1.5

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.
package/index.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ import type { ZodTypeAny, infer as ZodInfer } from 'zod';
2
+
3
+ export type BrainModel = Record<string, unknown>;
4
+
5
+ export type ToyFn = (args: any) => any | Promise<any>;
6
+
7
+ export type ToyDefinition = {
8
+ inputSchema?: ZodTypeAny;
9
+ description?: string;
10
+ strict?: boolean;
11
+ execute: ToyFn;
12
+ };
13
+
14
+ export type Toys = Record<string, ToyFn | ToyDefinition>;
15
+
16
+ export type KimtenConfig = {
17
+ brain: BrainModel;
18
+ toys?: Toys;
19
+ personality?: string;
20
+ hops?: number;
21
+ };
22
+
23
+ export type KimtenAgent = {
24
+ play(input: string): Promise<string>;
25
+ play<S extends ZodTypeAny>(input: string, schema: S): Promise<ZodInfer<S>>;
26
+ forget(): void;
27
+ };
28
+
29
+ export declare function Kimten(config: KimtenConfig): KimtenAgent;
30
+
31
+ declare const _default: typeof Kimten;
32
+ export default _default;
33
+
package/index.js CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @module @tabbybyte/kimten
3
+ *
4
+ * Public entrypoint for Kimten.
5
+ */
1
6
  import { Kimten } from './lib/kimten.js';
2
7
 
3
8
  export { Kimten };
package/lib/kimten.js CHANGED
@@ -5,6 +5,65 @@ import { normalizeToys } from './tools.js';
5
5
 
6
6
  const DEFAULT_PERSONALITY = 'You are a helpful assistant.';
7
7
 
8
+ /**
9
+ * @typedef {import('zod').ZodTypeAny} ZodSchema
10
+ */
11
+
12
+ /**
13
+ * A minimal AI SDK model-like object accepted by Kimten.
14
+ *
15
+ * This is intentionally loose to avoid coupling Kimten to AI SDK internal types,
16
+ * while still providing useful IDE hints.
17
+ *
18
+ * @typedef {object} BrainModel
19
+ * @property {string} [specificationVersion]
20
+ * @property {string} [provider]
21
+ * @property {string} [modelId]
22
+ * @property {Record<string, unknown>} [supportedUrls]
23
+ */
24
+
25
+ /**
26
+ * Shorthand tool form: any async/sync function.
27
+ *
28
+ * @callback ToyFn
29
+ * @param {any} args
30
+ * @returns {any | Promise<any>}
31
+ */
32
+
33
+ /**
34
+ * Object-form tool definition.
35
+ *
36
+ * @typedef {object} ToyDefinition
37
+ * @property {import('zod').ZodTypeAny} [inputSchema]
38
+ * @property {string} [description]
39
+ * @property {boolean} [strict]
40
+ * @property {ToyFn} execute
41
+ */
42
+
43
+ /**
44
+ * Tool registry map.
45
+ *
46
+ * @typedef {Record<string, ToyFn | ToyDefinition>} Toys
47
+ */
48
+
49
+ /**
50
+ * Kimten factory config.
51
+ *
52
+ * @typedef {object} KimtenConfig
53
+ * @property {BrainModel} brain AI SDK model instance.
54
+ * @property {Toys} [toys] Tool registry.
55
+ * @property {string} [personality] System prompt / instructions.
56
+ * @property {number} [hops] Max loop steps (prevents infinite loops).
57
+ */
58
+
59
+ /**
60
+ * Returned Kimten instance.
61
+ *
62
+ * @typedef {object} KimtenAgent
63
+ * @property {(input: string, schema?: ZodSchema | null) => Promise<any>} play Run the agent loop.
64
+ * @property {() => void} forget Clear short-term memory.
65
+ */
66
+
8
67
  function validateConfig(config) {
9
68
  if (config === null || typeof config !== 'object' || Array.isArray(config)) {
10
69
  throw new TypeError('Kimten requires a config object.');
@@ -33,6 +92,12 @@ function validateConfig(config) {
33
92
  };
34
93
  }
35
94
 
95
+ /**
96
+ * Create a tiny tool-using agent with short-term memory.
97
+ *
98
+ * @param {KimtenConfig} config
99
+ * @returns {KimtenAgent}
100
+ */
36
101
  export function Kimten(config) {
37
102
  const { brain, toys, personality, hops } = validateConfig(config);
38
103
  const memory = createMemory();
@@ -71,6 +136,16 @@ export function Kimten(config) {
71
136
  return createStructuredAgent(schema);
72
137
  }
73
138
 
139
+ /**
140
+ * Run the agent loop.
141
+ *
142
+ * - Stores the conversation in short-term memory (in-process, per instance).
143
+ * - If `schema` is provided, returns structured output (via AI SDK output mode).
144
+ *
145
+ * @param {string} input
146
+ * @param {ZodSchema | null} [schema]
147
+ * @returns {Promise<any>}
148
+ */
74
149
  async function play(input, schema = null) {
75
150
  if (typeof input !== 'string') {
76
151
  throw new TypeError('Kimten play(input) expects input to be a string.');
@@ -95,6 +170,11 @@ export function Kimten(config) {
95
170
  return schema ? result.output : assistantContent;
96
171
  }
97
172
 
173
+ /**
174
+ * Clear short-term memory for this instance.
175
+ *
176
+ * @returns {void}
177
+ */
98
178
  function forget() {
99
179
  memory.clear();
100
180
  }
package/lib/memory.js CHANGED
@@ -1,8 +1,32 @@
1
1
  export const MEMORY_LIMIT = 10;
2
2
 
3
+ /**
4
+ * A single chat message stored in short-term memory.
5
+ *
6
+ * @typedef {object} MemoryMessage
7
+ * @property {'system' | 'user' | 'assistant' | 'tool'} role
8
+ * @property {any} content
9
+ */
10
+
11
+ /**
12
+ * Short-term FIFO memory store (sliding window).
13
+ *
14
+ * @typedef {object} MemoryStore
15
+ * @property {(message: MemoryMessage) => void} add
16
+ * @property {() => MemoryMessage[]} list
17
+ * @property {() => void} clear
18
+ */
19
+
20
+ /**
21
+ * Create a short-term FIFO memory store.
22
+ *
23
+ * @param {number} [limit=MEMORY_LIMIT] Max number of messages to keep.
24
+ * @returns {MemoryStore}
25
+ */
3
26
  export function createMemory(limit = MEMORY_LIMIT) {
4
27
  const history = [];
5
28
 
29
+ /** @param {MemoryMessage} message */
6
30
  function add(message) {
7
31
  history.push(message);
8
32
  if (history.length > limit) {
package/lib/prompt.js CHANGED
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Build AI SDK messages for a generation call.
3
+ *
4
+ * @param {string} personality System prompt / instructions.
5
+ * @param {Array<{ role: string, content: any }>} history Prior conversation messages.
6
+ * @returns {Array<{ role: string, content: any }>}
7
+ */
1
8
  export function buildMessages(personality, history) {
2
9
  return [
3
10
  { role: 'system', content: personality },
package/lib/tools.js CHANGED
@@ -1,6 +1,34 @@
1
1
  import { tool } from 'ai';
2
2
  import { z } from 'zod';
3
3
 
4
+ /**
5
+ * @typedef {import('zod').ZodTypeAny} ZodSchema
6
+ */
7
+
8
+ /**
9
+ * Shorthand tool form: any async/sync function.
10
+ *
11
+ * @callback ToyFn
12
+ * @param {any} args
13
+ * @returns {any | Promise<any>}
14
+ */
15
+
16
+ /**
17
+ * Object-form tool definition.
18
+ *
19
+ * @typedef {object} ToyDefinition
20
+ * @property {ZodSchema} [inputSchema]
21
+ * @property {string} [description]
22
+ * @property {boolean} [strict]
23
+ * @property {ToyFn} execute
24
+ */
25
+
26
+ /**
27
+ * Tool registry map.
28
+ *
29
+ * @typedef {Record<string, ToyFn | ToyDefinition>} Toys
30
+ */
31
+
4
32
  function isPlainObject(value) {
5
33
  if (value === null || typeof value !== 'object' || Array.isArray(value)) {
6
34
  return false;
@@ -10,6 +38,18 @@ function isPlainObject(value) {
10
38
  return proto === Object.prototype || proto === null;
11
39
  }
12
40
 
41
+ /**
42
+ * Normalize a toy registry into AI SDK tool objects.
43
+ *
44
+ * - Shorthand entry: `async (args) => result`
45
+ * - Object form: `{ inputSchema?, description?, strict?, execute }`
46
+ *
47
+ * Tool execution is wrapped so thrown errors become JSON-safe results:
48
+ * `{ error, toolName }` (Kimten does not re-throw tool errors).
49
+ *
50
+ * @param {Toys | null | undefined} toys
51
+ * @returns {Record<string, ReturnType<typeof tool>>}
52
+ */
13
53
  export function normalizeToys(toys) {
14
54
  if (toys === undefined || toys === null) {
15
55
  return {};
package/package.json CHANGED
@@ -1,17 +1,22 @@
1
1
  {
2
2
  "name": "@tabbybyte/kimten",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
7
  "description": "A micro-agent library: thin wrapper over the Agent interface from Vercel's AI SDK Core v6+",
8
8
  "type": "module",
9
9
  "main": "index.js",
10
+ "types": "index.d.ts",
10
11
  "exports": {
11
- ".": "./index.js"
12
+ ".": {
13
+ "types": "./index.d.ts",
14
+ "default": "./index.js"
15
+ }
12
16
  },
13
17
  "files": [
14
18
  "index.js",
19
+ "index.d.ts",
15
20
  "lib"
16
21
  ],
17
22
  "scripts": {