@yushaw/sanqian-ai-sdk 0.1.1 → 0.1.2

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
@@ -120,6 +120,20 @@ interface RuntimeConnectionSnapshot {
120
120
  errorCode?: RuntimeConnectionErrorCode;
121
121
  lastChangedAt: number;
122
122
  }
123
+ /**
124
+ * Per-request tool-choice constraint (mirrors Vercel AI SDK / OpenAI semantics).
125
+ * - 'auto' (default): the model decides whether to call tools.
126
+ * - 'none': the model must not call tools.
127
+ * - 'required': the model MUST call at least one tool this turn.
128
+ * - { type: 'tool', toolName }: the model MUST call the named tool.
129
+ * Providers that cannot honor a constraining value MUST throw instead of silently
130
+ * degrading to 'auto' — callers rely on this for command-style requests where a
131
+ * hallucinated "done" without a tool call is a correctness bug.
132
+ */
133
+ type RuntimeToolChoice = 'auto' | 'none' | 'required' | {
134
+ type: 'tool';
135
+ toolName: string;
136
+ };
123
137
  interface RuntimeChatRequest {
124
138
  agentId: string;
125
139
  messages: RuntimeMessage[];
@@ -127,6 +141,7 @@ interface RuntimeChatRequest {
127
141
  providerInstanceId?: string;
128
142
  operationId?: string;
129
143
  tools?: RuntimeToolDefinition[];
144
+ toolChoice?: RuntimeToolChoice;
130
145
  contexts?: RuntimeContext[];
131
146
  resources?: RuntimeResourceRef[];
132
147
  sessionResources?: RuntimeResource[];
@@ -145,6 +160,7 @@ interface RuntimeChatStreamRequest {
145
160
  providerInstanceId?: string;
146
161
  operationId?: string;
147
162
  tools?: RuntimeToolDefinition[];
163
+ toolChoice?: RuntimeToolChoice;
148
164
  contexts?: RuntimeContext[];
149
165
  resources?: RuntimeResourceRef[];
150
166
  sessionResources?: RuntimeResource[];
@@ -1390,4 +1406,4 @@ declare class VercelEmbeddingProvider implements EmbeddingProvider {
1390
1406
  private redact;
1391
1407
  }
1392
1408
 
1393
- export { type ActiveRuntimeWork, type ActiveRuntimeWorkKind, type ActiveStream, type ActiveWorkTracker, type AgentExecutionMode, type AgentIdResolver, type AiFeatureRuntimeState, type AuthMode, type BillingMode, type BridgeSessionResource, type ChatRuntimeBridge, type ChatRuntimeBridgeConfig, type ConversationDetail, type ConversationInfo, type ConversationPage, type ConversationPatch, type ConversationStore, type CreateConversationInput, EMPTY_CAPABILITIES, type EditorOutputContext, type EmbeddingModelChangeEvent, type EmbeddingProvider, type EmbeddingProviderConfig, type EmbeddingSession, type ExecutionTarget, type GetConversationInput, type HistoryLocation, type InsertOutputData, type ListConversationsInput, MockSanqianSdk, type MockScenario, type MockSdkConfig, type OutputOperation, type OutputOperationType, type OutputOperationsManager, type PendingOutputOps, type PendingPermission, type PermissionDecision, type PermissionGate, type PermissionPolicy, type ProviderChangedEvent, type ProviderInstanceConfig, type RerankInput, type RerankProvider, type RerankResult, type RerankResultItem, type ResourceListPage, type ResourceListRequest, type ResourceProviderInfo, type RuntimeAgentConfig, type RuntimeAgentId, type RuntimeAgentRegistry, type RuntimeChatRequest, type RuntimeChatResponse, type RuntimeChatStreamRequest, type RuntimeConnectionErrorCode, type RuntimeConnectionSnapshot, type RuntimeConnectionStatus, type RuntimeContext, type RuntimeConversationMessage, type RuntimeHitlResponse, type RuntimeInterrupt, type RuntimeMessage, type RuntimePermissionResponse, type RuntimeProfile, type RuntimeProvider, type RuntimeProviderCapabilities, type RuntimeProviderDescriptor, type RuntimeProviderKind, type RuntimeResource, type RuntimeResourceRef, type RuntimeSecretStore, type RuntimeSessionManager, type RuntimeSessionResourceEvent, type RuntimeStreamEvent, type RuntimeTaskPipeline, type RuntimeTaskPipelineInput, type RuntimeToolCall, type RuntimeToolDefinition, type RuntimeToolExecutionContext, type RuntimeToolExecutionInput, type RuntimeToolExecutionMetadata, type RuntimeToolExecutionResult, type RuntimeToolHandler, type RuntimeToolMetadata, type RuntimeToolRegistration, type RuntimeToolRegistry, type RuntimeUsage, type SanqianEmbeddingConfig, SanqianEmbeddingProvider, SanqianProvider, type SanqianProviderConfig, type SanqianRerankConfig, SanqianRerankProvider, type SanqianSdkPort, type SecretDescriptor, type SecretRef, type StoreSecretInput, type SwitchOptions, type SwitchResult, type ToolCategory, type VercelEmbeddingConfig, VercelEmbeddingProvider, VercelProvider, type VercelProviderConfig, convertSdkStreamEvent, convertToolsForVercel, createActiveWorkTracker, createCategoryPermissionPolicy, createChatRuntimeBridge, createDefaultPermissionPolicy, createDisabledState, createEmbeddingSession, createMemoryConversationStore, createMemorySecretStore, createOutputOperationsManager, createPermissionGate, createSanqianAgentIdResolver, createSessionManager, createTaskPipeline, createToolRegistry, redactToolError, resolveAiFeaturesFromRuntime, validateOutputContent };
1409
+ export { type ActiveRuntimeWork, type ActiveRuntimeWorkKind, type ActiveStream, type ActiveWorkTracker, type AgentExecutionMode, type AgentIdResolver, type AiFeatureRuntimeState, type AuthMode, type BillingMode, type BridgeSessionResource, type ChatRuntimeBridge, type ChatRuntimeBridgeConfig, type ConversationDetail, type ConversationInfo, type ConversationPage, type ConversationPatch, type ConversationStore, type CreateConversationInput, EMPTY_CAPABILITIES, type EditorOutputContext, type EmbeddingModelChangeEvent, type EmbeddingProvider, type EmbeddingProviderConfig, type EmbeddingSession, type ExecutionTarget, type GetConversationInput, type HistoryLocation, type InsertOutputData, type ListConversationsInput, MockSanqianSdk, type MockScenario, type MockSdkConfig, type OutputOperation, type OutputOperationType, type OutputOperationsManager, type PendingOutputOps, type PendingPermission, type PermissionDecision, type PermissionGate, type PermissionPolicy, type ProviderChangedEvent, type ProviderInstanceConfig, type RerankInput, type RerankProvider, type RerankResult, type RerankResultItem, type ResourceListPage, type ResourceListRequest, type ResourceProviderInfo, type RuntimeAgentConfig, type RuntimeAgentId, type RuntimeAgentRegistry, type RuntimeChatRequest, type RuntimeChatResponse, type RuntimeChatStreamRequest, type RuntimeConnectionErrorCode, type RuntimeConnectionSnapshot, type RuntimeConnectionStatus, type RuntimeContext, type RuntimeConversationMessage, type RuntimeHitlResponse, type RuntimeInterrupt, type RuntimeMessage, type RuntimePermissionResponse, type RuntimeProfile, type RuntimeProvider, type RuntimeProviderCapabilities, type RuntimeProviderDescriptor, type RuntimeProviderKind, type RuntimeResource, type RuntimeResourceRef, type RuntimeSecretStore, type RuntimeSessionManager, type RuntimeSessionResourceEvent, type RuntimeStreamEvent, type RuntimeTaskPipeline, type RuntimeTaskPipelineInput, type RuntimeToolCall, type RuntimeToolChoice, type RuntimeToolDefinition, type RuntimeToolExecutionContext, type RuntimeToolExecutionInput, type RuntimeToolExecutionMetadata, type RuntimeToolExecutionResult, type RuntimeToolHandler, type RuntimeToolMetadata, type RuntimeToolRegistration, type RuntimeToolRegistry, type RuntimeUsage, type SanqianEmbeddingConfig, SanqianEmbeddingProvider, SanqianProvider, type SanqianProviderConfig, type SanqianRerankConfig, SanqianRerankProvider, type SanqianSdkPort, type SecretDescriptor, type SecretRef, type StoreSecretInput, type SwitchOptions, type SwitchResult, type ToolCategory, type VercelEmbeddingConfig, VercelEmbeddingProvider, VercelProvider, type VercelProviderConfig, convertSdkStreamEvent, convertToolsForVercel, createActiveWorkTracker, createCategoryPermissionPolicy, createChatRuntimeBridge, createDefaultPermissionPolicy, createDisabledState, createEmbeddingSession, createMemoryConversationStore, createMemorySecretStore, createOutputOperationsManager, createPermissionGate, createSanqianAgentIdResolver, createSessionManager, createTaskPipeline, createToolRegistry, redactToolError, resolveAiFeaturesFromRuntime, validateOutputContent };
package/dist/index.d.ts CHANGED
@@ -120,6 +120,20 @@ interface RuntimeConnectionSnapshot {
120
120
  errorCode?: RuntimeConnectionErrorCode;
121
121
  lastChangedAt: number;
122
122
  }
123
+ /**
124
+ * Per-request tool-choice constraint (mirrors Vercel AI SDK / OpenAI semantics).
125
+ * - 'auto' (default): the model decides whether to call tools.
126
+ * - 'none': the model must not call tools.
127
+ * - 'required': the model MUST call at least one tool this turn.
128
+ * - { type: 'tool', toolName }: the model MUST call the named tool.
129
+ * Providers that cannot honor a constraining value MUST throw instead of silently
130
+ * degrading to 'auto' — callers rely on this for command-style requests where a
131
+ * hallucinated "done" without a tool call is a correctness bug.
132
+ */
133
+ type RuntimeToolChoice = 'auto' | 'none' | 'required' | {
134
+ type: 'tool';
135
+ toolName: string;
136
+ };
123
137
  interface RuntimeChatRequest {
124
138
  agentId: string;
125
139
  messages: RuntimeMessage[];
@@ -127,6 +141,7 @@ interface RuntimeChatRequest {
127
141
  providerInstanceId?: string;
128
142
  operationId?: string;
129
143
  tools?: RuntimeToolDefinition[];
144
+ toolChoice?: RuntimeToolChoice;
130
145
  contexts?: RuntimeContext[];
131
146
  resources?: RuntimeResourceRef[];
132
147
  sessionResources?: RuntimeResource[];
@@ -145,6 +160,7 @@ interface RuntimeChatStreamRequest {
145
160
  providerInstanceId?: string;
146
161
  operationId?: string;
147
162
  tools?: RuntimeToolDefinition[];
163
+ toolChoice?: RuntimeToolChoice;
148
164
  contexts?: RuntimeContext[];
149
165
  resources?: RuntimeResourceRef[];
150
166
  sessionResources?: RuntimeResource[];
@@ -1390,4 +1406,4 @@ declare class VercelEmbeddingProvider implements EmbeddingProvider {
1390
1406
  private redact;
1391
1407
  }
1392
1408
 
1393
- export { type ActiveRuntimeWork, type ActiveRuntimeWorkKind, type ActiveStream, type ActiveWorkTracker, type AgentExecutionMode, type AgentIdResolver, type AiFeatureRuntimeState, type AuthMode, type BillingMode, type BridgeSessionResource, type ChatRuntimeBridge, type ChatRuntimeBridgeConfig, type ConversationDetail, type ConversationInfo, type ConversationPage, type ConversationPatch, type ConversationStore, type CreateConversationInput, EMPTY_CAPABILITIES, type EditorOutputContext, type EmbeddingModelChangeEvent, type EmbeddingProvider, type EmbeddingProviderConfig, type EmbeddingSession, type ExecutionTarget, type GetConversationInput, type HistoryLocation, type InsertOutputData, type ListConversationsInput, MockSanqianSdk, type MockScenario, type MockSdkConfig, type OutputOperation, type OutputOperationType, type OutputOperationsManager, type PendingOutputOps, type PendingPermission, type PermissionDecision, type PermissionGate, type PermissionPolicy, type ProviderChangedEvent, type ProviderInstanceConfig, type RerankInput, type RerankProvider, type RerankResult, type RerankResultItem, type ResourceListPage, type ResourceListRequest, type ResourceProviderInfo, type RuntimeAgentConfig, type RuntimeAgentId, type RuntimeAgentRegistry, type RuntimeChatRequest, type RuntimeChatResponse, type RuntimeChatStreamRequest, type RuntimeConnectionErrorCode, type RuntimeConnectionSnapshot, type RuntimeConnectionStatus, type RuntimeContext, type RuntimeConversationMessage, type RuntimeHitlResponse, type RuntimeInterrupt, type RuntimeMessage, type RuntimePermissionResponse, type RuntimeProfile, type RuntimeProvider, type RuntimeProviderCapabilities, type RuntimeProviderDescriptor, type RuntimeProviderKind, type RuntimeResource, type RuntimeResourceRef, type RuntimeSecretStore, type RuntimeSessionManager, type RuntimeSessionResourceEvent, type RuntimeStreamEvent, type RuntimeTaskPipeline, type RuntimeTaskPipelineInput, type RuntimeToolCall, type RuntimeToolDefinition, type RuntimeToolExecutionContext, type RuntimeToolExecutionInput, type RuntimeToolExecutionMetadata, type RuntimeToolExecutionResult, type RuntimeToolHandler, type RuntimeToolMetadata, type RuntimeToolRegistration, type RuntimeToolRegistry, type RuntimeUsage, type SanqianEmbeddingConfig, SanqianEmbeddingProvider, SanqianProvider, type SanqianProviderConfig, type SanqianRerankConfig, SanqianRerankProvider, type SanqianSdkPort, type SecretDescriptor, type SecretRef, type StoreSecretInput, type SwitchOptions, type SwitchResult, type ToolCategory, type VercelEmbeddingConfig, VercelEmbeddingProvider, VercelProvider, type VercelProviderConfig, convertSdkStreamEvent, convertToolsForVercel, createActiveWorkTracker, createCategoryPermissionPolicy, createChatRuntimeBridge, createDefaultPermissionPolicy, createDisabledState, createEmbeddingSession, createMemoryConversationStore, createMemorySecretStore, createOutputOperationsManager, createPermissionGate, createSanqianAgentIdResolver, createSessionManager, createTaskPipeline, createToolRegistry, redactToolError, resolveAiFeaturesFromRuntime, validateOutputContent };
1409
+ export { type ActiveRuntimeWork, type ActiveRuntimeWorkKind, type ActiveStream, type ActiveWorkTracker, type AgentExecutionMode, type AgentIdResolver, type AiFeatureRuntimeState, type AuthMode, type BillingMode, type BridgeSessionResource, type ChatRuntimeBridge, type ChatRuntimeBridgeConfig, type ConversationDetail, type ConversationInfo, type ConversationPage, type ConversationPatch, type ConversationStore, type CreateConversationInput, EMPTY_CAPABILITIES, type EditorOutputContext, type EmbeddingModelChangeEvent, type EmbeddingProvider, type EmbeddingProviderConfig, type EmbeddingSession, type ExecutionTarget, type GetConversationInput, type HistoryLocation, type InsertOutputData, type ListConversationsInput, MockSanqianSdk, type MockScenario, type MockSdkConfig, type OutputOperation, type OutputOperationType, type OutputOperationsManager, type PendingOutputOps, type PendingPermission, type PermissionDecision, type PermissionGate, type PermissionPolicy, type ProviderChangedEvent, type ProviderInstanceConfig, type RerankInput, type RerankProvider, type RerankResult, type RerankResultItem, type ResourceListPage, type ResourceListRequest, type ResourceProviderInfo, type RuntimeAgentConfig, type RuntimeAgentId, type RuntimeAgentRegistry, type RuntimeChatRequest, type RuntimeChatResponse, type RuntimeChatStreamRequest, type RuntimeConnectionErrorCode, type RuntimeConnectionSnapshot, type RuntimeConnectionStatus, type RuntimeContext, type RuntimeConversationMessage, type RuntimeHitlResponse, type RuntimeInterrupt, type RuntimeMessage, type RuntimePermissionResponse, type RuntimeProfile, type RuntimeProvider, type RuntimeProviderCapabilities, type RuntimeProviderDescriptor, type RuntimeProviderKind, type RuntimeResource, type RuntimeResourceRef, type RuntimeSecretStore, type RuntimeSessionManager, type RuntimeSessionResourceEvent, type RuntimeStreamEvent, type RuntimeTaskPipeline, type RuntimeTaskPipelineInput, type RuntimeToolCall, type RuntimeToolChoice, type RuntimeToolDefinition, type RuntimeToolExecutionContext, type RuntimeToolExecutionInput, type RuntimeToolExecutionMetadata, type RuntimeToolExecutionResult, type RuntimeToolHandler, type RuntimeToolMetadata, type RuntimeToolRegistration, type RuntimeToolRegistry, type RuntimeUsage, type SanqianEmbeddingConfig, SanqianEmbeddingProvider, SanqianProvider, type SanqianProviderConfig, type SanqianRerankConfig, SanqianRerankProvider, type SanqianSdkPort, type SecretDescriptor, type SecretRef, type StoreSecretInput, type SwitchOptions, type SwitchResult, type ToolCategory, type VercelEmbeddingConfig, VercelEmbeddingProvider, VercelProvider, type VercelProviderConfig, convertSdkStreamEvent, convertToolsForVercel, createActiveWorkTracker, createCategoryPermissionPolicy, createChatRuntimeBridge, createDefaultPermissionPolicy, createDisabledState, createEmbeddingSession, createMemoryConversationStore, createMemorySecretStore, createOutputOperationsManager, createPermissionGate, createSanqianAgentIdResolver, createSessionManager, createTaskPipeline, createToolRegistry, redactToolError, resolveAiFeaturesFromRuntime, validateOutputContent };
package/dist/index.js CHANGED
@@ -958,6 +958,11 @@ function createSanqianAgentIdResolver(appName) {
958
958
  }
959
959
 
960
960
  // src/providers/sanqian/provider.ts
961
+ var SANQIAN_TOOL_CHOICE_UNSUPPORTED_ERROR = "SanqianProvider does not support constraining toolChoice yet: the runtime wire protocol has no tool_choice field. Fail-fast by contract - do not silently degrade to auto.";
962
+ function assertSupportedToolChoice(toolChoice) {
963
+ if (toolChoice === void 0 || toolChoice === "auto") return;
964
+ throw new Error(SANQIAN_TOOL_CHOICE_UNSUPPORTED_ERROR);
965
+ }
961
966
  var SANQIAN_CAPABILITIES = {
962
967
  streamingText: true,
963
968
  reasoning: true,
@@ -1073,6 +1078,7 @@ var SanqianProvider = class {
1073
1078
  // --- Chat ---
1074
1079
  async chat(input) {
1075
1080
  this.ensureNotDisposed();
1081
+ assertSupportedToolChoice(input.toolChoice);
1076
1082
  const agentId = await this.resolveAgentId(input.agentId);
1077
1083
  const messages = input.messages.map((m) => ({ role: m.role, content: m.content }));
1078
1084
  const response = await this.sdk.chat(agentId, messages, {
@@ -1090,6 +1096,7 @@ var SanqianProvider = class {
1090
1096
  }
1091
1097
  async *chatStream(input) {
1092
1098
  this.ensureNotDisposed();
1099
+ assertSupportedToolChoice(input.toolChoice);
1093
1100
  const agentId = await this.resolveAgentId(input.agentId);
1094
1101
  const messages = input.messages.map((m) => ({ role: m.role, content: m.content }));
1095
1102
  const stream = this.sdk.chatStream(agentId, messages, {
@@ -1719,6 +1726,16 @@ function convertToolsForVercel(tools, registry, options) {
1719
1726
  }
1720
1727
 
1721
1728
  // src/providers/vercel/provider.ts
1729
+ function isConstrainingToolChoice(toolChoice) {
1730
+ return toolChoice === "required" || typeof toolChoice === "object" && toolChoice !== null;
1731
+ }
1732
+ function resolveToolChoiceOption(toolChoice, hasTools) {
1733
+ if (toolChoice === void 0) return {};
1734
+ if (!hasTools && isConstrainingToolChoice(toolChoice)) {
1735
+ throw new Error("toolChoice requires at least one resolved tool for this agent");
1736
+ }
1737
+ return { toolChoice };
1738
+ }
1722
1739
  var VERCEL_CAPABILITIES = {
1723
1740
  streamingText: true,
1724
1741
  reasoning: true,
@@ -1810,6 +1827,7 @@ var VercelProvider = class {
1810
1827
  system,
1811
1828
  messages: userMessages,
1812
1829
  tools,
1830
+ ...resolveToolChoiceOption(input.toolChoice, !!tools),
1813
1831
  stopWhen: (0, import_ai.stepCountIs)(maxSteps),
1814
1832
  abortSignal: input.signal
1815
1833
  });
@@ -1846,6 +1864,7 @@ var VercelProvider = class {
1846
1864
  system,
1847
1865
  messages: userMessages,
1848
1866
  tools,
1867
+ ...resolveToolChoiceOption(input.toolChoice, !!tools),
1849
1868
  stopWhen: (0, import_ai.stepCountIs)(maxSteps),
1850
1869
  abortSignal: input.signal
1851
1870
  });