@vistagenic/vista 0.2.16 → 0.3.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 (152) hide show
  1. package/bin/vista.js +184 -177
  2. package/dist/ai/agent.d.ts +37 -0
  3. package/dist/ai/agent.js +385 -0
  4. package/dist/ai/embeddings.d.ts +11 -0
  5. package/dist/ai/embeddings.js +71 -0
  6. package/dist/ai/index.d.ts +10 -0
  7. package/dist/ai/index.js +26 -0
  8. package/dist/ai/memory.d.ts +16 -0
  9. package/dist/ai/memory.js +39 -0
  10. package/dist/ai/observability.d.ts +21 -0
  11. package/dist/ai/observability.js +69 -0
  12. package/dist/ai/providers/anthropic.d.ts +2 -0
  13. package/dist/ai/providers/anthropic.js +190 -0
  14. package/dist/ai/providers/base.d.ts +7 -0
  15. package/dist/ai/providers/base.js +85 -0
  16. package/dist/ai/providers/gemini.d.ts +2 -0
  17. package/dist/ai/providers/gemini.js +194 -0
  18. package/dist/ai/providers/index.d.ts +5 -0
  19. package/dist/ai/providers/index.js +21 -0
  20. package/dist/ai/providers/mock.d.ts +8 -0
  21. package/dist/ai/providers/mock.js +77 -0
  22. package/dist/ai/providers/openai.d.ts +2 -0
  23. package/dist/ai/providers/openai.js +211 -0
  24. package/dist/ai/rag.d.ts +35 -0
  25. package/dist/ai/rag.js +110 -0
  26. package/dist/ai/react/index.d.ts +1 -0
  27. package/dist/ai/react/index.js +17 -0
  28. package/dist/ai/react/react-server.d.ts +1 -0
  29. package/dist/ai/react/react-server.js +17 -0
  30. package/dist/ai/react/use-agent.d.ts +23 -0
  31. package/dist/ai/react/use-agent.js +138 -0
  32. package/dist/ai/stream.d.ts +24 -0
  33. package/dist/ai/stream.js +109 -0
  34. package/dist/ai/tool.d.ts +11 -0
  35. package/dist/ai/tool.js +47 -0
  36. package/dist/ai/types.d.ts +117 -0
  37. package/dist/ai/types.js +5 -0
  38. package/dist/auth/core.d.ts +140 -0
  39. package/dist/auth/core.js +165 -0
  40. package/dist/auth/index.d.ts +20 -8
  41. package/dist/auth/index.js +369 -16
  42. package/dist/auth/react-server.d.ts +1 -0
  43. package/dist/auth/react-server.js +10 -0
  44. package/dist/auth/react.d.ts +18 -0
  45. package/dist/auth/react.js +71 -0
  46. package/dist/bin/build-rsc.js +602 -604
  47. package/dist/bin/build.js +389 -388
  48. package/dist/bin/deploy-output.d.ts +2 -7
  49. package/dist/bin/deploy-output.js +3 -76
  50. package/dist/bin/deploy.d.ts +7 -0
  51. package/dist/bin/deploy.js +102 -0
  52. package/dist/bin/dev-error-overlay-snippet.js +552 -552
  53. package/dist/bin/devtools-indicator-snippet.js +387 -387
  54. package/dist/bin/generate.js +510 -248
  55. package/dist/build/manifest.d.ts +169 -139
  56. package/dist/build/manifest.js +423 -367
  57. package/dist/build/rsc/client-manifest.d.ts +62 -52
  58. package/dist/build/rsc/client-manifest.js +295 -193
  59. package/dist/build/rsc/client-reference-plugin.d.ts +37 -37
  60. package/dist/build/rsc/client-reference-plugin.js +160 -160
  61. package/dist/build/rsc/native-scanner.d.ts +135 -123
  62. package/dist/build/rsc/native-scanner.js +203 -170
  63. package/dist/build/rsc/react-client-reference-manifest.d.ts +28 -22
  64. package/dist/build/rsc/react-client-reference-manifest.js +240 -219
  65. package/dist/build/rsc/rsc-renderer.d.ts +99 -99
  66. package/dist/build/rsc/rsc-renderer.js +263 -263
  67. package/dist/build/rsc/server-component-loader.d.ts +19 -19
  68. package/dist/build/rsc/server-component-loader.js +91 -91
  69. package/dist/build/rsc/server-manifest.d.ts +17 -0
  70. package/dist/build/rsc/server-manifest.js +20 -0
  71. package/dist/build/standalone.js +337 -334
  72. package/dist/build/webpack/plugins/vista-flight-plugin.js +5 -5
  73. package/dist/client/dynamic.react-server.d.ts +2 -0
  74. package/dist/client/dynamic.react-server.js +23 -0
  75. package/dist/client/link.react-server.d.ts +2 -0
  76. package/dist/client/link.react-server.js +11 -0
  77. package/dist/client/navigation.react-server.d.ts +1 -0
  78. package/dist/client/navigation.react-server.js +17 -0
  79. package/dist/client/router.react-server.d.ts +1 -0
  80. package/dist/client/router.react-server.js +17 -0
  81. package/dist/client/rsc-router.react-server.d.ts +1 -0
  82. package/dist/client/rsc-router.react-server.js +17 -0
  83. package/dist/client/script.react-server.d.ts +2 -0
  84. package/dist/client/script.react-server.js +23 -0
  85. package/dist/components/client-island.d.ts +34 -34
  86. package/dist/components/client-island.js +75 -75
  87. package/dist/config.d.ts +17 -0
  88. package/dist/config.js +60 -1
  89. package/dist/deploy/adapters/cloudflare.d.ts +2 -0
  90. package/dist/deploy/adapters/cloudflare.js +124 -0
  91. package/dist/deploy/adapters/docker.d.ts +2 -0
  92. package/dist/deploy/adapters/docker.js +112 -0
  93. package/dist/deploy/adapters/index.d.ts +15 -0
  94. package/dist/deploy/adapters/index.js +24 -0
  95. package/dist/deploy/adapters/netlify.d.ts +2 -0
  96. package/dist/deploy/adapters/netlify.js +115 -0
  97. package/dist/deploy/adapters/render.d.ts +2 -0
  98. package/dist/deploy/adapters/render.js +95 -0
  99. package/dist/deploy/adapters/vercel.d.ts +7 -0
  100. package/dist/deploy/adapters/vercel.js +164 -0
  101. package/dist/deploy/cli-runner.d.ts +8 -0
  102. package/dist/deploy/cli-runner.js +58 -0
  103. package/dist/deploy/detect.d.ts +6 -0
  104. package/dist/deploy/detect.js +77 -0
  105. package/dist/deploy/index.d.ts +24 -0
  106. package/dist/deploy/index.js +112 -0
  107. package/dist/deploy/preflight.d.ts +8 -0
  108. package/dist/deploy/preflight.js +80 -0
  109. package/dist/deploy/types.d.ts +48 -0
  110. package/dist/deploy/types.js +2 -0
  111. package/dist/deploy/utils.d.ts +18 -0
  112. package/dist/deploy/utils.js +70 -0
  113. package/dist/dev-error.js +667 -667
  114. package/dist/index.d.ts +23 -21
  115. package/dist/index.js +61 -57
  116. package/dist/server/cookie-parse.d.ts +4 -0
  117. package/dist/server/cookie-parse.js +14 -0
  118. package/dist/server/engine.js +6 -19
  119. package/dist/server/index.d.ts +109 -102
  120. package/dist/server/index.js +315 -286
  121. package/dist/server/middleware-runner.d.ts +125 -57
  122. package/dist/server/middleware-runner.js +615 -218
  123. package/dist/server/middleware-security.d.ts +36 -0
  124. package/dist/server/middleware-security.js +183 -0
  125. package/dist/server/module-compile-hook.js +695 -662
  126. package/dist/server/route-handler-registry.d.ts +65 -0
  127. package/dist/server/route-handler-registry.js +195 -0
  128. package/dist/server/route-patterns.d.ts +67 -0
  129. package/dist/server/route-patterns.js +186 -0
  130. package/dist/server/rsc-engine.js +73 -80
  131. package/dist/server/rsc-module-system.d.ts +33 -33
  132. package/dist/server/rsc-module-system.js +87 -87
  133. package/dist/server/rsc-upstream.js +892 -888
  134. package/dist/server/static-generator.js +10 -10
  135. package/dist/server/typed-api-runtime.d.ts +18 -0
  136. package/dist/server/typed-api-runtime.js +635 -507
  137. package/dist/server/vista-import-map.js +134 -123
  138. package/dist/stack/index.d.ts +34 -32
  139. package/dist/stack/index.js +49 -45
  140. package/dist/stack/server/caller.d.ts +13 -0
  141. package/dist/stack/server/caller.js +42 -0
  142. package/dist/stack/server/executor.d.ts +40 -36
  143. package/dist/stack/server/executor.js +222 -174
  144. package/dist/stack/server/index.d.ts +11 -10
  145. package/dist/stack/server/index.js +24 -23
  146. package/dist/stack/server/procedure.d.ts +20 -18
  147. package/dist/stack/server/procedure.js +66 -58
  148. package/dist/stack/server/types.d.ts +113 -100
  149. package/dist/theme/react-server.d.ts +10 -0
  150. package/dist/theme/react-server.js +16 -0
  151. package/package.json +178 -153
  152. package/LICENSE +0 -21
