@syncagent/js
Advanced tools
+17
-3
@@ -23,2 +23,13 @@ interface ToolParameter { | ||
| } | ||
| /** Structured data returned from a DB tool call */ | ||
| interface ToolData { | ||
| /** The tool that produced this data */ | ||
| tool: string; | ||
| /** Collection/table that was queried */ | ||
| collection: string; | ||
| /** Raw result rows/documents */ | ||
| data: Record<string, any>[]; | ||
| /** Total count if available */ | ||
| count?: number; | ||
| } | ||
| interface ChatOptions { | ||
@@ -30,2 +41,4 @@ onToken?: (token: string) => void; | ||
| onStatus?: (step: string, label: string) => void; | ||
| /** Called whenever a DB tool returns structured data */ | ||
| onData?: (data: ToolData) => void; | ||
| signal?: AbortSignal; | ||
@@ -55,5 +68,6 @@ } | ||
| private toWireMessages; | ||
| /** Serialize tool definitions for the API (strips execute functions) */ | ||
| private serializeTools; | ||
| chat(messages: Message[], options?: ChatOptions): Promise<ChatResult>; | ||
| chat(messages: Message[], options?: ChatOptions & { | ||
| context?: Record<string, any>; | ||
| }): Promise<ChatResult>; | ||
| private chatLoop; | ||
@@ -63,2 +77,2 @@ getSchema(): Promise<CollectionSchema[]>; | ||
| export { type ChatOptions, type ChatResult, type CollectionSchema, type Message, type SchemaField, SyncAgentClient, type SyncAgentConfig, type ToolDefinition, type ToolParameter }; | ||
| export { type ChatOptions, type ChatResult, type CollectionSchema, type Message, type SchemaField, SyncAgentClient, type SyncAgentConfig, type ToolData, type ToolDefinition, type ToolParameter }; |
+17
-3
@@ -23,2 +23,13 @@ interface ToolParameter { | ||
| } | ||
| /** Structured data returned from a DB tool call */ | ||
| interface ToolData { | ||
| /** The tool that produced this data */ | ||
| tool: string; | ||
| /** Collection/table that was queried */ | ||
| collection: string; | ||
| /** Raw result rows/documents */ | ||
| data: Record<string, any>[]; | ||
| /** Total count if available */ | ||
| count?: number; | ||
| } | ||
| interface ChatOptions { | ||
@@ -30,2 +41,4 @@ onToken?: (token: string) => void; | ||
| onStatus?: (step: string, label: string) => void; | ||
| /** Called whenever a DB tool returns structured data */ | ||
| onData?: (data: ToolData) => void; | ||
| signal?: AbortSignal; | ||
@@ -55,5 +68,6 @@ } | ||
| private toWireMessages; | ||
| /** Serialize tool definitions for the API (strips execute functions) */ | ||
| private serializeTools; | ||
| chat(messages: Message[], options?: ChatOptions): Promise<ChatResult>; | ||
| chat(messages: Message[], options?: ChatOptions & { | ||
| context?: Record<string, any>; | ||
| }): Promise<ChatResult>; | ||
| private chatLoop; | ||
@@ -63,2 +77,2 @@ getSchema(): Promise<CollectionSchema[]>; | ||
| export { type ChatOptions, type ChatResult, type CollectionSchema, type Message, type SchemaField, SyncAgentClient, type SyncAgentConfig, type ToolDefinition, type ToolParameter }; | ||
| export { type ChatOptions, type ChatResult, type CollectionSchema, type Message, type SchemaField, SyncAgentClient, type SyncAgentConfig, type ToolData, type ToolDefinition, type ToolParameter }; |
+30
-12
@@ -29,2 +29,3 @@ "use strict"; | ||
| var STATUS_PREFIX = "__sa_status:"; | ||
| var DATA_PREFIX = "__sa_data:"; | ||
| function parseChunkFull(chunk) { | ||
@@ -37,2 +38,3 @@ return parseChunk(chunk); | ||
| let status; | ||
| let data; | ||
| const lines = chunk.split("\n"); | ||
@@ -49,2 +51,9 @@ for (let i = 0; i < lines.length; i++) { | ||
| } | ||
| if (trimmed.startsWith(DATA_PREFIX)) { | ||
| try { | ||
| data = JSON.parse(trimmed.slice(DATA_PREFIX.length)); | ||
| } catch { | ||
| } | ||
| continue; | ||
| } | ||
| if (trimmed.startsWith("data:") || trimmed.startsWith("event:") || trimmed.startsWith("id:") || trimmed === "") { | ||
@@ -65,7 +74,7 @@ continue; | ||
| } | ||
| return { tokens, status }; | ||
| return { tokens, status, data }; | ||
| } | ||
| // src/client.ts | ||
| var SYNCAGENT_API_URL = "https://syncagentdev.vercel.app"; | ||
| var SYNCAGENT_API_URL = "https://syncagent.dev"; | ||
| var SyncAgentClient = class { | ||
@@ -86,4 +95,4 @@ constructor(config) { | ||
| } | ||
| toWireMessages(messages) { | ||
| return messages.map((m) => ({ | ||
| toWireMessages(messages, context) { | ||
| const wire = messages.map((m) => ({ | ||
| id: Math.random().toString(36).slice(2), | ||
@@ -93,4 +102,12 @@ role: m.role, | ||
| })); | ||
| if (context && Object.keys(context).length > 0) { | ||
| const last = wire[wire.length - 1]; | ||
| if (last?.role === "user") { | ||
| last.parts[0].text += ` | ||
| [Context: ${JSON.stringify(context)}]`; | ||
| } | ||
| } | ||
| return wire; | ||
| } | ||
| /** Serialize tool definitions for the API (strips execute functions) */ | ||
| serializeTools() { | ||
@@ -105,7 +122,7 @@ if (!Object.keys(this.tools).length) return void 0; | ||
| async chat(messages, options = {}) { | ||
| const { onToken, onComplete, onError, onToolCall, onStatus, signal } = options; | ||
| const wireMessages = this.toWireMessages(messages); | ||
| const { onToken, onComplete, onError, onToolCall, onStatus, onData, signal, context } = options; | ||
| const wireMessages = this.toWireMessages(messages, context); | ||
| const clientTools = this.serializeTools(); | ||
| try { | ||
| const fullText = await this.chatLoop(wireMessages, clientTools, { onToken, onToolCall, onStatus, signal }); | ||
| const fullText = await this.chatLoop(wireMessages, clientTools, { onToken, onToolCall, onStatus, onData, signal }); | ||
| onComplete?.(fullText); | ||
@@ -144,10 +161,11 @@ return { text: fullText }; | ||
| const chunk = decoder.decode(value, { stream: true }); | ||
| const { tokens, status } = parseChunkFull(chunk); | ||
| const { tokens, status, data } = parseChunkFull(chunk); | ||
| if (status) opts.onStatus?.(status.step, status.label); | ||
| if (data) opts.onData?.(data); | ||
| for (const line of chunk.split("\n")) { | ||
| if (line.startsWith("a:")) { | ||
| try { | ||
| const data = JSON.parse(line.slice(2)); | ||
| if (data.type === "client_tool_call") { | ||
| pendingToolCalls.push({ id: data.id, name: data.name, args: data.args }); | ||
| const data2 = JSON.parse(line.slice(2)); | ||
| if (data2.type === "client_tool_call") { | ||
| pendingToolCalls.push({ id: data2.id, name: data2.name, args: data2.args }); | ||
| } | ||
@@ -154,0 +172,0 @@ } catch { |
+30
-12
| // src/stream.ts | ||
| var STATUS_PREFIX = "__sa_status:"; | ||
| var DATA_PREFIX = "__sa_data:"; | ||
| function parseChunkFull(chunk) { | ||
@@ -10,2 +11,3 @@ return parseChunk(chunk); | ||
| let status; | ||
| let data; | ||
| const lines = chunk.split("\n"); | ||
@@ -22,2 +24,9 @@ for (let i = 0; i < lines.length; i++) { | ||
| } | ||
| if (trimmed.startsWith(DATA_PREFIX)) { | ||
| try { | ||
| data = JSON.parse(trimmed.slice(DATA_PREFIX.length)); | ||
| } catch { | ||
| } | ||
| continue; | ||
| } | ||
| if (trimmed.startsWith("data:") || trimmed.startsWith("event:") || trimmed.startsWith("id:") || trimmed === "") { | ||
@@ -38,7 +47,7 @@ continue; | ||
| } | ||
| return { tokens, status }; | ||
| return { tokens, status, data }; | ||
| } | ||
| // src/client.ts | ||
| var SYNCAGENT_API_URL = "https://syncagentdev.vercel.app"; | ||
| var SYNCAGENT_API_URL = "https://syncagent.dev"; | ||
| var SyncAgentClient = class { | ||
@@ -59,4 +68,4 @@ constructor(config) { | ||
| } | ||
| toWireMessages(messages) { | ||
| return messages.map((m) => ({ | ||
| toWireMessages(messages, context) { | ||
| const wire = messages.map((m) => ({ | ||
| id: Math.random().toString(36).slice(2), | ||
@@ -66,4 +75,12 @@ role: m.role, | ||
| })); | ||
| if (context && Object.keys(context).length > 0) { | ||
| const last = wire[wire.length - 1]; | ||
| if (last?.role === "user") { | ||
| last.parts[0].text += ` | ||
| [Context: ${JSON.stringify(context)}]`; | ||
| } | ||
| } | ||
| return wire; | ||
| } | ||
| /** Serialize tool definitions for the API (strips execute functions) */ | ||
| serializeTools() { | ||
@@ -78,7 +95,7 @@ if (!Object.keys(this.tools).length) return void 0; | ||
| async chat(messages, options = {}) { | ||
| const { onToken, onComplete, onError, onToolCall, onStatus, signal } = options; | ||
| const wireMessages = this.toWireMessages(messages); | ||
| const { onToken, onComplete, onError, onToolCall, onStatus, onData, signal, context } = options; | ||
| const wireMessages = this.toWireMessages(messages, context); | ||
| const clientTools = this.serializeTools(); | ||
| try { | ||
| const fullText = await this.chatLoop(wireMessages, clientTools, { onToken, onToolCall, onStatus, signal }); | ||
| const fullText = await this.chatLoop(wireMessages, clientTools, { onToken, onToolCall, onStatus, onData, signal }); | ||
| onComplete?.(fullText); | ||
@@ -117,10 +134,11 @@ return { text: fullText }; | ||
| const chunk = decoder.decode(value, { stream: true }); | ||
| const { tokens, status } = parseChunkFull(chunk); | ||
| const { tokens, status, data } = parseChunkFull(chunk); | ||
| if (status) opts.onStatus?.(status.step, status.label); | ||
| if (data) opts.onData?.(data); | ||
| for (const line of chunk.split("\n")) { | ||
| if (line.startsWith("a:")) { | ||
| try { | ||
| const data = JSON.parse(line.slice(2)); | ||
| if (data.type === "client_tool_call") { | ||
| pendingToolCalls.push({ id: data.id, name: data.name, args: data.args }); | ||
| const data2 = JSON.parse(line.slice(2)); | ||
| if (data2.type === "client_tool_call") { | ||
| pendingToolCalls.push({ id: data2.id, name: data2.name, args: data2.args }); | ||
| } | ||
@@ -127,0 +145,0 @@ } catch { |
+1
-1
| { | ||
| "name": "@syncagent/js", | ||
| "version": "0.1.8", | ||
| "version": "0.1.9", | ||
| "description": "SyncAgent JavaScript SDK — AI database agent for any app", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.cjs", |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
25752
7.34%483
11.03%