@xpert-ai/plugin-sdk 3.21.0 → 3.22.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/{README.md → docs/README.md} +10 -8
- package/docs/en/KNOWLEDGEBASE_API.md +42 -0
- package/docs/en/PERMISSIONS.md +173 -0
- package/{RESOURCE-CARDS.md → docs/en/RESOURCE-CARDS.md} +5 -5
- package/docs/en/SCHEMA_SPECIFICATION.md +325 -0
- package/{TOOL-IMAGES.md → docs/en/TOOL-IMAGES.md} +1 -1
- package/docs/en/structured-knowledge-graph.md +60 -0
- package/docs/en/video-generation-protocol.md +86 -0
- package/docs/en/view-extension-protocol.md +413 -0
- package/index.cjs.js +26 -4
- package/index.esm.js +24 -5
- package/package.json +2 -2
- package/src/lib/artifact-namespace.d.ts +1 -0
- package/src/lib/connector/runtime-capability.d.ts +5 -0
- package/src/lib/rag/capability/index.d.ts +1 -0
- package/src/lib/rag/capability/knowledgebase-catalog.d.ts +78 -0
- package/src/lib/rag/capability/knowledgebase.d.ts +65 -0
- package/src/lib/runtime/capabilities/index.d.ts +1 -0
- package/src/lib/runtime/capabilities/workspace-files.d.ts +4 -0
- package/src/lib/runtime/capabilities/workspace-storage.d.ts +22 -0
- package/src/lib/view-extension/index.d.ts +1 -0
- package/src/lib/view-extension/middleware-runtime.d.ts +20 -0
- package/PERMISSIONS.md +0 -181
- package/SCHEMA_SPECIFICATION.md +0 -335
- /package/{CHANGELOG.md → docs/CHANGELOG.md} +0 -0
- /package/{MIDDLEWARE_APPS.md → docs/en/MIDDLEWARE_APPS.md} +0 -0
- /package/{RESOURCE-CARDS-VALIDATION.md → docs/en/RESOURCE-CARDS-VALIDATION.md} +0 -0
- /package/{runtime-capabilities.md → docs/en/runtime-capabilities.md} +0 -0
package/index.esm.js
CHANGED
|
@@ -106,6 +106,9 @@ function assertPluginArtifactNamePart(value, label) {
|
|
|
106
106
|
throw new Error(`${label} must contain only lowercase letters, numbers, and underscores`);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
+
function isPluginArtifactNamespace(value) {
|
|
110
|
+
return typeof value === 'string' && ARTIFACT_NAMESPACE_PATTERN.test(value);
|
|
111
|
+
}
|
|
109
112
|
|
|
110
113
|
/** Call after the business mutation commits. A display failure must not retry that mutation. */ async function emitResourceCard(card, config) {
|
|
111
114
|
await dispatchCustomEvent(ChatMessageEventTypeEnum.ON_CHAT_EVENT, createResourceCardContent(card), config);
|
|
@@ -329,10 +332,9 @@ class RequestContext {
|
|
|
329
332
|
* server RequestContext. Authentication guards resolve JWTs, API keys and
|
|
330
333
|
* ChatKit client secrets before this check; the bearer is not always a JWT.
|
|
331
334
|
*/ static hasPermissions(findPermissions, throwError) {
|
|
332
|
-
const permissions = this.currentPermissions();
|
|
333
|
-
if (permissions.
|
|
334
|
-
|
|
335
|
-
if (found.length === findPermissions.length) return true;
|
|
335
|
+
const permissions = new Set(this.currentPermissions());
|
|
336
|
+
if (permissions.size > 0 && findPermissions.every((permission)=>permissions.has(permission))) {
|
|
337
|
+
return true;
|
|
336
338
|
}
|
|
337
339
|
if (throwError) {
|
|
338
340
|
throw new HttpException('Unauthorized', HttpStatus.UNAUTHORIZED);
|
|
@@ -1112,6 +1114,19 @@ const KnowledgebaseProvisioningRuntimeCapability = createRuntimeCapability('plat
|
|
|
1112
1114
|
description: 'Idempotently provision managed platform knowledgebases and connect them to an Agent.'
|
|
1113
1115
|
});
|
|
1114
1116
|
|
|
1117
|
+
/** Knowledgebase discovery is scoped to the authenticated runtime, never caller-supplied identities. */ const knowledgebaseActions = [
|
|
1118
|
+
'knowledgebase.read',
|
|
1119
|
+
'knowledgebase.manage',
|
|
1120
|
+
'content.search',
|
|
1121
|
+
'documents.read',
|
|
1122
|
+
'documents.create',
|
|
1123
|
+
'documents.update',
|
|
1124
|
+
'documents.delete',
|
|
1125
|
+
'documents.process',
|
|
1126
|
+
'chunks.write',
|
|
1127
|
+
'chunks.delete'
|
|
1128
|
+
];
|
|
1129
|
+
|
|
1115
1130
|
const KnowledgeGraphRuntimeCapability = createRuntimeCapability('platform.knowledge-graph', {
|
|
1116
1131
|
description: 'Publish, inspect, and retract source-owned structured knowledge graphs without model extraction.'
|
|
1117
1132
|
});
|
|
@@ -6233,6 +6248,10 @@ function escapeInlineScript(value) {
|
|
|
6233
6248
|
|
|
6234
6249
|
const VIEW_EXTENSION_CACHE_SERVICE_TOKEN = 'XPERT_PLUGIN_VIEW_EXTENSION_CACHE_SERVICE';
|
|
6235
6250
|
|
|
6251
|
+
const ViewMiddlewareRuntimeCapability = createRuntimeCapability('platform.view.middleware-runtime', {
|
|
6252
|
+
description: 'Resolve a View capability through its authorized Assistant middleware and scoped runtime.'
|
|
6253
|
+
});
|
|
6254
|
+
|
|
6236
6255
|
/** Platform-owned real-time collaboration capability available to scoped plugin runtimes. */ const CollaborationRuntimeCapability = createRuntimeCapability('platform.collaboration', {
|
|
6237
6256
|
description: 'Create, synchronize, persist, authorize, and observe platform-managed real-time collaboration documents.'
|
|
6238
6257
|
});
|
|
@@ -10132,4 +10151,4 @@ Reflect.defineMetadata('__command__', {
|
|
|
10132
10151
|
id: ImportDefaultAgentPluginsCommand.type
|
|
10133
10152
|
}, ImportDefaultAgentPluginsCommand);
|
|
10134
10153
|
|
|
10135
|
-
export { ACCOUNT_BINDING_PERMISSION_SERVICE_TOKEN, AGENT_CHAT_DISPATCH_ERROR_STEER_TARGET_NOT_RUNNING, AGENT_CHAT_DISPATCH_MESSAGE_TYPE, AGENT_MIDDLEWARE_STRATEGY, AGENT_RUNTIME_EVENT_MESSAGE_TYPE, AGENT_RUNTIME_STRATEGY, AIModel, AIModelProviderNotFoundException, AIModelProviderRegistry, AIModelProviderStrategy, AI_MODEL_PROVIDER, ASSISTANT_CAPABILITY_PROVIDER, AdapterDataSourceStrategy, AgentExecutionRunnerCapability, AgentExecutionRunnerFactoryCapability, AgentInvocationRuntimeCapability, AgentMiddlewareRegistry, AgentMiddlewareStrategy, AgentRuntimeFactoryCapability, AgentRuntimeRegistry, AgentRuntimeStrategy, AiModelNotFoundException, AssistantCapabilityProvider, AssistantCapabilityProviderRegistry, AssistantTaskRuntimeCapability, BOUND_IDENTITY_LOGIN_PERMISSION_SERVICE_TOKEN, BUILTIN_GLOBAL_SCOPE, BaseHTTPQueryRunner, BaseQueryRunner, BaseSQLQueryRunner, BaseSandbox, BaseStrategyRegistry, BuiltinToolset, CHAT_CHANNEL, CHAT_CHANNEL_TEXT_LIMITS, CLI_MODEL_TOKEN_REFERENCE, COLLABORATION_DOCUMENT_PROVIDER, CONNECTION_COMMAND_ROUTER_TOKEN, CONNECTOR_STRATEGY, CancelConversationCommand, ChatChannel, ChatChannelRegistry, ChatOAICompatReasoningModel, CliModelProfilesCapability, CollaborationDocumentProvider, CollaborationDocumentProviderRegistry, CollaborationRuntimeCapability, CommonParameterRules, ConnectorRuntimeCapability, ConnectorRuntimeFactoryCapability, ConnectorStrategyKey, ConnectorStrategyRegistry, CreateModelClientCommand, CredentialsValidateFailedError, DATASOURCE_STRATEGY, DBCreateTableMode, DBProtocolEnum, DBSyntaxEnum, DBTableAction, DBTableDataAction, DEFAULT_EXECUTION_CONFIG, DEFAULT_SANDBOX_EXECUTION_MAX_OUTPUT_BYTES, DEFAULT_SANDBOX_FILE_OPERATION_EXECUTION_OPTIONS, DEFAULT_SANDBOX_FILE_OPERATION_TIMEOUT_MS, DEFAULT_SANDBOX_FILE_OPERATION_TIMEOUT_SEC, DEFAULT_SANDBOX_FILE_SEARCH_EXECUTION_OPTIONS, DEFAULT_SANDBOX_FILE_SEARCH_TIMEOUT_MS, DEFAULT_SANDBOX_FILE_SEARCH_TIMEOUT_SEC, DEFAULT_SANDBOX_SHELL_EXECUTION_OPTIONS, DEFAULT_SANDBOX_SHELL_TIMEOUT_MS, DEFAULT_SANDBOX_SHELL_TIMEOUT_SEC, DOCUMENT_SOURCE_STRATEGY, DOCUMENT_TRANSFORMER_STRATEGY, DataSourceStrategy, DataSourceStrategyRegistry, DecoratedAgentMiddlewareStrategy, DecoratedToolsetStrategy, DocumentSourceRegistry, DocumentSourceStrategy, DocumentTransformerRegistry, DocumentTransformerStrategy, EVOLUTION_RUNTIME_SERVICE_TOKEN, EVOLUTION_TARGET_PROVIDER, EvolutionBaselineRuntimeCapability, EvolutionChangeRuntimeCapability, EvolutionRuntimeCapability, EvolutionTargetProviderRegistry, EvolutionTargetProviderStrategy, FILE_STORAGE_PROVIDER, FILE_UPLOAD_TARGET_STRATEGY, FileRuntimeCapability, FileStorageProvider, FileStorageProviderRegistry, FileUploadTargetRegistry, FileUploadTargetStrategy, GLOBAL_ORGANIZATION_SCOPE, HANDOFF_PERMISSION_SERVICE_TOKEN, HANDOFF_PROCESSOR_STRATEGY, HANDOFF_QUEUE_SERVICE_TOKEN, HandoffProcessorRegistry, HandoffProcessorStrategy, IMAGE_UNDERSTANDING_STRATEGY, INTEGRATION_PERMISSION_SERVICE_TOKEN, INTEGRATION_STRATEGY, ImageGenerationModel, ImageUnderstandingRegistry, ImageUnderstandingStrategy, ImportDefaultAgentPluginsCommand, IntegrationStrategyKey, IntegrationStrategyRegistry, JUMP_TO_TARGETS, JsonSchemaValidator, KEYWORD_ANALYZER_STRATEGY, KNOWLEDGE_STRATEGY, KeywordAnalyzerRegistry, KeywordAnalyzerStrategy, KnowledgeDocumentVisualAssetsRuntimeCapability, KnowledgeDocumentVisualAssetsRuntimeFactoryCapability, KnowledgeGraphRuntimeCapability, KnowledgeStrategyKey, KnowledgeStrategyRegistry, KnowledgebaseDocumentsRuntimeCapability, KnowledgebaseProvisioningRuntimeCapability, KnowledgebaseRuntimeCapability, LLMUsage, LargeLanguageModel, MANAGED_CONNECTION_REGISTRY_TOKEN, MANAGED_QUEUE_HANDLER_REGISTRY_TOKEN, MANAGED_QUEUE_SERVICE_TOKEN, MCP_CAPABILITY_CHANGE_EVENT_TYPES, MODEL_OUTPUT_VALIDATION_ERROR_CODE, ModelExecutionEnvironmentCapability, ModelOutputValidationError, ModelProvider, ORGANIZATION_METADATA_KEY, OpenAICompatibleReranker, PERMISSION_OPERATION_METADATA_KEY, PLUGIN_CONFIG_RESOLVER_TOKEN, PLUGIN_JOB_PROCESSOR_METADATA, PLUGIN_METADATA, PLUGIN_METADATA_KEY, PLUGIN_VERSION_METADATA_KEY, PLUGIN_WEBHOOK_AUTH_METADATA_KEY, PLUGIN_WEBHOOK_AUTH_SERVICE_TOKEN, PROJECT_TASK_PROVIDER, PROJECT_TYPE_PROVIDER, PROVIDE_AI_MODEL_LLM, PROVIDE_AI_MODEL_MODERATION, PROVIDE_AI_MODEL_RERANK, PROVIDE_AI_MODEL_SPEECH2TEXT, PROVIDE_AI_MODEL_TEXT_EMBEDDING, PROVIDE_AI_MODEL_TTS, PluginJobProcessor, PluginWebhookAuth, PluginWebhookAuthGuard, ProjectTaskProvider, ProjectTaskProviderRegistry, ProjectTasksRuntimeCapability, ProjectTypeProvider, ProjectTypeProviderRegistry, RESOURCE_CARD_EVENT, RESOURCE_CARD_PROVIDER, RETRIEVER_STRATEGY, RequestContext, RequestContextMiddleware, RequirePermissionOperation, RerankModel, ResourceCardProvider, ResourceCardProviderRegistry, RetrieverRegistry, RetrieverStrategy, SANDBOX_PROVIDER, SANDBOX_RUNTIME_PROVIDER, SANDBOX_SHELL_TIMEOUT_LIMITS_SEC, SANDBOX_WORKSPACE_MAPPER, SKILL_SOURCE_PROVIDER, SPEECH_TO_TEXT_PERMISSION_SERVICE_TOKEN, SPEECH_TO_TEXT_SERVICE_TOKEN, SSOProviderRegistry, SSOProviderStrategyKey, SSO_BINDING_PERMISSION_SERVICE_TOKEN, SSO_PROVIDER, STRATEGY_META_KEY, SYSTEM_GLOBAL_SCOPE, SandboxProviderRegistry, SandboxProviderStrategy, SandboxRuntimeProviderRegistry, SandboxRuntimeProviderStrategy, SandboxWorkspaceMapperRegistry, SandboxWorkspaceMapperStrategy, ShellModelExecutionSourceCapability, SkillSourceProviderRegistry, SkillSourceProviderStrategy, Speech2TextChatModel, SpeechToTextModel, StrategyBus, TENANT_GLOBAL_SCOPE_PREFIX, TENANT_GLOBAL_SCOPE_SUFFIX, TEXT_SPLITTER_STRATEGY, TOOLSET_STRATEGY, TextEmbeddingModelManager, TextSplitterRegistry, TextSplitterStrategy, TextToSpeechModel, ToolsetRegistry, ToolsetStrategy, USER_PERMISSION_SERVICE_TOKEN, VECTOR_STORE_STRATEGY, VIDEO_GENERATION_PERMISSION_SERVICE_TOKEN, VIDEO_GENERATION_SERVICE_TOKEN, VIDEO_GENERATOR_FAMILIES, VIEW_EXTENSION_CACHE_SERVICE_TOKEN, VIEW_EXTENSION_PROVIDER, VectorStoreRegistry, VectorStoreStrategy, VideoGenerationModel, ViewExtensionProvider, ViewExtensionProviderRegistry, WORKFLOW_NODE_STRATEGY, WORKFLOW_TRIGGER_STRATEGY, WorkflowNodeRegistry, WorkflowNodeStrategy, WorkflowTriggerRegistry, WorkflowTriggerStrategy, WorkspaceFilesRuntimeCapability, WrapWorkflowNodeExecutionCommand, XPERT_AGENT_MIDDLEWARE_RUNTIME_TOKEN, XPERT_TOOL_METHOD_METADATA, XPERT_TOOL_PROVIDER, XPERT_TOOL_PROVIDER_METADATA, XPERT_TOOL_RESULT_FORMAT_VERSION, XpFileSystem, XpertPrompt, XpertResource, XpertResourceTemplate, XpertServerPlugin, XpertTool, XpertToolProvider, XpertToolProviderCoordinator, XpertToolProviderRegistry, agentInvocationDispatchContextSchema, agentRuntimeConsumptionStateSchema, agentRuntimeDeliveryStateSchema, agentRuntimeEventMessageId, agentRuntimeEventSchema, agentRuntimeReplyTargetSchema, agentRuntimeResultClaimSchema, agentRuntimeResultConsumptionKey, als, appendSandboxMessage, assertConnectorDefinition, buildSandboxTimeoutMessage, calcTokenUsage, calculateLLMUsagePrice, calculateModelPrice, calculateModelUsageCharge, chunkText, countTextTokens, countTokensSafe, createI18nInstance, createPluginLogger, createRuntimeCapability, defineAgentMessageType, defineChannelMessageType, defineMcpApp, defineMcpCapabilities, defineMcpPrompt, defineMcpResource, defineMcpResourceTemplate, defineXpertTool, derivePluginArtifactNamespace, describeXpertToolProvider, downloadRemoteFile, emitResourceCard, formatSandboxTimeout, getDefaultTenantId, getErrorMessage, getModelContextSize, getPermissionOperationMetadata, getPositionList, getPositionMap, getRequestContext, getRequiredPermissionOperation, getTenantGlobalScopeKey, getXpertToolMethod, isAgentInvocationTerminal, isDevelopmentSandboxRuntimeEnvironment, isModelOutputValidationError, isModelUsagePricingConfig, isRemoteFile, isSandboxBackend, isSandboxManagedServiceAdapter, isSandboxServiceProxyAdapter, isSandboxTerminalAdapter, isStrategyInstance, isStructuredMessageType, isTenantGlobalScopeKey, loadYamlFile, mergeCredentials, mergeModelRequirements, mergeParentChildChunks, nativeModelTransport, normalizeContextSize, normalizeTokenUsage, pluginArtifactTableName, prepareToolResult, processAsyncAIGCManagedJob, renderRemoteModuleIframeHtml, renderRemoteReactIframeHtml, renderRemoteVueIframeHtml, resolveModelUsagePricingSnapshot, resolveSandboxBackend, resolveSandboxExecutionOptions, resolveSandboxManagedServiceAdapter, resolveSandboxServiceProxyAdapter, resolveSandboxTerminalAdapter, resolveStrategyMetadataTarget, resolveTenantGlobalScopeKey, resolveTokenUsage, resolveTokenUsageCandidates, resolveXpertMcpExtensions, runWithRequestContext, runtimeToolProviderComponent, secondsToMilliseconds, setDefaultTenantId, sumTokenUsage, taskWaitReason, textTokenBoundaries };
|
|
10154
|
+
export { ACCOUNT_BINDING_PERMISSION_SERVICE_TOKEN, AGENT_CHAT_DISPATCH_ERROR_STEER_TARGET_NOT_RUNNING, AGENT_CHAT_DISPATCH_MESSAGE_TYPE, AGENT_MIDDLEWARE_STRATEGY, AGENT_RUNTIME_EVENT_MESSAGE_TYPE, AGENT_RUNTIME_STRATEGY, AIModel, AIModelProviderNotFoundException, AIModelProviderRegistry, AIModelProviderStrategy, AI_MODEL_PROVIDER, ASSISTANT_CAPABILITY_PROVIDER, AdapterDataSourceStrategy, AgentExecutionRunnerCapability, AgentExecutionRunnerFactoryCapability, AgentInvocationRuntimeCapability, AgentMiddlewareRegistry, AgentMiddlewareStrategy, AgentRuntimeFactoryCapability, AgentRuntimeRegistry, AgentRuntimeStrategy, AiModelNotFoundException, AssistantCapabilityProvider, AssistantCapabilityProviderRegistry, AssistantTaskRuntimeCapability, BOUND_IDENTITY_LOGIN_PERMISSION_SERVICE_TOKEN, BUILTIN_GLOBAL_SCOPE, BaseHTTPQueryRunner, BaseQueryRunner, BaseSQLQueryRunner, BaseSandbox, BaseStrategyRegistry, BuiltinToolset, CHAT_CHANNEL, CHAT_CHANNEL_TEXT_LIMITS, CLI_MODEL_TOKEN_REFERENCE, COLLABORATION_DOCUMENT_PROVIDER, CONNECTION_COMMAND_ROUTER_TOKEN, CONNECTOR_STRATEGY, CancelConversationCommand, ChatChannel, ChatChannelRegistry, ChatOAICompatReasoningModel, CliModelProfilesCapability, CollaborationDocumentProvider, CollaborationDocumentProviderRegistry, CollaborationRuntimeCapability, CommonParameterRules, ConnectorRuntimeCapability, ConnectorRuntimeFactoryCapability, ConnectorStrategyKey, ConnectorStrategyRegistry, CreateModelClientCommand, CredentialsValidateFailedError, DATASOURCE_STRATEGY, DBCreateTableMode, DBProtocolEnum, DBSyntaxEnum, DBTableAction, DBTableDataAction, DEFAULT_EXECUTION_CONFIG, DEFAULT_SANDBOX_EXECUTION_MAX_OUTPUT_BYTES, DEFAULT_SANDBOX_FILE_OPERATION_EXECUTION_OPTIONS, DEFAULT_SANDBOX_FILE_OPERATION_TIMEOUT_MS, DEFAULT_SANDBOX_FILE_OPERATION_TIMEOUT_SEC, DEFAULT_SANDBOX_FILE_SEARCH_EXECUTION_OPTIONS, DEFAULT_SANDBOX_FILE_SEARCH_TIMEOUT_MS, DEFAULT_SANDBOX_FILE_SEARCH_TIMEOUT_SEC, DEFAULT_SANDBOX_SHELL_EXECUTION_OPTIONS, DEFAULT_SANDBOX_SHELL_TIMEOUT_MS, DEFAULT_SANDBOX_SHELL_TIMEOUT_SEC, DOCUMENT_SOURCE_STRATEGY, DOCUMENT_TRANSFORMER_STRATEGY, DataSourceStrategy, DataSourceStrategyRegistry, DecoratedAgentMiddlewareStrategy, DecoratedToolsetStrategy, DocumentSourceRegistry, DocumentSourceStrategy, DocumentTransformerRegistry, DocumentTransformerStrategy, EVOLUTION_RUNTIME_SERVICE_TOKEN, EVOLUTION_TARGET_PROVIDER, EvolutionBaselineRuntimeCapability, EvolutionChangeRuntimeCapability, EvolutionRuntimeCapability, EvolutionTargetProviderRegistry, EvolutionTargetProviderStrategy, FILE_STORAGE_PROVIDER, FILE_UPLOAD_TARGET_STRATEGY, FileRuntimeCapability, FileStorageProvider, FileStorageProviderRegistry, FileUploadTargetRegistry, FileUploadTargetStrategy, GLOBAL_ORGANIZATION_SCOPE, HANDOFF_PERMISSION_SERVICE_TOKEN, HANDOFF_PROCESSOR_STRATEGY, HANDOFF_QUEUE_SERVICE_TOKEN, HandoffProcessorRegistry, HandoffProcessorStrategy, IMAGE_UNDERSTANDING_STRATEGY, INTEGRATION_PERMISSION_SERVICE_TOKEN, INTEGRATION_STRATEGY, ImageGenerationModel, ImageUnderstandingRegistry, ImageUnderstandingStrategy, ImportDefaultAgentPluginsCommand, IntegrationStrategyKey, IntegrationStrategyRegistry, JUMP_TO_TARGETS, JsonSchemaValidator, KEYWORD_ANALYZER_STRATEGY, KNOWLEDGE_STRATEGY, KeywordAnalyzerRegistry, KeywordAnalyzerStrategy, KnowledgeDocumentVisualAssetsRuntimeCapability, KnowledgeDocumentVisualAssetsRuntimeFactoryCapability, KnowledgeGraphRuntimeCapability, KnowledgeStrategyKey, KnowledgeStrategyRegistry, KnowledgebaseDocumentsRuntimeCapability, KnowledgebaseProvisioningRuntimeCapability, KnowledgebaseRuntimeCapability, LLMUsage, LargeLanguageModel, MANAGED_CONNECTION_REGISTRY_TOKEN, MANAGED_QUEUE_HANDLER_REGISTRY_TOKEN, MANAGED_QUEUE_SERVICE_TOKEN, MCP_CAPABILITY_CHANGE_EVENT_TYPES, MODEL_OUTPUT_VALIDATION_ERROR_CODE, ModelExecutionEnvironmentCapability, ModelOutputValidationError, ModelProvider, ORGANIZATION_METADATA_KEY, OpenAICompatibleReranker, PERMISSION_OPERATION_METADATA_KEY, PLUGIN_CONFIG_RESOLVER_TOKEN, PLUGIN_JOB_PROCESSOR_METADATA, PLUGIN_METADATA, PLUGIN_METADATA_KEY, PLUGIN_VERSION_METADATA_KEY, PLUGIN_WEBHOOK_AUTH_METADATA_KEY, PLUGIN_WEBHOOK_AUTH_SERVICE_TOKEN, PROJECT_TASK_PROVIDER, PROJECT_TYPE_PROVIDER, PROVIDE_AI_MODEL_LLM, PROVIDE_AI_MODEL_MODERATION, PROVIDE_AI_MODEL_RERANK, PROVIDE_AI_MODEL_SPEECH2TEXT, PROVIDE_AI_MODEL_TEXT_EMBEDDING, PROVIDE_AI_MODEL_TTS, PluginJobProcessor, PluginWebhookAuth, PluginWebhookAuthGuard, ProjectTaskProvider, ProjectTaskProviderRegistry, ProjectTasksRuntimeCapability, ProjectTypeProvider, ProjectTypeProviderRegistry, RESOURCE_CARD_EVENT, RESOURCE_CARD_PROVIDER, RETRIEVER_STRATEGY, RequestContext, RequestContextMiddleware, RequirePermissionOperation, RerankModel, ResourceCardProvider, ResourceCardProviderRegistry, RetrieverRegistry, RetrieverStrategy, SANDBOX_PROVIDER, SANDBOX_RUNTIME_PROVIDER, SANDBOX_SHELL_TIMEOUT_LIMITS_SEC, SANDBOX_WORKSPACE_MAPPER, SKILL_SOURCE_PROVIDER, SPEECH_TO_TEXT_PERMISSION_SERVICE_TOKEN, SPEECH_TO_TEXT_SERVICE_TOKEN, SSOProviderRegistry, SSOProviderStrategyKey, SSO_BINDING_PERMISSION_SERVICE_TOKEN, SSO_PROVIDER, STRATEGY_META_KEY, SYSTEM_GLOBAL_SCOPE, SandboxProviderRegistry, SandboxProviderStrategy, SandboxRuntimeProviderRegistry, SandboxRuntimeProviderStrategy, SandboxWorkspaceMapperRegistry, SandboxWorkspaceMapperStrategy, ShellModelExecutionSourceCapability, SkillSourceProviderRegistry, SkillSourceProviderStrategy, Speech2TextChatModel, SpeechToTextModel, StrategyBus, TENANT_GLOBAL_SCOPE_PREFIX, TENANT_GLOBAL_SCOPE_SUFFIX, TEXT_SPLITTER_STRATEGY, TOOLSET_STRATEGY, TextEmbeddingModelManager, TextSplitterRegistry, TextSplitterStrategy, TextToSpeechModel, ToolsetRegistry, ToolsetStrategy, USER_PERMISSION_SERVICE_TOKEN, VECTOR_STORE_STRATEGY, VIDEO_GENERATION_PERMISSION_SERVICE_TOKEN, VIDEO_GENERATION_SERVICE_TOKEN, VIDEO_GENERATOR_FAMILIES, VIEW_EXTENSION_CACHE_SERVICE_TOKEN, VIEW_EXTENSION_PROVIDER, VectorStoreRegistry, VectorStoreStrategy, VideoGenerationModel, ViewExtensionProvider, ViewExtensionProviderRegistry, ViewMiddlewareRuntimeCapability, WORKFLOW_NODE_STRATEGY, WORKFLOW_TRIGGER_STRATEGY, WorkflowNodeRegistry, WorkflowNodeStrategy, WorkflowTriggerRegistry, WorkflowTriggerStrategy, WorkspaceFilesRuntimeCapability, WrapWorkflowNodeExecutionCommand, XPERT_AGENT_MIDDLEWARE_RUNTIME_TOKEN, XPERT_TOOL_METHOD_METADATA, XPERT_TOOL_PROVIDER, XPERT_TOOL_PROVIDER_METADATA, XPERT_TOOL_RESULT_FORMAT_VERSION, XpFileSystem, XpertPrompt, XpertResource, XpertResourceTemplate, XpertServerPlugin, XpertTool, XpertToolProvider, XpertToolProviderCoordinator, XpertToolProviderRegistry, agentInvocationDispatchContextSchema, agentRuntimeConsumptionStateSchema, agentRuntimeDeliveryStateSchema, agentRuntimeEventMessageId, agentRuntimeEventSchema, agentRuntimeReplyTargetSchema, agentRuntimeResultClaimSchema, agentRuntimeResultConsumptionKey, als, appendSandboxMessage, assertConnectorDefinition, buildSandboxTimeoutMessage, calcTokenUsage, calculateLLMUsagePrice, calculateModelPrice, calculateModelUsageCharge, chunkText, countTextTokens, countTokensSafe, createI18nInstance, createPluginLogger, createRuntimeCapability, defineAgentMessageType, defineChannelMessageType, defineMcpApp, defineMcpCapabilities, defineMcpPrompt, defineMcpResource, defineMcpResourceTemplate, defineXpertTool, derivePluginArtifactNamespace, describeXpertToolProvider, downloadRemoteFile, emitResourceCard, formatSandboxTimeout, getDefaultTenantId, getErrorMessage, getModelContextSize, getPermissionOperationMetadata, getPositionList, getPositionMap, getRequestContext, getRequiredPermissionOperation, getTenantGlobalScopeKey, getXpertToolMethod, isAgentInvocationTerminal, isDevelopmentSandboxRuntimeEnvironment, isModelOutputValidationError, isModelUsagePricingConfig, isPluginArtifactNamespace, isRemoteFile, isSandboxBackend, isSandboxManagedServiceAdapter, isSandboxServiceProxyAdapter, isSandboxTerminalAdapter, isStrategyInstance, isStructuredMessageType, isTenantGlobalScopeKey, knowledgebaseActions, loadYamlFile, mergeCredentials, mergeModelRequirements, mergeParentChildChunks, nativeModelTransport, normalizeContextSize, normalizeTokenUsage, pluginArtifactTableName, prepareToolResult, processAsyncAIGCManagedJob, renderRemoteModuleIframeHtml, renderRemoteReactIframeHtml, renderRemoteVueIframeHtml, resolveModelUsagePricingSnapshot, resolveSandboxBackend, resolveSandboxExecutionOptions, resolveSandboxManagedServiceAdapter, resolveSandboxServiceProxyAdapter, resolveSandboxTerminalAdapter, resolveStrategyMetadataTarget, resolveTenantGlobalScopeKey, resolveTokenUsage, resolveTokenUsageCandidates, resolveXpertMcpExtensions, runWithRequestContext, runtimeToolProviderComponent, secondsToMilliseconds, setDefaultTenantId, sumTokenUsage, taskWaitReason, textTokenBoundaries };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xpert-ai/plugin-sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.22.0",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@langchain/openai": "0.6.9",
|
|
65
|
-
"@xpert-ai/contracts": "3.21.
|
|
65
|
+
"@xpert-ai/contracts": "3.21.1",
|
|
66
66
|
"express": "^4.22.1",
|
|
67
67
|
"js-tiktoken": "^1.0.21"
|
|
68
68
|
},
|
|
@@ -8,3 +8,4 @@ export declare function derivePluginArtifactNamespace(packageName: string): stri
|
|
|
8
8
|
* Keep table keys stable; the returned name is part of the plugin data contract.
|
|
9
9
|
*/
|
|
10
10
|
export declare function pluginArtifactTableName(namespace: string, tableKey: string): string;
|
|
11
|
+
export declare function isPluginArtifactNamespace(value: unknown): value is string;
|
|
@@ -3,6 +3,11 @@ import type { ConnectorRuntimeApi } from './strategy.interface';
|
|
|
3
3
|
export declare const ConnectorRuntimeCapability: import("../core").RuntimeCapabilityKey<ConnectorRuntimeApi>;
|
|
4
4
|
/** No binding or provider grants means no connector access. */
|
|
5
5
|
export type ConnectorRuntimeScope = RuntimeIdentityScope & {
|
|
6
|
+
/** Server-owned View host identity, set only after the host authorizes the Assistant and its graph. */
|
|
7
|
+
viewHost?: {
|
|
8
|
+
type: 'agent';
|
|
9
|
+
id: string;
|
|
10
|
+
};
|
|
6
11
|
/** Host-validated Agent Plugin dependencies may use their workspace binding in an authorized project. */
|
|
7
12
|
allowWorkspaceBindingsInProject?: boolean;
|
|
8
13
|
/** Host-selected bindings, including IDs pinned by enabled graph Connector nodes. */
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/** Knowledgebase discovery is scoped to the authenticated runtime, never caller-supplied identities. */
|
|
2
|
+
export declare const knowledgebaseActions: readonly ["knowledgebase.read", "knowledgebase.manage", "content.search", "documents.read", "documents.create", "documents.update", "documents.delete", "documents.process", "chunks.write", "chunks.delete"];
|
|
3
|
+
export type KnowledgebaseAction = (typeof knowledgebaseActions)[number];
|
|
4
|
+
export type KnowledgebaseQuery = {
|
|
5
|
+
scope: {
|
|
6
|
+
kind: 'workspace';
|
|
7
|
+
workspaceId: string;
|
|
8
|
+
relation: 'owned' | 'available';
|
|
9
|
+
} | {
|
|
10
|
+
kind: 'organization';
|
|
11
|
+
} | {
|
|
12
|
+
kind: 'tenant';
|
|
13
|
+
};
|
|
14
|
+
filter?: {
|
|
15
|
+
/** Literal name/description substring, not content retrieval. */
|
|
16
|
+
text?: string;
|
|
17
|
+
visibility?: 'private' | 'organization' | 'public';
|
|
18
|
+
applicationTags?: {
|
|
19
|
+
allOf: string[];
|
|
20
|
+
};
|
|
21
|
+
publication?: 'published' | 'unpublished';
|
|
22
|
+
};
|
|
23
|
+
access?: {
|
|
24
|
+
requireAll: KnowledgebaseAction[];
|
|
25
|
+
};
|
|
26
|
+
page?: {
|
|
27
|
+
limit?: number;
|
|
28
|
+
cursor?: string;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export type KnowledgebaseSummary = {
|
|
32
|
+
id: string;
|
|
33
|
+
name: string;
|
|
34
|
+
description: string | null;
|
|
35
|
+
workspaceId: string | null;
|
|
36
|
+
visibility: 'private' | 'organization' | 'public';
|
|
37
|
+
applicationTags: string[];
|
|
38
|
+
type: string | null;
|
|
39
|
+
status: string | null;
|
|
40
|
+
published: boolean;
|
|
41
|
+
documentNum: number;
|
|
42
|
+
chunkNum: number;
|
|
43
|
+
};
|
|
44
|
+
export type KnowledgebasePage = {
|
|
45
|
+
items: KnowledgebaseSummary[];
|
|
46
|
+
/** Follow even when items is empty; authorization is re-evaluated on every page. */
|
|
47
|
+
nextCursor: string | null;
|
|
48
|
+
};
|
|
49
|
+
export type KnowledgebaseDetail = KnowledgebaseSummary & {
|
|
50
|
+
capabilities: {
|
|
51
|
+
documentIngestion: boolean;
|
|
52
|
+
};
|
|
53
|
+
configuration: {
|
|
54
|
+
embeddingConfigured: boolean;
|
|
55
|
+
};
|
|
56
|
+
processing: {
|
|
57
|
+
blocked: boolean;
|
|
58
|
+
reason: 'rebuilding' | 'embedding_not_configured' | 'unsupported_type' | null;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
export type KnowledgebaseGetInput = {
|
|
62
|
+
knowledgebaseId: string;
|
|
63
|
+
};
|
|
64
|
+
export type KnowledgebaseAccessInput = {
|
|
65
|
+
knowledgebaseIds: string[];
|
|
66
|
+
actions: KnowledgebaseAction[];
|
|
67
|
+
};
|
|
68
|
+
export type KnowledgebaseAccessResult = {
|
|
69
|
+
items: Array<{
|
|
70
|
+
knowledgebaseId: string;
|
|
71
|
+
/** Missing and inaccessible resources have the same unavailable result. */
|
|
72
|
+
status: 'available' | 'unavailable';
|
|
73
|
+
actions: Array<{
|
|
74
|
+
action: KnowledgebaseAction;
|
|
75
|
+
allowed: boolean;
|
|
76
|
+
}>;
|
|
77
|
+
}>;
|
|
78
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { JSONValue, KnowledgeFilterDiagnostics, KnowledgeFilterNode } from '@xpert-ai/contracts';
|
|
2
|
+
import type { KnowledgebaseQuery, KnowledgebasePage, KnowledgebaseGetInput, KnowledgebaseDetail, KnowledgebaseAccessInput, KnowledgebaseAccessResult } from './knowledgebase-catalog';
|
|
2
3
|
export type KnowledgebaseRetrievalMode = 'vector' | 'keyword' | 'graph' | 'hybrid';
|
|
3
4
|
export type KnowledgebaseMetadata = Record<string, JSONValue>;
|
|
4
5
|
export type KnowledgebaseRetrievalSettings = {
|
|
@@ -176,14 +177,78 @@ export type KnowledgebaseConnectAgentResult = {
|
|
|
176
177
|
knowledgebaseIds: string[];
|
|
177
178
|
addedKnowledgebaseIds: string[];
|
|
178
179
|
};
|
|
180
|
+
/**
|
|
181
|
+
* Set up application-managed libraries and Agent connections using trusted configuration.
|
|
182
|
+
* Use during installation/configuration; use KnowledgebaseApi for runtime discovery and
|
|
183
|
+
* retrieval, and the document capability for ingestion. Provisioning retains host access checks.
|
|
184
|
+
*/
|
|
179
185
|
export interface KnowledgebaseProvisioningApi {
|
|
186
|
+
/**
|
|
187
|
+
* Reconcile declared libraries by stable namespace/key, creating missing resources
|
|
188
|
+
* and updating managed settings. Preserve keys across retries to avoid duplicate libraries.
|
|
189
|
+
* Tenant provisioning requires an administrator already in tenant scope.
|
|
190
|
+
*/
|
|
180
191
|
ensure(input: KnowledgebaseEnsureInput): Promise<KnowledgebaseEnsureResult>;
|
|
192
|
+
/**
|
|
193
|
+
* Connect selected libraries and optional retrieval policies to an existing Agent.
|
|
194
|
+
* Existing connections are retained; repeated connections are not duplicated.
|
|
195
|
+
* Supply Agent/workspace identity from trusted configuration; binding does not grant access.
|
|
196
|
+
*/
|
|
181
197
|
connectAgent(input: KnowledgebaseConnectAgentInput): Promise<KnowledgebaseConnectAgentResult>;
|
|
182
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Discover knowledgebase resources and consume indexed knowledge through the host runtime.
|
|
201
|
+
* Keep resource discovery (query), readiness (get), permissions (getAccess) and content
|
|
202
|
+
* retrieval (search) separate. Use the document capability for ingestion/lifecycle,
|
|
203
|
+
* and the provisioning capability for managed setup and Agent connections.
|
|
204
|
+
* Catalog methods use trusted request context; permission checks never authorize later
|
|
205
|
+
* writes. Feature-detect optional methods on older hosts and require an upgrade if needed.
|
|
206
|
+
*/
|
|
183
207
|
export interface KnowledgebaseApi {
|
|
208
|
+
/**
|
|
209
|
+
* Legacy discovery; preserves existing scope, shared-library semantics and array results.
|
|
210
|
+
* @deprecated Use query for new integrations. Migrate scope and pagination explicitly;
|
|
211
|
+
* a readable result does not establish write permission.
|
|
212
|
+
*/
|
|
184
213
|
list(input: KnowledgebaseListInput): Promise<KnowledgebaseListItem[]>;
|
|
214
|
+
/**
|
|
215
|
+
* Discover resources by scope, metadata and required actions. Use workspace/owned
|
|
216
|
+
* for destinations belonging to that workspace; use search for indexed content.
|
|
217
|
+
* Follow nextCursor until null, even after empty pages. Cursors bind query/context,
|
|
218
|
+
* not a snapshot or permission grant; every page rechecks access.
|
|
219
|
+
*/
|
|
220
|
+
query?(input: KnowledgebaseQuery): Promise<KnowledgebasePage>;
|
|
221
|
+
/**
|
|
222
|
+
* Read safe resource metadata, ingestion capability and processing readiness.
|
|
223
|
+
* Combine with getAccess before costly work: readiness and permission are independent,
|
|
224
|
+
* and a configured model binding does not guarantee provider health.
|
|
225
|
+
* Missing and unreadable resources produce the same unavailable error.
|
|
226
|
+
*/
|
|
227
|
+
get?(input: KnowledgebaseGetInput): Promise<KnowledgebaseDetail>;
|
|
228
|
+
/**
|
|
229
|
+
* Inspect current action permissions for known IDs; use query to discover candidates.
|
|
230
|
+
* Missing and inaccessible IDs both return unavailable with denied actions.
|
|
231
|
+
* Recheck after long-running work and retain authorization on actual mutations.
|
|
232
|
+
*/
|
|
233
|
+
getAccess?(input: KnowledgebaseAccessInput): Promise<KnowledgebaseAccessResult>;
|
|
234
|
+
/**
|
|
235
|
+
* Retrieve indexed content from selected libraries using retrieval modes and filters.
|
|
236
|
+
* Preserve metadata for citations/provenance and use diagnostics to explain filtering.
|
|
237
|
+
* Derive legacy identity overrides from trusted context, never model-authored input.
|
|
238
|
+
*/
|
|
185
239
|
search(input: KnowledgebaseSearchInput): Promise<KnowledgebaseSearchResult>;
|
|
240
|
+
/**
|
|
241
|
+
* Write a small Agent-managed knowledge item into a connected library. Stable writeKey
|
|
242
|
+
* values allow replay detection; existing writes are skipped, not replaced. Use a stable
|
|
243
|
+
* document key for an independent projection. Use the document capability for file
|
|
244
|
+
* ingestion and durable processing, and trusted configuration for Agent bindings.
|
|
245
|
+
*/
|
|
186
246
|
writeChunk(input: KnowledgebaseWriteChunkInput): Promise<KnowledgebaseWriteChunkResult>;
|
|
247
|
+
/**
|
|
248
|
+
* Remove Agent-managed writes by exact keys or a narrow application prefix.
|
|
249
|
+
* Match documentKey to the write target; optionally remove its empty managed document.
|
|
250
|
+
* A missing target is a no-op. Use the document capability for ordinary document deletion.
|
|
251
|
+
*/
|
|
187
252
|
deleteChunks(input: KnowledgebaseDeleteChunksInput): Promise<KnowledgebaseDeleteChunksResult>;
|
|
188
253
|
}
|
|
189
254
|
export declare const KnowledgebaseRuntimeCapability: import("../../core/runtime-capability").RuntimeCapabilityKey<KnowledgebaseApi>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { WorkspaceAppDataOptions, WorkspaceStorage } from './workspace-storage';
|
|
1
2
|
/** Logical workspace volume catalog supported by plugin-facing file APIs. */
|
|
2
3
|
export type WorkspaceFileCatalog = 'projects' | 'users' | 'knowledges' | 'skills' | 'xperts' | 'user-xperts';
|
|
3
4
|
/** Stable source identifier for portable workspace file references. */
|
|
@@ -232,6 +233,9 @@ export type WorkspaceSearchUnderstandingChunksInput = WorkspaceFileScope & {
|
|
|
232
233
|
* understanding files in Xpert workspace Volumes.
|
|
233
234
|
*/
|
|
234
235
|
export interface WorkspaceFilesApi {
|
|
236
|
+
/** Managed .apps data in the bound Assistant workspace. Each operation reauthorizes the actor.
|
|
237
|
+
* Ordinary Files/sandbox access cannot access this namespace. Requires a scoped runtime API. */
|
|
238
|
+
appData(options: WorkspaceAppDataOptions): WorkspaceStorage;
|
|
235
239
|
/** Host-bound storage identity for restoring the same scope in durable jobs. */
|
|
236
240
|
readonly scope?: Readonly<WorkspaceFileScope>;
|
|
237
241
|
/** Upload raw bytes into an explicitly scoped workspace Volume. */
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Durable application state inside an authorized Assistant workspace.
|
|
2
|
+
* Paths and lock keys are canonical relative paths: no empty, dot or .locks segments.
|
|
3
|
+
* Handles stay bound to their first authorized volume; recreate them after a workspace policy change. */
|
|
4
|
+
export interface WorkspaceStorage {
|
|
5
|
+
read(path: string): Promise<Buffer>;
|
|
6
|
+
write(path: string, content: string | Uint8Array): Promise<void>;
|
|
7
|
+
mkdir(path: string): Promise<void>;
|
|
8
|
+
list(path: string): Promise<string[]>;
|
|
9
|
+
remove(path: string): Promise<void>;
|
|
10
|
+
/** Shared-filesystem mutex renewed by confirmed heartbeats. Lock loss rejects subsequent
|
|
11
|
+
* app-data and ordinary Volume mutations in the callback, including detached work. */
|
|
12
|
+
withLock<T>(key: string, action: () => Promise<T>, options?: {
|
|
13
|
+
waitMs?: number;
|
|
14
|
+
}): Promise<T>;
|
|
15
|
+
}
|
|
16
|
+
/** Host resolves the namespace from this loaded plugin's metadata, never from a filesystem path.
|
|
17
|
+
* Native plugins are trusted server code; this handle is not a sandbox for malicious plugin code. */
|
|
18
|
+
export interface WorkspaceAppDataOptions {
|
|
19
|
+
pluginName: string;
|
|
20
|
+
/** Opt in for personal data; shared Assistant workspaces otherwise remain supported. */
|
|
21
|
+
requireUserIsolation?: boolean;
|
|
22
|
+
}
|
|
@@ -3,4 +3,5 @@ export * from './provider.interface';
|
|
|
3
3
|
export * from './provider.registry';
|
|
4
4
|
export * from './remote-component-html';
|
|
5
5
|
export * from './tokens';
|
|
6
|
+
export * from './middleware-runtime';
|
|
6
7
|
export { ASSISTANT_CHAT_SEND_MESSAGE_COMMAND, ASSISTANT_CONTEXT_SET_COMMAND } from '@xpert-ai/contracts';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { IWFNMiddleware, XpertResolvedViewHostContext } from '@xpert-ai/contracts';
|
|
2
|
+
import type { IAgentMiddlewareContext } from '../agent/middleware/strategy.interface';
|
|
3
|
+
/** Server-only input: use the authorized context received by a View provider, never iframe input. */
|
|
4
|
+
export interface ViewMiddlewareRuntimeInput {
|
|
5
|
+
context: XpertResolvedViewHostContext;
|
|
6
|
+
provider: string;
|
|
7
|
+
requiredFeature: string;
|
|
8
|
+
/** Authoring requires the same draft access policy as the Agent View host. Defaults to published. */
|
|
9
|
+
isDraft?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/** Contains trusted configuration and callable capabilities. Never serialize this result to a Remote View. */
|
|
12
|
+
export interface ViewMiddlewareRuntimeResult {
|
|
13
|
+
options: IWFNMiddleware['options'];
|
|
14
|
+
context: IAgentMiddlewareContext;
|
|
15
|
+
}
|
|
16
|
+
export interface ViewMiddlewareRuntimeResolver {
|
|
17
|
+
/** Revalidates identity, host access, the exact connected middleware and its Feature on every call. */
|
|
18
|
+
resolve(input: ViewMiddlewareRuntimeInput): Promise<ViewMiddlewareRuntimeResult>;
|
|
19
|
+
}
|
|
20
|
+
export declare const ViewMiddlewareRuntimeCapability: import("../core/runtime-capability").RuntimeCapabilityKey<ViewMiddlewareRuntimeResolver>;
|
package/PERMISSIONS.md
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
# 插件权限设计指南
|
|
2
|
-
|
|
3
|
-
:::tip
|
|
4
|
-
在 meta 中设计一套可以向核心系统反向请求 大模型 调用权限的(如请求一个 OpenAI Client实例)的配置,例如在 meta中声明大模型的权限请求,在 configSchema 中设计属性让用户配置具体的模型提供商和模型名称,核心系统在识别到权限请求时会根据 config 中用户配置的具体参数实例化大模型 Client 通过 config 传入到 understandImages 这个方法:
|
|
5
|
-
:::
|
|
6
|
-
|
|
7
|
-
👌明白了,你希望 **在插件 Strategy 的 meta 中声明依赖的大模型权限请求**,核心系统解析后根据用户配置(模型提供商 + 模型名称 + 其他参数)自动注入一个 `client` 到 `config`,这样插件不用自己创建 OpenAI / Anthropic / 其他 VLM 客户端。
|
|
8
|
-
|
|
9
|
-
我帮你重新设计 `OpenAIGPT4VStrategy` 的 meta 和 configSchema,使它能 **反向请求核心系统提供的 Client**。
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
## 新版 Strategy
|
|
14
|
-
|
|
15
|
-
```ts
|
|
16
|
-
import { Injectable } from '@nestjs/common';
|
|
17
|
-
import { Document } from 'langchain/document';
|
|
18
|
-
import {
|
|
19
|
-
ImageUnderstandingStrategy,
|
|
20
|
-
IImageUnderstandingStrategy,
|
|
21
|
-
TImageUnderstandingFile,
|
|
22
|
-
TImageUnderstandingResult
|
|
23
|
-
} from './strategy.interface';
|
|
24
|
-
|
|
25
|
-
@Injectable()
|
|
26
|
-
@ImageUnderstandingStrategy('openai-gpt4v')
|
|
27
|
-
export class OpenAIGPT4VStrategy implements IImageUnderstandingStrategy<any> {
|
|
28
|
-
readonly meta = {
|
|
29
|
-
name: 'openai-gpt4v',
|
|
30
|
-
label: { en: 'OpenAI GPT-4 Vision', zh: 'OpenAI GPT-4 图像理解' },
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* 权限声明:告诉核心系统,这个插件需要一个 "llm" 权限,
|
|
34
|
-
* 提供方是 openai,能力是 vision。
|
|
35
|
-
* 核心系统识别后会根据 config.provider + config.model 实例化对应的 Client,
|
|
36
|
-
* 并注入到 config.client
|
|
37
|
-
*/
|
|
38
|
-
permissions: [
|
|
39
|
-
{
|
|
40
|
-
type: 'llm',
|
|
41
|
-
provider: 'openai',
|
|
42
|
-
capability: 'vision',
|
|
43
|
-
},
|
|
44
|
-
],
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* 配置 schema,用户需要填写 provider 和 model,
|
|
48
|
-
* 核心系统会根据 provider + model + 用户账号 API Key,
|
|
49
|
-
* 实例化好 Client 注入。
|
|
50
|
-
*/
|
|
51
|
-
configSchema: {
|
|
52
|
-
type: 'object',
|
|
53
|
-
properties: {
|
|
54
|
-
provider: {
|
|
55
|
-
type: 'string',
|
|
56
|
-
enum: ['openai'],
|
|
57
|
-
description: '模型提供商'
|
|
58
|
-
},
|
|
59
|
-
model: {
|
|
60
|
-
type: 'string',
|
|
61
|
-
default: 'gpt-4-vision-preview',
|
|
62
|
-
description: '大模型名称'
|
|
63
|
-
},
|
|
64
|
-
prompt: {
|
|
65
|
-
type: 'string',
|
|
66
|
-
default: 'Describe this image in detail.',
|
|
67
|
-
description: '提示词(可以自定义理解任务)'
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
required: ['provider', 'model']
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
icon: {
|
|
74
|
-
svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><circle cx="10" cy="10" r="8" stroke="black" fill="none"/><text x="6" y="14">VLM</text></svg>',
|
|
75
|
-
color: '#10a37f'
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
async validateConfig(config: any): Promise<void> {
|
|
80
|
-
if (!config.client) {
|
|
81
|
-
throw new Error('Missing injected LLM client in config. Core system must inject client.');
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async understandImages(
|
|
86
|
-
files: TImageUnderstandingFile[],
|
|
87
|
-
config: any
|
|
88
|
-
): Promise<TImageUnderstandingResult[]> {
|
|
89
|
-
const client = config.client; // ✅ 已由核心系统注入
|
|
90
|
-
const results: TImageUnderstandingResult[] = [];
|
|
91
|
-
|
|
92
|
-
for (const file of files) {
|
|
93
|
-
const description = await this.runGPT4V(client, file.path, config);
|
|
94
|
-
|
|
95
|
-
const doc = new Document({
|
|
96
|
-
pageContent: description,
|
|
97
|
-
metadata: {
|
|
98
|
-
chunkId: `img-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
99
|
-
parentChunkId: file.parentChunkId,
|
|
100
|
-
imagePath: file.path,
|
|
101
|
-
source: file.filename,
|
|
102
|
-
type: 'vlm',
|
|
103
|
-
engine: config.model
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
results.push({
|
|
108
|
-
docs: [doc],
|
|
109
|
-
metadata: { engine: config.model, file: file.filename }
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return results;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
private async runGPT4V(client: any, imagePath: string, config: any): Promise<string> {
|
|
117
|
-
// client 已经是 openai client,由核心系统实例化
|
|
118
|
-
const response = await client.chat.completions.create({
|
|
119
|
-
model: config.model,
|
|
120
|
-
messages: [
|
|
121
|
-
{
|
|
122
|
-
role: 'user',
|
|
123
|
-
content: [
|
|
124
|
-
{ type: 'text', text: config.prompt || 'Describe this image in detail.' },
|
|
125
|
-
{ type: 'image_url', image_url: { url: imagePath } }
|
|
126
|
-
]
|
|
127
|
-
}
|
|
128
|
-
],
|
|
129
|
-
max_tokens: 500
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
return response.choices[0]?.message?.content || '';
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
---
|
|
138
|
-
|
|
139
|
-
## 🔑 核心系统如何处理
|
|
140
|
-
|
|
141
|
-
* 解析插件的 `meta.permissions`,发现需要:
|
|
142
|
-
|
|
143
|
-
```json
|
|
144
|
-
{ "type": "llm", "provider": "openai", "capability": "vision" }
|
|
145
|
-
```
|
|
146
|
-
* 根据用户 `config.provider = "openai"`, `config.model = "gpt-4-vision-preview"`
|
|
147
|
-
实例化 `OpenAI({ apiKey: userApiKey })`
|
|
148
|
-
* 将 client 注入到 `config.client`
|
|
149
|
-
* 调用 `strategy.understandImages(files, config)`
|
|
150
|
-
|
|
151
|
-
---
|
|
152
|
-
|
|
153
|
-
## 📌 使用示例
|
|
154
|
-
|
|
155
|
-
```ts
|
|
156
|
-
const strategy = this.imageUnderstandingRegistry.get('openai-gpt4v');
|
|
157
|
-
const result = await strategy.understandImages(
|
|
158
|
-
[
|
|
159
|
-
{
|
|
160
|
-
path: 'https://example.com/chart.png',
|
|
161
|
-
filename: 'chart.png',
|
|
162
|
-
extname: 'png',
|
|
163
|
-
parentChunkId: 'uuid-123'
|
|
164
|
-
}
|
|
165
|
-
],
|
|
166
|
-
{
|
|
167
|
-
provider: 'openai',
|
|
168
|
-
model: 'gpt-4-vision-preview',
|
|
169
|
-
prompt: '请用中文详细描述这张图片。',
|
|
170
|
-
client: openaiClient // ✅ 核心系统注入
|
|
171
|
-
}
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
console.log(result[0].docs[0].pageContent);
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
---
|
|
178
|
-
|
|
179
|
-
这样插件本身不依赖任何 `openai` 包装逻辑,**只声明权限 + 要求 provider/model**,核心系统就能注入合适的 client。
|
|
180
|
-
|
|
181
|
-
要不要我帮你写一个 **抽象的权限声明接口 (例如 ILLMPermissionRequest)**,这样 OCR/VLM/Embedding 插件都可以统一声明依赖?
|