@@ -0,0 +1,385 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Agent = void 0;
4
+ exports.agent = agent;
5
+ const base_1 = require("./providers/base");
6
+ const memory_1 = require("./memory");
7
+ const stream_1 = require("./stream");
8
+ const observability_1 = require("./observability");
9
+ const tool_1 = require("./tool");
10
+ class Agent {
11
+ name;
12
+ model;
13
+ config;
14
+ toolsMap;
15
+ memory;
16
+ constructor(config) {
17
+ if (!config.name || typeof config.name !== 'string') {
18
+ throw new Error('Agent must have a valid string name');
19
+ }
20
+ this.name = config.name;
21
+ this.config = config;
22
+ this.model = (0, base_1.resolveModel)(config.model);
23
+ // Initialize tools lookup
24
+ this.toolsMap = new Map();
25
+ if (config.tools) {
26
+ for (const t of config.tools) {
27
+ if (t && typeof t.name === 'string') {
28
+ this.toolsMap.set(t.name, t);
29
+ }
30
+ }
31
+ }
32
+ // Initialize memory store
33
+ if (config.memory === true) {
34
+ this.memory = memory_1.defaultMemoryStore;
35
+ }
36
+ else if (typeof config.memory === 'object' && config.memory !== null) {
37
+ this.memory = config.memory;
38
+ }
39
+ }
40
+ async resolveSystemPrompt() {
41
+ if (typeof this.config.systemPrompt === 'function') {
42
+ return await this.config.systemPrompt();
43
+ }
44
+ return this.config.systemPrompt;
45
+ }
46
+ normalizeInput(input) {
47
+ if (typeof input === 'string') {
48
+ return { messages: [{ role: 'user', content: input }] };
49
+ }
50
+ if (Array.isArray(input)) {
51
+ return { messages: [...input] };
52
+ }
53
+ const messages = input.messages ? [...input.messages] : [];
54
+ if (input.prompt) {
55
+ messages.push({ role: 'user', content: input.prompt });
56
+ }
57
+ return {
58
+ messages,
59
+ sessionId: input.sessionId,
60
+ abortSignal: input.abortSignal,
61
+ };
62
+ }
63
+ /**
64
+ * Run the agent through a multi-step reasoning and tool-execution loop.
65
+ */
66
+ async run(input) {
67
+ const { messages: incomingMessages, sessionId, abortSignal } = this.normalizeInput(input);
68
+ const telemetry = new observability_1.AgentTelemetry(this.config.observability);
69
+ telemetry.start();
70
+ // Load memory history if session provided
71
+ let conversationHistory = [];
72
+ if (this.memory && sessionId) {
73
+ const stored = await this.memory.get(sessionId);
74
+ conversationHistory = [...stored];
75
+ }
76
+ conversationHistory.push(...incomingMessages);
77
+ const systemPrompt = await this.resolveSystemPrompt();
78
+ const maxSteps = this.config.maxSteps || 5;
79
+ const toolsList = Array.from(this.toolsMap.values());
80
+ const steps = [];
81
+ let currentStep = 1;
82
+ let finalAnswer = '';
83
+ let finishReason = 'stop';
84
+ while (currentStep <= maxSteps) {
85
+ if (abortSignal?.aborted) {
86
+ throw new Error('Agent execution aborted');
87
+ }
88
+ telemetry.recordStepStart(currentStep);
89
+ const stepResult = await this.model.generateText({
90
+ messages: conversationHistory,
91
+ systemPrompt,
92
+ tools: toolsList.length > 0 ? toolsList : undefined,
93
+ temperature: this.config.temperature,
94
+ maxTokens: this.config.maxTokens,
95
+ abortSignal,
96
+ });
97
+ const stepRecord = {
98
+ stepNumber: currentStep,
99
+ prompt: [...conversationHistory],
100
+ text: stepResult.text,
101
+ toolCalls: stepResult.toolCalls,
102
+ usage: stepResult.usage,
103
+ };
104
+ // 1. If no tool calls requested, we have reached the final answer
105
+ if (!stepResult.toolCalls || stepResult.toolCalls.length === 0) {
106
+ finalAnswer = stepResult.text;
107
+ finishReason = stepResult.finishReason || 'stop';
108
+ conversationHistory.push({
109
+ role: 'assistant',
110
+ content: finalAnswer,
111
+ });
112
+ telemetry.recordStepFinish(stepRecord);
113
+ steps.push(stepRecord);
114
+ if (this.config.onStepFinish) {
115
+ await this.config.onStepFinish(stepRecord);
116
+ }
117
+ break;
118
+ }
119
+ // 2. Model requested tool calls
120
+ conversationHistory.push({
121
+ role: 'assistant',
122
+ content: stepResult.text,
123
+ toolCalls: stepResult.toolCalls,
124
+ });
125
+ const toolResults = [];
126
+ for (const call of stepResult.toolCalls) {
127
+ telemetry.recordToolCall(call);
128
+ const registeredTool = this.toolsMap.get(call.name);
129
+ if (!registeredTool) {
130
+ const errRes = {
131
+ toolCallId: call.id,
132
+ name: call.name,
133
+ result: `Error: Tool "${call.name}" is not registered on agent "${this.name}".`,
134
+ isError: true,
135
+ };
136
+ toolResults.push(errRes);
137
+ telemetry.recordToolResult(errRes);
138
+ conversationHistory.push({
139
+ role: 'tool',
140
+ name: call.name,
141
+ toolCallId: call.id,
142
+ content: errRes.result,
143
+ });
144
+ continue;
145
+ }
146
+ const toolCtx = {
147
+ step: currentStep,
148
+ messages: conversationHistory,
149
+ agentName: this.name,
150
+ abortSignal,
151
+ };
152
+ try {
153
+ const args = typeof call.arguments === 'object' && call.arguments !== null
154
+ ? call.arguments
155
+ : typeof call.arguments === 'string'
156
+ ? JSON.parse(call.arguments || '{}')
157
+ : {};
158
+ const rawOutput = await registeredTool.execute(args, toolCtx);
159
+ const serializedOutput = typeof rawOutput === 'string' ? rawOutput : JSON.stringify(rawOutput);
160
+ const successRes = {
161
+ toolCallId: call.id,
162
+ name: call.name,
163
+ result: rawOutput,
164
+ };
165
+ toolResults.push(successRes);
166
+ telemetry.recordToolResult(successRes);
167
+ conversationHistory.push({
168
+ role: 'tool',
169
+ name: call.name,
170
+ toolCallId: call.id,
171
+ content: serializedOutput,
172
+ });
173
+ }
174
+ catch (toolError) {
175
+ const errMessage = toolError?.message || 'Tool execution failed';
176
+ const failureRes = {
177
+ toolCallId: call.id,
178
+ name: call.name,
179
+ result: `Error executing ${call.name}: ${errMessage}`,
180
+ isError: true,
181
+ };
182
+ toolResults.push(failureRes);
183
+ telemetry.recordToolResult(failureRes);
184
+ conversationHistory.push({
185
+ role: 'tool',
186
+ name: call.name,
187
+ toolCallId: call.id,
188
+ content: failureRes.result,
189
+ });
190
+ }
191
+ }
192
+ stepRecord.toolResults = toolResults;
193
+ telemetry.recordStepFinish(stepRecord);
194
+ steps.push(stepRecord);
195
+ if (this.config.onStepFinish) {
196
+ await this.config.onStepFinish(stepRecord);
197
+ }
198
+ currentStep++;
199
+ if (currentStep > maxSteps) {
200
+ finishReason = 'length';
201
+ finalAnswer =
202
+ stepResult.text ||
203
+ `Agent reached maximum step limit (${maxSteps}) before arriving at final answer.`;
204
+ }
205
+ }
206
+ // Save updated memory if configured
207
+ if (this.memory && sessionId) {
208
+ await this.memory.save(sessionId, conversationHistory);
209
+ }
210
+ const metrics = telemetry.finish();
211
+ return {
212
+ text: finalAnswer,
213
+ messages: conversationHistory,
214
+ steps,
215
+ usage: metrics.totalUsage,
216
+ finishReason,
217
+ };
218
+ }
219
+ /**
220
+ * Stream the agent's response, yielding real-time text deltas and tool events.
221
+ */
222
+ stream(input) {
223
+ const self = this;
224
+ const { messages: incomingMessages, sessionId, abortSignal } = this.normalizeInput(input);
225
+ async function* streamGenerator() {
226
+ // For streaming, we run the agent steps and yield incremental events
227
+ let conversationHistory = [];
228
+ if (self.memory && sessionId) {
229
+ const stored = await self.memory.get(sessionId);
230
+ conversationHistory = [...stored];
231
+ }
232
+ conversationHistory.push(...incomingMessages);
233
+ const systemPrompt = await self.resolveSystemPrompt();
234
+ const maxSteps = self.config.maxSteps || 5;
235
+ const toolsList = Array.from(self.toolsMap.values());
236
+ let currentStep = 1;
237
+ const totalUsage = { promptTokens: 0, completionTokens: 0, totalTokens: 0 };
238
+ while (currentStep <= maxSteps) {
239
+ if (abortSignal?.aborted) {
240
+ yield { type: 'error', error: 'Agent execution aborted' };
241
+ return;
242
+ }
243
+ // Stream from the underlying model
244
+ const chunks = [];
245
+ let accumulatedText = '';
246
+ const toolCalls = [];
247
+ for await (const chunk of self.model.streamText({
248
+ messages: conversationHistory,
249
+ systemPrompt,
250
+ tools: toolsList.length > 0 ? toolsList : undefined,
251
+ temperature: self.config.temperature,
252
+ maxTokens: self.config.maxTokens,
253
+ abortSignal,
254
+ })) {
255
+ if (chunk.type === 'text-delta' && chunk.textDelta) {
256
+ accumulatedText += chunk.textDelta;
257
+ yield chunk;
258
+ }
259
+ else if (chunk.type === 'tool-call' && chunk.toolCall) {
260
+ toolCalls.push(chunk.toolCall);
261
+ yield chunk;
262
+ }
263
+ else if (chunk.type === 'done' && chunk.usage) {
264
+ totalUsage.promptTokens += chunk.usage.promptTokens;
265
+ totalUsage.completionTokens += chunk.usage.completionTokens;
266
+ totalUsage.totalTokens += chunk.usage.totalTokens;
267
+ }
268
+ }
269
+ // If no tool calls, generation is complete
270
+ if (toolCalls.length === 0) {
271
+ conversationHistory.push({
272
+ role: 'assistant',
273
+ content: accumulatedText,
274
+ });
275
+ yield { type: 'step-finish' };
276
+ break;
277
+ }
278
+ // Handle tool calls
279
+ conversationHistory.push({
280
+ role: 'assistant',
281
+ content: accumulatedText,
282
+ toolCalls,
283
+ });
284
+ for (const call of toolCalls) {
285
+ const registeredTool = self.toolsMap.get(call.name);
286
+ if (!registeredTool) {
287
+ const errRes = {
288
+ toolCallId: call.id,
289
+ name: call.name,
290
+ result: `Tool "${call.name}" not found`,
291
+ isError: true,
292
+ };
293
+ yield { type: 'tool-result', toolResult: errRes };
294
+ conversationHistory.push({
295
+ role: 'tool',
296
+ name: call.name,
297
+ toolCallId: call.id,
298
+ content: errRes.result,
299
+ });
300
+ continue;
301
+ }
302
+ try {
303
+ const args = typeof call.arguments === 'object' && call.arguments !== null
304
+ ? call.arguments
305
+ : typeof call.arguments === 'string'
306
+ ? JSON.parse(call.arguments || '{}')
307
+ : {};
308
+ const result = await registeredTool.execute(args, {
309
+ step: currentStep,
310
+ messages: conversationHistory,
311
+ agentName: self.name,
312
+ abortSignal,
313
+ });
314
+ const serialized = typeof result === 'string' ? result : JSON.stringify(result);
315
+ yield {
316
+ type: 'tool-result',
317
+ toolResult: { toolCallId: call.id, name: call.name, result },
318
+ };
319
+ conversationHistory.push({
320
+ role: 'tool',
321
+ name: call.name,
322
+ toolCallId: call.id,
323
+ content: serialized,
324
+ });
325
+ }
326
+ catch (err) {
327
+ const errRes = {
328
+ toolCallId: call.id,
329
+ name: call.name,
330
+ result: err?.message || 'Tool execution error',
331
+ isError: true,
332
+ };
333
+ yield { type: 'tool-result', toolResult: errRes };
334
+ conversationHistory.push({
335
+ role: 'tool',
336
+ name: call.name,
337
+ toolCallId: call.id,
338
+ content: errRes.result,
339
+ });
340
+ }
341
+ }
342
+ yield { type: 'step-finish' };
343
+ currentStep++;
344
+ }
345
+ if (self.memory && sessionId) {
346
+ await self.memory.save(sessionId, conversationHistory);
347
+ }
348
+ yield { type: 'done', usage: totalUsage };
349
+ }
350
+ return new stream_1.AgentStream(streamGenerator());
351
+ }
352
+ /**
353
+ * Composes this agent as a callable Tool for another agent (multi-agent hierarchy).
354
+ */
355
+ asTool(options) {
356
+ const toolName = options?.name || `ask_${this.name.toLowerCase().replace(/[^a-z0-9_]/g, '_')}`;
357
+ const toolDescription = options?.description ||
358
+ `Delegate a question, task, or request to the specialized ${this.name} agent.`;
359
+ return (0, tool_1.tool)({
360
+ name: toolName,
361
+ description: toolDescription,
362
+ parameters: {
363
+ type: 'object',
364
+ properties: {
365
+ query: {
366
+ type: 'string',
367
+ description: `The query or instruction to give to the ${this.name} agent`,
368
+ },
369
+ },
370
+ required: ['query'],
371
+ },
372
+ execute: async ({ query }) => {
373
+ const result = await this.run(query);
374
+ return result.text;
375
+ },
376
+ });
377
+ }
378
+ }
379
+ exports.Agent = Agent;
380
+ /**
381
+ * Creates a Vista AI Agent instance.
382
+ */
383
+ function agent(config) {
384
+ return new Agent(config);
385
+ }
@@ -0,0 +1,11 @@
1
+ export interface EmbedOptions {
2
+ model?: string;
3
+ apiKey?: string;
4
+ baseURL?: string;
5
+ }
6
+ export declare function embedTexts(texts: string[], options?: EmbedOptions): Promise<number[][]>;
7
+ export declare function embedText(text: string, options?: EmbedOptions): Promise<number[]>;
8
+ export declare function createEmbeddings(options?: EmbedOptions): {
9
+ embedText: (text: string) => Promise<number[]>;
10
+ embedTexts: (texts: string[]) => Promise<number[][]>;
11
+ };
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.embedTexts = embedTexts;
4
+ exports.embedText = embedText;
5
+ exports.createEmbeddings = createEmbeddings;
6
+ const base_1 = require("./providers/base");
7
+ function resolveEmbedTarget(options = {}) {
8
+ const identifier = (0, base_1.parseModelIdentifier)(options.model || 'openai:text-embedding-3-small');
9
+ const provider = identifier.provider;
10
+ const modelName = identifier.modelName || 'text-embedding-3-small';
11
+ if (provider === 'nvidia' || provider === 'nim') {
12
+ return {
13
+ modelName,
14
+ baseURL: (options.baseURL ||
15
+ process.env.NVIDIA_BASE_URL ||
16
+ process.env.NIM_BASE_URL ||
17
+ 'https://integrate.api.nvidia.com/v1').replace(/\/+$/, ''),
18
+ apiKey: options.apiKey || process.env.NVIDIA_API_KEY || process.env.NIM_API_KEY || '',
19
+ };
20
+ }
21
+ if (provider === 'groq') {
22
+ return {
23
+ modelName,
24
+ baseURL: (options.baseURL || process.env.GROQ_BASE_URL || 'https://api.groq.com/openai/v1').replace(/\/+$/, ''),
25
+ apiKey: options.apiKey || process.env.GROQ_API_KEY || '',
26
+ };
27
+ }
28
+ if (provider === 'ollama') {
29
+ return {
30
+ modelName,
31
+ baseURL: (options.baseURL || process.env.OLLAMA_BASE_URL || 'http://localhost:11434/v1').replace(/\/+$/, ''),
32
+ apiKey: options.apiKey || 'ollama',
33
+ };
34
+ }
35
+ return {
36
+ modelName,
37
+ baseURL: (options.baseURL || process.env.OPENAI_BASE_URL || 'https://api.openai.com/v1').replace(/\/+$/, ''),
38
+ apiKey: options.apiKey || process.env.OPENAI_API_KEY || '',
39
+ };
40
+ }
41
+ async function embedTexts(texts, options = {}) {
42
+ const target = resolveEmbedTarget(options);
43
+ const response = await fetch(`${target.baseURL}/embeddings`, {
44
+ method: 'POST',
45
+ headers: {
46
+ 'Content-Type': 'application/json',
47
+ ...(target.apiKey ? { Authorization: `Bearer ${target.apiKey}` } : {}),
48
+ },
49
+ body: JSON.stringify({
50
+ model: target.modelName,
51
+ input: texts,
52
+ }),
53
+ });
54
+ if (!response.ok) {
55
+ const detail = await response.text().catch(() => '');
56
+ throw new Error(`Embedding request failed (${response.status}): ${detail || response.statusText}`);
57
+ }
58
+ const json = (await response.json());
59
+ const rows = [...(json.data || [])].sort((left, right) => (left.index || 0) - (right.index || 0));
60
+ return rows.map((row) => row.embedding || []);
61
+ }
62
+ async function embedText(text, options = {}) {
63
+ const [vector] = await embedTexts([text], options);
64
+ return vector || [];
65
+ }
66
+ function createEmbeddings(options = {}) {
67
+ return {
68
+ embedText: (text) => embedText(text, options),
69
+ embedTexts: (texts) => embedTexts(texts, options),
70
+ };
71
+ }
@@ -0,0 +1,10 @@
1
+ export * from './types';
2
+ export * from './tool';
3
+ export * from './agent';
4
+ export * from './memory';
5
+ export * from './stream';
6
+ export * from './rag';
7
+ export * from './embeddings';
8
+ export * from './observability';
9
+ export * from './providers';
10
+ export * from './react';
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types"), exports);
18
+ __exportStar(require("./tool"), exports);
19
+ __exportStar(require("./agent"), exports);
20
+ __exportStar(require("./memory"), exports);
21
+ __exportStar(require("./stream"), exports);
22
+ __exportStar(require("./rag"), exports);
23
+ __exportStar(require("./embeddings"), exports);
24
+ __exportStar(require("./observability"), exports);
25
+ __exportStar(require("./providers"), exports);
26
+ __exportStar(require("./react"), exports);
@@ -0,0 +1,16 @@
1
+ import type { AgentMemory, Message } from './types';
2
+ export interface InMemoryStoreOptions {
3
+ maxMessages?: number;
4
+ ttlMs?: number;
5
+ }
6
+ export declare class InMemoryStore implements AgentMemory {
7
+ private sessions;
8
+ private maxMessages;
9
+ private ttlMs?;
10
+ constructor(options?: InMemoryStoreOptions);
11
+ get(sessionId: string): Promise<Message[]>;
12
+ save(sessionId: string, messages: Message[]): Promise<void>;
13
+ clear(sessionId: string): Promise<void>;
14
+ private cleanExpired;
15
+ }
16
+ export declare const defaultMemoryStore: InMemoryStore;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultMemoryStore = exports.InMemoryStore = void 0;
4
+ class InMemoryStore {
5
+ sessions = new Map();
6
+ maxMessages;
7
+ ttlMs;
8
+ constructor(options = {}) {
9
+ this.maxMessages = options.maxMessages || 100;
10
+ this.ttlMs = options.ttlMs;
11
+ }
12
+ async get(sessionId) {
13
+ this.cleanExpired();
14
+ const session = this.sessions.get(sessionId);
15
+ if (!session)
16
+ return [];
17
+ return [...session.messages];
18
+ }
19
+ async save(sessionId, messages) {
20
+ const trimmed = messages.slice(-this.maxMessages);
21
+ const expiresAt = this.ttlMs ? Date.now() + this.ttlMs : Infinity;
22
+ this.sessions.set(sessionId, { messages: trimmed, expiresAt });
23
+ }
24
+ async clear(sessionId) {
25
+ this.sessions.delete(sessionId);
26
+ }
27
+ cleanExpired() {
28
+ if (!this.ttlMs)
29
+ return;
30
+ const now = Date.now();
31
+ for (const [id, session] of this.sessions.entries()) {
32
+ if (session.expiresAt <= now) {
33
+ this.sessions.delete(id);
34
+ }
35
+ }
36
+ }
37
+ }
38
+ exports.InMemoryStore = InMemoryStore;
39
+ exports.defaultMemoryStore = new InMemoryStore();
@@ -0,0 +1,21 @@
1
+ import type { AgentStep, ObservabilityHandler, TokenUsage, ToolCall, ToolResult } from './types';
2
+ export interface ObservabilityMetrics {
3
+ totalSteps: number;
4
+ totalDurationMs: number;
5
+ totalUsage: TokenUsage;
6
+ toolCallsCount: number;
7
+ }
8
+ export declare class AgentTelemetry {
9
+ private startTime;
10
+ private endTime;
11
+ private steps;
12
+ private handler?;
13
+ constructor(handler?: ObservabilityHandler | boolean);
14
+ start(): void;
15
+ recordStepStart(stepNumber: number): void;
16
+ recordToolCall(call: ToolCall): void;
17
+ recordToolResult(result: ToolResult): void;
18
+ recordStepFinish(step: AgentStep): void;
19
+ recordError(error: Error): void;
20
+ finish(): ObservabilityMetrics;
21
+ }
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AgentTelemetry = void 0;
4
+ class AgentTelemetry {
5
+ startTime = 0;
6
+ endTime = 0;
7
+ steps = [];
8
+ handler;
9
+ constructor(handler) {
10
+ if (typeof handler === 'object' && handler !== null) {
11
+ this.handler = handler;
12
+ }
13
+ else if (handler === true) {
14
+ // Default console logger
15
+ this.handler = {
16
+ onStepStart: (step) => console.log(`[vista:ai] Starting step ${step}...`),
17
+ onToolCall: (call) => console.log(`[vista:ai] Tool call: ${call.name}(${JSON.stringify(call.arguments)})`),
18
+ onToolResult: (res) => console.log(`[vista:ai] Tool result: ${res.name} -> ${JSON.stringify(res.result).slice(0, 80)}`),
19
+ onError: (err) => console.error(`[vista:ai] Error:`, err),
20
+ };
21
+ }
22
+ }
23
+ start() {
24
+ this.startTime = Date.now();
25
+ }
26
+ recordStepStart(stepNumber) {
27
+ this.handler?.onStepStart?.(stepNumber);
28
+ }
29
+ recordToolCall(call) {
30
+ this.handler?.onToolCall?.(call);
31
+ }
32
+ recordToolResult(result) {
33
+ this.handler?.onToolResult?.(result);
34
+ }
35
+ recordStepFinish(step) {
36
+ this.steps.push(step);
37
+ this.handler?.onStepFinish?.(step);
38
+ }
39
+ recordError(error) {
40
+ this.handler?.onError?.(error);
41
+ }
42
+ finish() {
43
+ this.endTime = Date.now();
44
+ const duration = this.endTime - this.startTime;
45
+ const totalUsage = {
46
+ promptTokens: 0,
47
+ completionTokens: 0,
48
+ totalTokens: 0,
49
+ };
50
+ let toolCallsCount = 0;
51
+ for (const step of this.steps) {
52
+ if (step.usage) {
53
+ totalUsage.promptTokens += step.usage.promptTokens;
54
+ totalUsage.completionTokens += step.usage.completionTokens;
55
+ totalUsage.totalTokens += step.usage.totalTokens;
56
+ }
57
+ if (step.toolCalls) {
58
+ toolCallsCount += step.toolCalls.length;
59
+ }
60
+ }
61
+ return {
62
+ totalSteps: this.steps.length,
63
+ totalDurationMs: duration,
64
+ totalUsage,
65
+ toolCallsCount,
66
+ };
67
+ }
68
+ }
69
+ exports.AgentTelemetry = AgentTelemetry;
@@ -0,0 +1,2 @@
1
+ import type { LanguageModel, ModelOptions } from '../types';
2
+ export declare function createAnthropicModel(options: ModelOptions): LanguageModel;