@objectstack/service-ai 6.3.0 → 6.5.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.
- package/dist/index.cjs +317 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +46 -7
- package/dist/index.d.ts +46 -7
- package/dist/index.js +315 -30
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AIToolDefinition, ToolCallPart, ToolResultPart, IDataEngine, Logger, IAIService, IAIConversationService, LLMAdapter, ModelMessage, AIRequestOptions, AIResult, GenerateObjectOptions, AIObjectResult, TextStreamPart, ToolSet, ChatWithToolsOptions, ProposePendingActionInput, PendingActionStatus, PendingActionRow, AIConversation, IMetadataService, IAutomationService } from '@objectstack/spec/contracts';
|
|
1
|
+
import { AIToolDefinition, ToolExecutionContext, ToolCallPart, ToolResultPart, IDataEngine, Logger, IAIService, IAIConversationService, LLMAdapter, ModelMessage, AIRequestOptions, AIResult, GenerateObjectOptions, AIObjectResult, TextStreamPart, ToolSet, ChatWithToolsOptions, ProposePendingActionInput, PendingActionStatus, PendingActionRow, AIConversation, IMetadataService, IKnowledgeService, IAutomationService } from '@objectstack/spec/contracts';
|
|
2
2
|
export { LLMAdapter } from '@objectstack/spec/contracts';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import * as AI from '@objectstack/spec/ai';
|
|
@@ -13,9 +13,12 @@ import * as _objectstack_spec_data from '@objectstack/spec/data';
|
|
|
13
13
|
/**
|
|
14
14
|
* Handler function for a registered tool.
|
|
15
15
|
*
|
|
16
|
-
* Receives parsed arguments and
|
|
16
|
+
* Receives parsed arguments and an optional per-call execution context.
|
|
17
|
+
* Returns the tool output as a string (typically JSON). Tools that
|
|
18
|
+
* require permission enforcement should use `ctx.actor` and propagate
|
|
19
|
+
* it into the underlying engine call.
|
|
17
20
|
*/
|
|
18
|
-
type ToolHandler = (args: Record<string, unknown
|
|
21
|
+
type ToolHandler = (args: Record<string, unknown>, ctx?: ToolExecutionContext) => Promise<string> | string;
|
|
19
22
|
/**
|
|
20
23
|
* Extended ToolResultPart that carries an `isError` flag for internal
|
|
21
24
|
* error-tracking in the tool-call loop.
|
|
@@ -61,12 +64,20 @@ declare class ToolRegistry {
|
|
|
61
64
|
names(): string[];
|
|
62
65
|
/**
|
|
63
66
|
* Execute a tool call and return the result.
|
|
67
|
+
*
|
|
68
|
+
* @param toolCall The decoded tool-call part from the model response.
|
|
69
|
+
* @param ctx Optional per-call execution context (actor, conversation,
|
|
70
|
+
* environment). Handlers may use this to enforce RLS,
|
|
71
|
+
* attribute audit entries, or correlate traces. When
|
|
72
|
+
* omitted, handlers should fall back to system-level
|
|
73
|
+
* behaviour for backward compatibility.
|
|
64
74
|
*/
|
|
65
|
-
execute(toolCall: ToolCallPart): Promise<ToolExecutionResult>;
|
|
75
|
+
execute(toolCall: ToolCallPart, ctx?: ToolExecutionContext): Promise<ToolExecutionResult>;
|
|
66
76
|
/**
|
|
67
|
-
* Execute multiple tool calls in parallel
|
|
77
|
+
* Execute multiple tool calls in parallel, threading the same
|
|
78
|
+
* execution context to each handler.
|
|
68
79
|
*/
|
|
69
|
-
executeAll(toolCalls: ToolCallPart[]): Promise<ToolExecutionResult[]>;
|
|
80
|
+
executeAll(toolCalls: ToolCallPart[], ctx?: ToolExecutionContext): Promise<ToolExecutionResult[]>;
|
|
70
81
|
/**
|
|
71
82
|
* Clear all registered tools.
|
|
72
83
|
*/
|
|
@@ -300,6 +311,13 @@ declare class AIService implements IAIService {
|
|
|
300
311
|
constructor(config?: AIServiceConfig);
|
|
301
312
|
/** The name of the active LLM adapter. */
|
|
302
313
|
get adapterName(): string;
|
|
314
|
+
/**
|
|
315
|
+
* Best-effort persistence of a single chat message to the conversation
|
|
316
|
+
* store. Failures are logged at warn level and swallowed — chat requests
|
|
317
|
+
* must never fail because the history write failed. Mirrors the
|
|
318
|
+
* precedent set by `ObjectQLTraceRecorder.record`.
|
|
319
|
+
*/
|
|
320
|
+
private persistMessage;
|
|
303
321
|
/**
|
|
304
322
|
* Run an adapter call and emit a trace event.
|
|
305
323
|
*
|
|
@@ -850,6 +868,27 @@ interface MetadataToolContext {
|
|
|
850
868
|
*/
|
|
851
869
|
declare function registerMetadataTools(registry: ToolRegistry, context: MetadataToolContext): void;
|
|
852
870
|
|
|
871
|
+
/**
|
|
872
|
+
* Services required by the knowledge tool family.
|
|
873
|
+
*/
|
|
874
|
+
interface KnowledgeToolContext {
|
|
875
|
+
/** Orchestrator that resolves adapters and applies permission filtering. */
|
|
876
|
+
knowledgeService: IKnowledgeService;
|
|
877
|
+
}
|
|
878
|
+
declare const SEARCH_KNOWLEDGE_TOOL: AIToolDefinition;
|
|
879
|
+
/**
|
|
880
|
+
* Register knowledge-related tools on the AI tool registry.
|
|
881
|
+
*
|
|
882
|
+
* @example
|
|
883
|
+
* ```ts
|
|
884
|
+
* ctx.hook('ai:ready', async (aiService) => {
|
|
885
|
+
* const knowledgeService = ctx.getService<IKnowledgeService>('knowledge');
|
|
886
|
+
* registerKnowledgeTools(aiService.toolRegistry, { knowledgeService });
|
|
887
|
+
* });
|
|
888
|
+
* ```
|
|
889
|
+
*/
|
|
890
|
+
declare function registerKnowledgeTools(registry: ToolRegistry, context: KnowledgeToolContext): void;
|
|
891
|
+
|
|
853
892
|
/**
|
|
854
893
|
* list_packages — AI Tool Metadata
|
|
855
894
|
*
|
|
@@ -10279,4 +10318,4 @@ declare function buildAssistantRoutes(aiService: AIService, agentRuntime: AgentR
|
|
|
10279
10318
|
*/
|
|
10280
10319
|
declare function buildToolRoutes(aiService: AIService, logger: Logger): RouteDefinition[];
|
|
10281
10320
|
|
|
10282
|
-
export { ACTIONS_EXECUTOR_SKILL, AIService, type AIServiceConfig, AIServicePlugin, type AIServicePluginOptions, type ActionToolsContext, type AgentChatContext, AgentRuntime, AiConversationObject, AiMessageObject, AiTraceObject, AiTraceView, type CostEstimate, DATA_CHAT_AGENT, DATA_EXPLORER_SKILL, DATA_TOOL_DEFINITIONS, type DataToolContext, type FieldShape, type IConversationService, type IPackageRegistry, InMemoryConversationService, METADATA_ASSISTANT_AGENT, METADATA_AUTHORING_SKILL, METADATA_TOOL_DEFINITIONS, MemoryLLMAdapter, type MetadataToolContext, ModelRegistry, type ModelRegistryConfig, NullTraceRecorder, ObjectQLConversationService, ObjectQLTraceRecorder, type ObjectShape, PACKAGE_TOOL_DEFINITIONS, type PackageToolContext, QUERY_DATA_TOOL, type QueryDataToolContext, type QueryPlan, type RouteDefinition, type RouteRequest, type RouteResponse, type RouteUserContext, type SchemaHit, SchemaRetriever, type SchemaRetrieverOptions, type SkillContext, SkillRegistry, type SkillSummary, type TokenUsage, type ToolExecutionResult, type ToolHandler, ToolRegistry, type TraceEvent, type TraceOperation, type TraceRecorder, VercelLLMAdapter, type VercelLLMAdapterConfig, actionSkipReason, actionToToolDefinition, actionToolName, addFieldTool, buildAIRoutes, buildAgentRoutes, buildAssistantRoutes, buildToolRoutes, buildTraceEvent, computeCost, createObjectTool, createPackageTool, createQueryDataHandler, deleteFieldTool, describeObjectTool, encodeStreamPart, encodeVercelDataStream, getActivePackageTool, getPackageTool, listObjectsTool, listPackagesTool, modifyFieldTool, registerActionsAsTools, registerDataTools, registerMetadataTools, registerPackageTools, registerQueryDataTool, setActivePackageTool };
|
|
10321
|
+
export { ACTIONS_EXECUTOR_SKILL, AIService, type AIServiceConfig, AIServicePlugin, type AIServicePluginOptions, type ActionToolsContext, type AgentChatContext, AgentRuntime, AiConversationObject, AiMessageObject, AiTraceObject, AiTraceView, type CostEstimate, DATA_CHAT_AGENT, DATA_EXPLORER_SKILL, DATA_TOOL_DEFINITIONS, type DataToolContext, type FieldShape, type IConversationService, type IPackageRegistry, InMemoryConversationService, type KnowledgeToolContext, METADATA_ASSISTANT_AGENT, METADATA_AUTHORING_SKILL, METADATA_TOOL_DEFINITIONS, MemoryLLMAdapter, type MetadataToolContext, ModelRegistry, type ModelRegistryConfig, NullTraceRecorder, ObjectQLConversationService, ObjectQLTraceRecorder, type ObjectShape, PACKAGE_TOOL_DEFINITIONS, type PackageToolContext, QUERY_DATA_TOOL, type QueryDataToolContext, type QueryPlan, type RouteDefinition, type RouteRequest, type RouteResponse, type RouteUserContext, SEARCH_KNOWLEDGE_TOOL, type SchemaHit, SchemaRetriever, type SchemaRetrieverOptions, type SkillContext, SkillRegistry, type SkillSummary, type TokenUsage, type ToolExecutionResult, type ToolHandler, ToolRegistry, type TraceEvent, type TraceOperation, type TraceRecorder, VercelLLMAdapter, type VercelLLMAdapterConfig, actionSkipReason, actionToToolDefinition, actionToolName, addFieldTool, buildAIRoutes, buildAgentRoutes, buildAssistantRoutes, buildToolRoutes, buildTraceEvent, computeCost, createObjectTool, createPackageTool, createQueryDataHandler, deleteFieldTool, describeObjectTool, encodeStreamPart, encodeVercelDataStream, getActivePackageTool, getPackageTool, listObjectsTool, listPackagesTool, modifyFieldTool, registerActionsAsTools, registerDataTools, registerKnowledgeTools, registerMetadataTools, registerPackageTools, registerQueryDataTool, setActivePackageTool };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AIToolDefinition, ToolCallPart, ToolResultPart, IDataEngine, Logger, IAIService, IAIConversationService, LLMAdapter, ModelMessage, AIRequestOptions, AIResult, GenerateObjectOptions, AIObjectResult, TextStreamPart, ToolSet, ChatWithToolsOptions, ProposePendingActionInput, PendingActionStatus, PendingActionRow, AIConversation, IMetadataService, IAutomationService } from '@objectstack/spec/contracts';
|
|
1
|
+
import { AIToolDefinition, ToolExecutionContext, ToolCallPart, ToolResultPart, IDataEngine, Logger, IAIService, IAIConversationService, LLMAdapter, ModelMessage, AIRequestOptions, AIResult, GenerateObjectOptions, AIObjectResult, TextStreamPart, ToolSet, ChatWithToolsOptions, ProposePendingActionInput, PendingActionStatus, PendingActionRow, AIConversation, IMetadataService, IKnowledgeService, IAutomationService } from '@objectstack/spec/contracts';
|
|
2
2
|
export { LLMAdapter } from '@objectstack/spec/contracts';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import * as AI from '@objectstack/spec/ai';
|
|
@@ -13,9 +13,12 @@ import * as _objectstack_spec_data from '@objectstack/spec/data';
|
|
|
13
13
|
/**
|
|
14
14
|
* Handler function for a registered tool.
|
|
15
15
|
*
|
|
16
|
-
* Receives parsed arguments and
|
|
16
|
+
* Receives parsed arguments and an optional per-call execution context.
|
|
17
|
+
* Returns the tool output as a string (typically JSON). Tools that
|
|
18
|
+
* require permission enforcement should use `ctx.actor` and propagate
|
|
19
|
+
* it into the underlying engine call.
|
|
17
20
|
*/
|
|
18
|
-
type ToolHandler = (args: Record<string, unknown
|
|
21
|
+
type ToolHandler = (args: Record<string, unknown>, ctx?: ToolExecutionContext) => Promise<string> | string;
|
|
19
22
|
/**
|
|
20
23
|
* Extended ToolResultPart that carries an `isError` flag for internal
|
|
21
24
|
* error-tracking in the tool-call loop.
|
|
@@ -61,12 +64,20 @@ declare class ToolRegistry {
|
|
|
61
64
|
names(): string[];
|
|
62
65
|
/**
|
|
63
66
|
* Execute a tool call and return the result.
|
|
67
|
+
*
|
|
68
|
+
* @param toolCall The decoded tool-call part from the model response.
|
|
69
|
+
* @param ctx Optional per-call execution context (actor, conversation,
|
|
70
|
+
* environment). Handlers may use this to enforce RLS,
|
|
71
|
+
* attribute audit entries, or correlate traces. When
|
|
72
|
+
* omitted, handlers should fall back to system-level
|
|
73
|
+
* behaviour for backward compatibility.
|
|
64
74
|
*/
|
|
65
|
-
execute(toolCall: ToolCallPart): Promise<ToolExecutionResult>;
|
|
75
|
+
execute(toolCall: ToolCallPart, ctx?: ToolExecutionContext): Promise<ToolExecutionResult>;
|
|
66
76
|
/**
|
|
67
|
-
* Execute multiple tool calls in parallel
|
|
77
|
+
* Execute multiple tool calls in parallel, threading the same
|
|
78
|
+
* execution context to each handler.
|
|
68
79
|
*/
|
|
69
|
-
executeAll(toolCalls: ToolCallPart[]): Promise<ToolExecutionResult[]>;
|
|
80
|
+
executeAll(toolCalls: ToolCallPart[], ctx?: ToolExecutionContext): Promise<ToolExecutionResult[]>;
|
|
70
81
|
/**
|
|
71
82
|
* Clear all registered tools.
|
|
72
83
|
*/
|
|
@@ -300,6 +311,13 @@ declare class AIService implements IAIService {
|
|
|
300
311
|
constructor(config?: AIServiceConfig);
|
|
301
312
|
/** The name of the active LLM adapter. */
|
|
302
313
|
get adapterName(): string;
|
|
314
|
+
/**
|
|
315
|
+
* Best-effort persistence of a single chat message to the conversation
|
|
316
|
+
* store. Failures are logged at warn level and swallowed — chat requests
|
|
317
|
+
* must never fail because the history write failed. Mirrors the
|
|
318
|
+
* precedent set by `ObjectQLTraceRecorder.record`.
|
|
319
|
+
*/
|
|
320
|
+
private persistMessage;
|
|
303
321
|
/**
|
|
304
322
|
* Run an adapter call and emit a trace event.
|
|
305
323
|
*
|
|
@@ -850,6 +868,27 @@ interface MetadataToolContext {
|
|
|
850
868
|
*/
|
|
851
869
|
declare function registerMetadataTools(registry: ToolRegistry, context: MetadataToolContext): void;
|
|
852
870
|
|
|
871
|
+
/**
|
|
872
|
+
* Services required by the knowledge tool family.
|
|
873
|
+
*/
|
|
874
|
+
interface KnowledgeToolContext {
|
|
875
|
+
/** Orchestrator that resolves adapters and applies permission filtering. */
|
|
876
|
+
knowledgeService: IKnowledgeService;
|
|
877
|
+
}
|
|
878
|
+
declare const SEARCH_KNOWLEDGE_TOOL: AIToolDefinition;
|
|
879
|
+
/**
|
|
880
|
+
* Register knowledge-related tools on the AI tool registry.
|
|
881
|
+
*
|
|
882
|
+
* @example
|
|
883
|
+
* ```ts
|
|
884
|
+
* ctx.hook('ai:ready', async (aiService) => {
|
|
885
|
+
* const knowledgeService = ctx.getService<IKnowledgeService>('knowledge');
|
|
886
|
+
* registerKnowledgeTools(aiService.toolRegistry, { knowledgeService });
|
|
887
|
+
* });
|
|
888
|
+
* ```
|
|
889
|
+
*/
|
|
890
|
+
declare function registerKnowledgeTools(registry: ToolRegistry, context: KnowledgeToolContext): void;
|
|
891
|
+
|
|
853
892
|
/**
|
|
854
893
|
* list_packages — AI Tool Metadata
|
|
855
894
|
*
|
|
@@ -10279,4 +10318,4 @@ declare function buildAssistantRoutes(aiService: AIService, agentRuntime: AgentR
|
|
|
10279
10318
|
*/
|
|
10280
10319
|
declare function buildToolRoutes(aiService: AIService, logger: Logger): RouteDefinition[];
|
|
10281
10320
|
|
|
10282
|
-
export { ACTIONS_EXECUTOR_SKILL, AIService, type AIServiceConfig, AIServicePlugin, type AIServicePluginOptions, type ActionToolsContext, type AgentChatContext, AgentRuntime, AiConversationObject, AiMessageObject, AiTraceObject, AiTraceView, type CostEstimate, DATA_CHAT_AGENT, DATA_EXPLORER_SKILL, DATA_TOOL_DEFINITIONS, type DataToolContext, type FieldShape, type IConversationService, type IPackageRegistry, InMemoryConversationService, METADATA_ASSISTANT_AGENT, METADATA_AUTHORING_SKILL, METADATA_TOOL_DEFINITIONS, MemoryLLMAdapter, type MetadataToolContext, ModelRegistry, type ModelRegistryConfig, NullTraceRecorder, ObjectQLConversationService, ObjectQLTraceRecorder, type ObjectShape, PACKAGE_TOOL_DEFINITIONS, type PackageToolContext, QUERY_DATA_TOOL, type QueryDataToolContext, type QueryPlan, type RouteDefinition, type RouteRequest, type RouteResponse, type RouteUserContext, type SchemaHit, SchemaRetriever, type SchemaRetrieverOptions, type SkillContext, SkillRegistry, type SkillSummary, type TokenUsage, type ToolExecutionResult, type ToolHandler, ToolRegistry, type TraceEvent, type TraceOperation, type TraceRecorder, VercelLLMAdapter, type VercelLLMAdapterConfig, actionSkipReason, actionToToolDefinition, actionToolName, addFieldTool, buildAIRoutes, buildAgentRoutes, buildAssistantRoutes, buildToolRoutes, buildTraceEvent, computeCost, createObjectTool, createPackageTool, createQueryDataHandler, deleteFieldTool, describeObjectTool, encodeStreamPart, encodeVercelDataStream, getActivePackageTool, getPackageTool, listObjectsTool, listPackagesTool, modifyFieldTool, registerActionsAsTools, registerDataTools, registerMetadataTools, registerPackageTools, registerQueryDataTool, setActivePackageTool };
|
|
10321
|
+
export { ACTIONS_EXECUTOR_SKILL, AIService, type AIServiceConfig, AIServicePlugin, type AIServicePluginOptions, type ActionToolsContext, type AgentChatContext, AgentRuntime, AiConversationObject, AiMessageObject, AiTraceObject, AiTraceView, type CostEstimate, DATA_CHAT_AGENT, DATA_EXPLORER_SKILL, DATA_TOOL_DEFINITIONS, type DataToolContext, type FieldShape, type IConversationService, type IPackageRegistry, InMemoryConversationService, type KnowledgeToolContext, METADATA_ASSISTANT_AGENT, METADATA_AUTHORING_SKILL, METADATA_TOOL_DEFINITIONS, MemoryLLMAdapter, type MetadataToolContext, ModelRegistry, type ModelRegistryConfig, NullTraceRecorder, ObjectQLConversationService, ObjectQLTraceRecorder, type ObjectShape, PACKAGE_TOOL_DEFINITIONS, type PackageToolContext, QUERY_DATA_TOOL, type QueryDataToolContext, type QueryPlan, type RouteDefinition, type RouteRequest, type RouteResponse, type RouteUserContext, SEARCH_KNOWLEDGE_TOOL, type SchemaHit, SchemaRetriever, type SchemaRetrieverOptions, type SkillContext, SkillRegistry, type SkillSummary, type TokenUsage, type ToolExecutionResult, type ToolHandler, ToolRegistry, type TraceEvent, type TraceOperation, type TraceRecorder, VercelLLMAdapter, type VercelLLMAdapterConfig, actionSkipReason, actionToToolDefinition, actionToolName, addFieldTool, buildAIRoutes, buildAgentRoutes, buildAssistantRoutes, buildToolRoutes, buildTraceEvent, computeCost, createObjectTool, createPackageTool, createQueryDataHandler, deleteFieldTool, describeObjectTool, encodeStreamPart, encodeVercelDataStream, getActivePackageTool, getPackageTool, listObjectsTool, listPackagesTool, modifyFieldTool, registerActionsAsTools, registerDataTools, registerKnowledgeTools, registerMetadataTools, registerPackageTools, registerQueryDataTool, setActivePackageTool };
|