@yesvara/svara 0.1.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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +497 -0
  3. package/dist/chunk-CIESM3BP.mjs +33 -0
  4. package/dist/chunk-FEA5KIJN.mjs +418 -0
  5. package/dist/cli/index.d.mts +1 -0
  6. package/dist/cli/index.d.ts +1 -0
  7. package/dist/cli/index.js +328 -0
  8. package/dist/cli/index.mjs +39 -0
  9. package/dist/dev-OYGXXK2B.mjs +69 -0
  10. package/dist/index.d.mts +967 -0
  11. package/dist/index.d.ts +967 -0
  12. package/dist/index.js +1976 -0
  13. package/dist/index.mjs +1502 -0
  14. package/dist/new-7K4NIDZO.mjs +177 -0
  15. package/dist/retriever-4QY667XF.mjs +7 -0
  16. package/examples/01-basic/index.ts +26 -0
  17. package/examples/02-with-tools/index.ts +73 -0
  18. package/examples/03-rag-knowledge/index.ts +41 -0
  19. package/examples/04-multi-channel/index.ts +91 -0
  20. package/package.json +74 -0
  21. package/src/app/index.ts +176 -0
  22. package/src/channels/telegram.ts +122 -0
  23. package/src/channels/web.ts +118 -0
  24. package/src/channels/whatsapp.ts +161 -0
  25. package/src/cli/commands/dev.ts +87 -0
  26. package/src/cli/commands/new.ts +213 -0
  27. package/src/cli/index.ts +78 -0
  28. package/src/core/agent.ts +607 -0
  29. package/src/core/llm.ts +406 -0
  30. package/src/core/types.ts +183 -0
  31. package/src/database/schema.ts +79 -0
  32. package/src/database/sqlite.ts +239 -0
  33. package/src/index.ts +94 -0
  34. package/src/memory/context.ts +49 -0
  35. package/src/memory/conversation.ts +51 -0
  36. package/src/rag/chunker.ts +165 -0
  37. package/src/rag/loader.ts +216 -0
  38. package/src/rag/retriever.ts +248 -0
  39. package/src/tools/executor.ts +54 -0
  40. package/src/tools/index.ts +89 -0
  41. package/src/tools/registry.ts +44 -0
  42. package/src/types.ts +131 -0
  43. package/tsconfig.json +26 -0
package/src/types.ts ADDED
@@ -0,0 +1,131 @@
1
+ /**
2
+ * @module types
3
+ * Public types for @yesvara/svara
4
+ *
5
+ * These are the types users import and work with directly.
6
+ * Internal implementation types stay in core/types.ts.
7
+ */
8
+
9
+ import type { InternalAgentContext } from './core/types.js';
10
+
11
+ // ─── Tool ─────────────────────────────────────────────────────────────────────
12
+
13
+ /**
14
+ * A function the agent can call during a conversation.
15
+ *
16
+ * @example
17
+ * const weatherTool: Tool = {
18
+ * name: 'get_weather',
19
+ * description: 'Get the current weather for a city',
20
+ * parameters: {
21
+ * city: { type: 'string', description: 'The city name', required: true },
22
+ * },
23
+ * async run({ city }) {
24
+ * const data = await fetchWeather(city as string);
25
+ * return { temp: data.temp, condition: data.condition };
26
+ * },
27
+ * };
28
+ */
29
+ export interface Tool {
30
+ /** Unique identifier used by the LLM to call this tool. snake_case recommended. */
31
+ name: string;
32
+
33
+ /** What this tool does. The LLM uses this to decide when to call it. Be specific. */
34
+ description: string;
35
+
36
+ /**
37
+ * Input parameters the tool accepts.
38
+ * The LLM will fill these in based on the conversation.
39
+ */
40
+ parameters?: Record<string, ToolParameter>;
41
+
42
+ /**
43
+ * The function that runs when the LLM calls this tool.
44
+ * Return anything — it gets serialized and sent back to the LLM.
45
+ */
46
+ run(args: Record<string, unknown>, ctx: AgentContext): Promise<unknown>;
47
+
48
+ /** Group related tools together. Optional — used for organization. */
49
+ category?: string;
50
+
51
+ /** Timeout in milliseconds before the tool is cancelled. @default 30000 */
52
+ timeout?: number;
53
+ }
54
+
55
+ /**
56
+ * A single parameter definition for a tool.
57
+ *
58
+ * @example
59
+ * { type: 'string', description: 'City name', required: true }
60
+ * { type: 'number', description: 'Temperature in Celsius', required: false }
61
+ * { type: 'string', description: 'Status', enum: ['active', 'inactive'] }
62
+ */
63
+ export interface ToolParameter {
64
+ type: 'string' | 'number' | 'boolean' | 'object' | 'array';
65
+ description: string;
66
+ required?: boolean;
67
+ enum?: string[];
68
+ default?: unknown;
69
+ }
70
+
71
+ // ─── Agent Context ────────────────────────────────────────────────────────────
72
+
73
+ /**
74
+ * Context passed to tool `run()` functions.
75
+ * Gives tools access to session info and conversation history.
76
+ */
77
+ export type AgentContext = InternalAgentContext;
78
+
79
+ // ─── Agent Run ────────────────────────────────────────────────────────────────
80
+
81
+ /**
82
+ * The full result of a `agent.process()` call.
83
+ */
84
+ export interface ProcessResult {
85
+ /** The agent's response text. */
86
+ response: string;
87
+
88
+ /** The session ID used for this conversation. */
89
+ sessionId: string;
90
+
91
+ /** Names of tools called during this response. */
92
+ toolsUsed: string[];
93
+
94
+ /** Number of LLM iterations (tool call rounds) used. */
95
+ iterations: number;
96
+
97
+ /** Token usage for this request. */
98
+ usage: {
99
+ promptTokens: number;
100
+ completionTokens: number;
101
+ totalTokens: number;
102
+ };
103
+
104
+ /** Total time in milliseconds. */
105
+ duration: number;
106
+ }
107
+
108
+ // ─── Memory Options ───────────────────────────────────────────────────────────
109
+
110
+ /**
111
+ * Memory configuration for a SvaraAgent.
112
+ */
113
+ export interface MemoryOptions {
114
+ /** Number of previous messages to include in context. @default 20 */
115
+ window?: number;
116
+ }
117
+
118
+ // ─── App Options ──────────────────────────────────────────────────────────────
119
+
120
+ export type { AppOptions } from './app/index.js';
121
+
122
+ // ─── Channel Types ────────────────────────────────────────────────────────────
123
+
124
+ /**
125
+ * Supported channel names for `agent.connectChannel()`.
126
+ */
127
+ export type { ChannelName } from './core/types.js';
128
+
129
+ // ─── Re-exports for convenience ───────────────────────────────────────────────
130
+
131
+ export type { AgentConfig } from './core/agent.js';
package/tsconfig.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ES2022",
5
+ "moduleResolution": "bundler",
6
+ "lib": ["ES2022"],
7
+ "outDir": "dist",
8
+ "rootDir": "src",
9
+ "strict": true,
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "resolveJsonModule": true,
14
+ "declaration": true,
15
+ "declarationMap": true,
16
+ "sourceMap": true,
17
+ "experimentalDecorators": true,
18
+ "emitDecoratorMetadata": true,
19
+ "baseUrl": ".",
20
+ "paths": {
21
+ "@svara/*": ["src/*"]
22
+ }
23
+ },
24
+ "include": ["src/**/*"],
25
+ "exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.spec.ts"]
26
+ }