@snap-agent/core 0.1.2 → 0.1.3

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/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { P as ProviderConfig, a as ProviderType, b as Plugin, S as StoredPluginConfig, A as AgentData, c as StorageAdapter, d as AgentConfig, e as AgentFile, R as RAGDocument, I as IngestOptions, f as IngestResult, B as BulkOperation, g as BulkResult, U as URLSource, h as URLIngestResult, T as ThreadData, i as ThreadConfig, M as MessageRole, j as MessageAttachment, k as MessageData, C as ClientConfig, l as ChatRequest, m as ChatResponse, n as StreamCallbacks, o as RAGPlugin, p as ToolPlugin, q as MiddlewarePlugin, r as AnalyticsPlugin, s as RAGContext } from './index-m2vDW79n.mjs';
2
2
  export { L as AgentNotFoundError, K as AgentSDKError, u as BasePlugin, D as DataTransform, H as ErrorTrackingData, w as IngestionSchedule, Q as InvalidConfigError, W as MemoryStorage, V as MongoDBStorage, Y as MongoDBStorageConfig, y as PerformanceTimings, J as PluginRegistryInterface, O as ProviderNotFoundError, t as RAGConfig, z as RAGMetrics, F as RequestTrackingData, G as ResponseTrackingData, N as ThreadNotFoundError, E as TokenMetrics, x as Tool, v as URLSourceAuth, X as UpstashStorage, Z as UpstashStorageConfig } from './index-m2vDW79n.mjs';
3
- import { LanguageModel, UserModelMessage, AssistantModelMessage } from 'ai';
3
+ import { LanguageModel, UserModelMessage, AssistantModelMessage, Schema } from 'ai';
4
4
 
5
5
  /**
6
6
  * Provider factory for creating language model instances
@@ -215,12 +215,19 @@ declare class Agent {
215
215
  /**
216
216
  * Generate a text response with optional plugin support
217
217
  */
218
- generateResponse(messages: AIMessage$1[], options?: {
218
+ generateResponse<T = unknown>(messages: AIMessage$1[], options?: {
219
219
  useRAG?: boolean;
220
220
  ragFilters?: Record<string, any>;
221
221
  threadId?: string;
222
+ output?: {
223
+ mode: 'json';
224
+ } | {
225
+ mode: 'object';
226
+ schema: Schema<T>;
227
+ };
222
228
  }): Promise<{
223
229
  text: string;
230
+ parsed?: T;
224
231
  metadata?: Record<string, any>;
225
232
  }>;
226
233
  /**
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { P as ProviderConfig, a as ProviderType, b as Plugin, S as StoredPluginConfig, A as AgentData, c as StorageAdapter, d as AgentConfig, e as AgentFile, R as RAGDocument, I as IngestOptions, f as IngestResult, B as BulkOperation, g as BulkResult, U as URLSource, h as URLIngestResult, T as ThreadData, i as ThreadConfig, M as MessageRole, j as MessageAttachment, k as MessageData, C as ClientConfig, l as ChatRequest, m as ChatResponse, n as StreamCallbacks, o as RAGPlugin, p as ToolPlugin, q as MiddlewarePlugin, r as AnalyticsPlugin, s as RAGContext } from './index-m2vDW79n.js';
2
2
  export { L as AgentNotFoundError, K as AgentSDKError, u as BasePlugin, D as DataTransform, H as ErrorTrackingData, w as IngestionSchedule, Q as InvalidConfigError, W as MemoryStorage, V as MongoDBStorage, Y as MongoDBStorageConfig, y as PerformanceTimings, J as PluginRegistryInterface, O as ProviderNotFoundError, t as RAGConfig, z as RAGMetrics, F as RequestTrackingData, G as ResponseTrackingData, N as ThreadNotFoundError, E as TokenMetrics, x as Tool, v as URLSourceAuth, X as UpstashStorage, Z as UpstashStorageConfig } from './index-m2vDW79n.js';
3
- import { LanguageModel, UserModelMessage, AssistantModelMessage } from 'ai';
3
+ import { LanguageModel, UserModelMessage, AssistantModelMessage, Schema } from 'ai';
4
4
 
5
5
  /**
6
6
  * Provider factory for creating language model instances
@@ -215,12 +215,19 @@ declare class Agent {
215
215
  /**
216
216
  * Generate a text response with optional plugin support
217
217
  */
218
- generateResponse(messages: AIMessage$1[], options?: {
218
+ generateResponse<T = unknown>(messages: AIMessage$1[], options?: {
219
219
  useRAG?: boolean;
220
220
  ragFilters?: Record<string, any>;
221
221
  threadId?: string;
222
+ output?: {
223
+ mode: 'json';
224
+ } | {
225
+ mode: 'object';
226
+ schema: Schema<T>;
227
+ };
222
228
  }): Promise<{
223
229
  text: string;
230
+ parsed?: T;
224
231
  metadata?: Record<string, any>;
225
232
  }>;
226
233
  /**
package/dist/index.js CHANGED
@@ -7688,11 +7688,37 @@ var Agent = class _Agent {
7688
7688
  ragMetadata = allMetadata;
7689
7689
  }
7690
7690
  const model = await this.providerFactory.getModel(this.data.provider, this.data.model);
7691
- const { text } = await (0, import_ai.generateText)({
7692
- model,
7693
- messages: beforeResult.messages,
7694
- system: systemPrompt
7695
- });
7691
+ let text;
7692
+ let parsed;
7693
+ if (options?.output?.mode === "object") {
7694
+ const result = await (0, import_ai.generateText)({
7695
+ model,
7696
+ messages: beforeResult.messages,
7697
+ system: systemPrompt,
7698
+ experimental_output: import_ai.Output.object({ schema: options.output.schema })
7699
+ });
7700
+ text = JSON.stringify(result.experimental_output);
7701
+ parsed = result.experimental_output;
7702
+ } else if (options?.output?.mode === "json") {
7703
+ const jsonSystemPrompt = systemPrompt + "\n\n---\nOUTPUT FORMAT: You MUST respond with valid JSON only. No markdown code blocks, no explanations, no additional text - just raw JSON that can be parsed directly.";
7704
+ const result = await (0, import_ai.generateText)({
7705
+ model,
7706
+ messages: beforeResult.messages,
7707
+ system: jsonSystemPrompt
7708
+ });
7709
+ text = result.text;
7710
+ try {
7711
+ parsed = JSON.parse(text);
7712
+ } catch {
7713
+ }
7714
+ } else {
7715
+ const result = await (0, import_ai.generateText)({
7716
+ model,
7717
+ messages: beforeResult.messages,
7718
+ system: systemPrompt
7719
+ });
7720
+ text = result.text;
7721
+ }
7696
7722
  const afterResult = await this.pluginManager.executeAfterResponse(text, {
7697
7723
  agentId: this.data.id,
7698
7724
  threadId: options?.threadId,
@@ -7708,6 +7734,7 @@ var Agent = class _Agent {
7708
7734
  });
7709
7735
  return {
7710
7736
  text: afterResult.response,
7737
+ ...parsed !== void 0 && { parsed },
7711
7738
  metadata: {
7712
7739
  ...afterResult.metadata,
7713
7740
  ragMetadata,
package/dist/index.mjs CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  } from "./chunk-FS7G3ID4.mjs";
6
6
 
7
7
  // src/core/Agent.ts
8
- import { generateText, streamText } from "ai";
8
+ import { generateText, streamText, Output } from "ai";
9
9
 
10
10
  // src/core/PluginManager.ts
11
11
  var PluginManager = class {
@@ -352,11 +352,37 @@ var Agent = class _Agent {
352
352
  ragMetadata = allMetadata;
353
353
  }
354
354
  const model = await this.providerFactory.getModel(this.data.provider, this.data.model);
355
- const { text } = await generateText({
356
- model,
357
- messages: beforeResult.messages,
358
- system: systemPrompt
359
- });
355
+ let text;
356
+ let parsed;
357
+ if (options?.output?.mode === "object") {
358
+ const result = await generateText({
359
+ model,
360
+ messages: beforeResult.messages,
361
+ system: systemPrompt,
362
+ experimental_output: Output.object({ schema: options.output.schema })
363
+ });
364
+ text = JSON.stringify(result.experimental_output);
365
+ parsed = result.experimental_output;
366
+ } else if (options?.output?.mode === "json") {
367
+ const jsonSystemPrompt = systemPrompt + "\n\n---\nOUTPUT FORMAT: You MUST respond with valid JSON only. No markdown code blocks, no explanations, no additional text - just raw JSON that can be parsed directly.";
368
+ const result = await generateText({
369
+ model,
370
+ messages: beforeResult.messages,
371
+ system: jsonSystemPrompt
372
+ });
373
+ text = result.text;
374
+ try {
375
+ parsed = JSON.parse(text);
376
+ } catch {
377
+ }
378
+ } else {
379
+ const result = await generateText({
380
+ model,
381
+ messages: beforeResult.messages,
382
+ system: systemPrompt
383
+ });
384
+ text = result.text;
385
+ }
360
386
  const afterResult = await this.pluginManager.executeAfterResponse(text, {
361
387
  agentId: this.data.id,
362
388
  threadId: options?.threadId,
@@ -372,6 +398,7 @@ var Agent = class _Agent {
372
398
  });
373
399
  return {
374
400
  text: afterResult.response,
401
+ ...parsed !== void 0 && { parsed },
375
402
  metadata: {
376
403
  ...afterResult.metadata,
377
404
  ragMetadata,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snap-agent/core",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "SnapAgent - The lightweight, snap-in AI agent SDK. Multi-provider support. Edge-runtime compatible.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -89,6 +89,7 @@
89
89
  "eslint": "^8.0.0",
90
90
  "mongodb": "^7.0.0",
91
91
  "tsup": "^8.0.0",
92
+ "tsx": "^4.21.0",
92
93
  "typescript": "^5.8.0",
93
94
  "vitest": "^1.0.0"
94
95
  },