@bobannomi/client 0.3.0 → 0.3.1

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 CHANGED
@@ -74,7 +74,7 @@ await modelProviders.defaults.updateModel({
74
74
 
75
75
  全局推理强度使用 `modelProviders.defaults.updateEffort({ effort, expectedRevision })`,可选值来自当前模型的 `reasoningEfforts`。断开或删除默认供应商时传入 `replacement: { provider, model }`,或显式传入 `disableDefault: true`。连接测试查询模型列表并记录验证结果。没有独立验证接口的订阅会返回 `unsupported`。 [可运行示例](../../apps/client-docs/examples/README.md)
76
76
 
77
- ## 宿主配置模型目录
77
+ ## 自建后台的共享目录(可选)
78
78
 
79
79
  自行启动后台的 Node 宿主,可将 `modelCatalog: { url }` 或 `modelCatalog: { load }` 传给 `startBobanNomiDaemon()`。用启动结果的 `listen.url` 作为 SDK 的 `baseUrl`,并传入该后台的 token。连接成功后,`client.models.list()` 返回已连接供应商的模型。 [bobannomi 网关动态目录示例](../server/src/application/README.md#bobannomi-网关示例)
80
80
 
@@ -108,7 +108,7 @@ await modelProviders.defaults.updateModel({
108
108
 
109
109
  会话快照、reducer(合并快照和事件的函数)、选择函数及同步控制器从根入口导出,供不同界面共用一套恢复流程。请求 metadata 与工具输入/输出保留扩展数据。
110
110
 
111
- 工作台模型设置由 app-host 提供管理接口。公开 Client SDK 可读取已连接的模型,并通过会话配置选项读取新会话默认值。供应商连接与凭据、目录刷新、全局默认模型和推理强度写入,以及已保存连接的验证需要宿主授权。
111
+ 内置工作台经 AppHost 授权管理模型供应商。独立应用用目标 daemon 的管理员连接调用 `client.modelProviders`。页面用 `client.models.list()` 读取模型目录,用会话配置选项核对当前后台支持执行的模型。
112
112
 
113
113
  `session.management` 先按动作读取版本,再用原 `requestId` 和 `expectedRevision` 或 `expectedTreeRevision` 改名、置顶、归档或删除。`getMutation` 按原请求 ID 查询结果。`session.goal.getRequest` 和 `attachments.getUpload` 也通过原请求定位回执。`session.getContextUsage()` 读取会话当前上下文的用量,`session.getUsage()` 读取历史统计。 [会话管理与配置示例](../../apps/client-docs/examples/README.md)
114
114
 
package/dist/index.d.ts CHANGED
@@ -179,6 +179,8 @@ interface CreateClientSessionInput$1 {
179
179
  requestId?: string;
180
180
  cwd: string;
181
181
  projectId?: string;
182
+ workspaceId?: never;
183
+ outsideProject?: never;
182
184
  title?: string;
183
185
  storage?: "sqlite" | "memory";
184
186
  configuration?: SessionConfigurationInput;
@@ -196,7 +198,18 @@ type CreateSessionByProjectInput = Omit<CreateClientSessionInput$1, "cwd" | "pro
196
198
  projectId: string;
197
199
  cwd?: never;
198
200
  };
199
- type SessionCreationInput = CreateClientSessionInput$1 | CreateSessionByProjectInput;
201
+ /** Use a desktop workspace selection or let the daemon allocate a new directory. */
202
+ type CreateSessionWithDirectoryInput = Omit<CreateClientSessionInput$1, "cwd" | "projectId" | "workspaceId" | "outsideProject"> & {
203
+ cwd?: never;
204
+ projectId?: never;
205
+ } & ({
206
+ workspaceId: string;
207
+ outsideProject?: never;
208
+ } | {
209
+ outsideProject: true;
210
+ workspaceId?: never;
211
+ });
212
+ type SessionCreationInput = CreateClientSessionInput$1 | CreateSessionByProjectInput | CreateSessionWithDirectoryInput;
200
213
  type DispatchedSessionCreationRequest = SessionCreationInput & {
201
214
  id: string;
202
215
  requestId: string;
@@ -2633,6 +2646,17 @@ interface PluginGitInstallInput extends PluginGitPreviewInput {
2633
2646
 
2634
2647
  /** Public Agent lifecycle request, response and synchronization types. */
2635
2648
 
2649
+ /** Gateway credentials supplied by the application for its Agent sessions. */
2650
+ interface ClientModelConnection {
2651
+ baseUrl: string;
2652
+ apiKey: string;
2653
+ apiFormat: "openai";
2654
+ }
2655
+ type ClientModelProvider = ModelProviderInfo & {
2656
+ connection?: ClientModelConnection | ((options: {
2657
+ signal?: AbortSignal;
2658
+ }) => Promise<ClientModelConnection>);
2659
+ };
2636
2660
  /** `BobanNomiClient` 构造参数。 */
2637
2661
  interface BobanNomiClientOptions {
2638
2662
  /** daemon HTTP 根地址,例如 `http://127.0.0.1:8787`。 */
@@ -2641,10 +2665,10 @@ interface BobanNomiClientOptions {
2641
2665
  token?: string;
2642
2666
  /** 可注入的 fetch,便于测试或自定义传输。 */
2643
2667
  fetch?: typeof fetch;
2644
- /** Optional display catalog. It supplies models.list() without configuring the daemon. */
2645
- providers?: readonly ModelProviderInfo[] | ((options: {
2668
+ /** App-provided catalog and optional connections. Reading the catalog is side-effect-free. */
2669
+ providers?: readonly ClientModelProvider[] | ((options: {
2646
2670
  signal?: AbortSignal;
2647
- }) => Promise<readonly ModelProviderInfo[]>);
2671
+ }) => Promise<readonly ClientModelProvider[]>);
2648
2672
  }
2649
2673
  interface BobanNomiServerHealth {
2650
2674
  ok: true;
@@ -2861,6 +2885,8 @@ declare class ProtocolClient {
2861
2885
  capabilities(options?: CapabilitiesOptions): Promise<ServerCapabilities>;
2862
2886
  }
2863
2887
 
2888
+ type PrepareModelConnection = (sessionId: string, selection: SessionConfigurationInput["model"], signal?: AbortSignal) => Promise<string | undefined>;
2889
+
2864
2890
  declare class EventResource {
2865
2891
  private readonly transport;
2866
2892
  private readonly sse;
@@ -3076,7 +3102,8 @@ interface SessionHandle {
3076
3102
  /** Find, prepare, and create sessions on one daemon connection. */
3077
3103
  declare class SessionResource {
3078
3104
  #private;
3079
- constructor(transport: HttpTransport, events?: EventResource);
3105
+ private readonly prepareModel?;
3106
+ constructor(transport: HttpTransport, events?: EventResource, prepareModel?: PrepareModelConnection | undefined);
3080
3107
  /** Bind a session ID locally. Operations use this resource's daemon connection when called. */
3081
3108
  byId(sessionId: string): SessionHandle;
3082
3109
  /** `GET /sessions/search` - search saved conversation text without opening it. */
@@ -4134,4 +4161,4 @@ declare function readSessionRuntimeConfig(session: SessionRecord, defaults?: Par
4134
4161
  declare function patchSessionRuntimeMetadata(metadata: Record<string, unknown>, patch: SessionRuntimeConfigPatch): Record<string, unknown>;
4135
4162
 
4136
4163
  export { AttachmentResource, BobanNomiApiError, BobanNomiClient, CURRENT_PROTOCOL_VERSION, ChannelResource, CommandResource, ContextResource, DiagnosticResource, EventResource, GitResource, HookResource, HttpTransport, IncompatibleProtocolError, MaintenanceResource, McpResource, McpServersResource, MemoryResource, PermissionResource, PluginMarketplaceResource, PluginResource, ProjectResource, ProtocolClient, ProtocolValidationError, ScheduleResource, SessionResource, SessionSyncController, SettingsResource, SseTransport, TerminalResource, UnsupportedSessionEventSchemaVersionError, WorktreeResource, applyEvent, applyEvents, attachmentRangeHeader, checkProtocolCompatibility, createClientState, createSessionRequestId, getVisibleSessionMessages, hydrateState, isSupersededModelPart, isWorkMode, normalizeApprovalMode, normalizeDaemonBaseUrl, parseCreateSessionGoalInput, parseGoalActionInput, parseMcpCallResultData, parseUpdateSessionGoalInput, patchSessionRuntimeMetadata, readPluginUiInstance, readRuntimeMetadata, readSessionModelRetryState, readSessionModelUsage, readSessionRuntimeConfig, readWorkspaceChangesMetadata, replaceSessionState, responseArray, responseField, selectFirstPendingPermission, selectSessionInputs, selectSessionMessagesWithParts, selectSessionModelRetry, selectSessionModelUsage, selectSessionOrderedMessages, selectSessionParts, selectSessionPermissions, selectSessionRuns, selectSessionTasks, streamServerSentEvents, supportsFeature, syncEvents };
4137
- export type { AdmitClientPromptInput, AdmitPromptAttachmentInput, AgentEnvironmentCapabilities, AgentPersonaInfo, ApprovalMode, ApprovalReviewRecord, AttachmentAssetRecord, AttachmentStorageGcResult, AttachmentStorageIssue, AttachmentStorageRepairResult, AttachmentStorageReport, AuthStatus, BobanNomiClientOptions, BobanNomiClientState, BobanNomiServerHealth, CancelQueuedClientPromptInput, CancelQueuedPromptResponse, CancelResponseMode, ChannelConnectorRuntimeStatus, ChannelDeliveryRecord, ChannelDeliveryStatus, ChannelDenialNotice, ChannelDomain, ChannelQuery, ChannelRuntimeControlInput, ChannelRuntimeState, ChannelRuntimeStatus, ChannelStatusSnapshot, CleanupCandidate, CleanupPreview, CleanupResult, ClearMemoryInput, ClientProtocolSupport, CommandCatalogEntry, CommandKind, CommandSelection, CommandSource, ConfigureClientSessionInput, ContextBucketId, ContextUsageBucket, ContextUsageSnapshot, ContextUsageTip, ContextUsageTipCode, CreateBackgroundShellInput, CreateBackgroundShellResult, CreateClientSessionInput, CreateScheduledTaskInput, CreateSessionByProjectInput, CreateSessionGoalInput, CustomModelProviderInput, DaemonRestartPreview, DiagnosticExecutionQuery, DispatchedSessionCreation, DispatchedSessionCreationRequest, DownloadAttachmentOptions, DraftComposerOptions, DraftComposerTarget, DurableChannelMessageInput, DurableChannelMessageResult, EditLatestClientPromptInput, EventSyncOptions, ExecutionInstructions, ExpectedModelConnection, ExternalConversationRecord, FactReplacementResult, FeishuAllowInput, FeishuChannelSnapshot, FeishuComposedSnapshot, FeishuConnectInput, FeishuPatchInput, FeishuRegistrationSnapshot, FeishuRegistrationStartInput, FeishuRegistrationState, ForkClientSessionInput, GlobalSettingsPatch, GoalActionInput, GoalExternalWait, GoalStopReason, HookInfo, HostDiagnosticSnapshots, HttpRequestOptions, HttpTransportOptions, InputDelivery, InterruptSessionResponse, JobCancelReceipt, JobCapabilities, JobInputReceipt, JobKind, JobListResult, JobReadResult, JobSnapshot, JobStatus, JobTarget, JobWaitResult, JsonValue, ListClientMessagePartsOptions, ListCommandsOptions, ListEventsOptions, ListMessagePartsOptions, ListMessagesOptions, ListPermissionsOptions, ListProjectsOptions, ListSessionJobsOptions, ListSessionsOptions, MaintenanceBackupManifest, MaintenanceBackupResult, MarketplaceAddSourceRequest, MarketplaceCancelRequest, MarketplaceCancelResponse, MarketplaceCatalog, MarketplaceCatalogRequest, MarketplaceEntry, MarketplaceInstallInput, MarketplaceInstallRequest, MarketplaceOperation, MarketplacePreview, MarketplacePreviewRequest, MarketplaceProvenance, MarketplaceSelection, MarketplaceSource, MarketplaceSourceEnabledRequest, MarketplaceSourceView, MarketplaceSourcesResponse, McpConfigOperationResult, McpManagedServerConfig, McpManagedServerSummary, McpOAuthLoginInput, McpOAuthLoginResponse, McpOAuthStatusSnapshot, McpRuntimeStatus, McpRuntimeSyncResult, McpServerRuntimeRef, McpServerStatus, MemoryEntryRecord, MemoryListResponse, MemoryRevision, ModelInfo, ModelProviderConnection, ModelProviderInfo, ModelProviderRequest, OAuthOperationEvent, OAuthOperationView, OutputStyleInfo, PermissionRequestRecord, PermissionStatus, PluginArchiveError, PluginArchiveInstallInput, PluginArchivePreview, PluginArchivePreviewInput, PluginGitInstallInput, PluginGitPreview, PluginGitPreviewInput, PluginInfo, PluginListResult, PluginLocalInstallInput, PluginLocalPreview, PluginLocalPreviewInput, PluginRuntimeStatus, PluginUiInstanceRecord, PluginUiInventory, ProjectFactRecord, ProjectRecord, PromoteQueuedClientPromptInput, PromoteQueuedPromptResponse, PromptResponse, ProtocolCompatibility, ProviderConnectionTestResult, ProviderDefaultsRequest, ProviderDefaultsSnapshot, ProviderInfo, QueuedPromptCancelReceipt, RawRequestOptions, RecordChannelDeliveryInput, ReloadPluginsResponse, RememberSessionResponse, ReplyPermissionInput, ResolvedSessionConfiguration, ResumeInterruptedRunInput, ResumeInterruptedRunResponse, RewindSessionResponse, RunResult, ScheduledRunRecord, ScheduledTaskRecord, ScheduledTaskStatusSummary, SearchSessionsOptions, ServerCapabilities, SessionActivityPage, SessionAttachmentMessagePartRecord, SessionBucket, SessionComposerContext, SessionConfigurationInput, SessionConfigurationOptions, SessionConfigurationResultInput, SessionConfigurationSnapshot, SessionControlOriginal, SessionControlReceipt, SessionControls, SessionCreationInput, SessionCreationReceipt, SessionDirectoryEntry, SessionDirectoryPage, SessionDirectoryResult, SessionEventRecord, SessionExecutionRecord, SessionExportResponse, SessionFileErrorCode, SessionFileFindInput, SessionFileFindOptions, SessionFileInfo, SessionFileListInput, SessionFileListOptions, SessionFileReadInput, SessionFileReadOptions, SessionFileRequestOptions, SessionFileSearchInput, SessionFileSearchMatch, SessionFileSearchOptions, SessionFileStatInput, SessionFindFilesResult, SessionGoal, SessionGoalRequestReceipt, SessionHandle, SessionInputAttachmentRecord, SessionInputRecord, SessionManagementAction, SessionMessagePartRecord, SessionMessageRecord, SessionMessageWithParts, SessionModelRetryState, SessionModelUsageSummary, SessionMutationPublicReceipt, SessionRecord, SessionResourceRevision, SessionRunAttemptRecord, SessionRunRecord, SessionRuntimeConfig, SessionRuntimeConfigPatch, SessionSearchFilesResult, SessionSearchResult, AgentSessionStateSnapshot as SessionStateSnapshot, SessionSyncControllerOptions, SessionTextFileResult, SessionTransformationMessagePartRecord, SessionUsageResponse, SessionUserInputItem, SkillInfo, SkillMarketplaceEntry, SkillMarketplaceInstallInput, SkillProject, SkillSnapshot, SkillSource, StartDreamResponse, StorageCategory, StorageReport, StorageRetentionPolicy, SyncConnectionStatus, SyncEventUpdate, SyncEventsClient, TaskWorktreeRecord, TerminalCreateRequest, TerminalEvent, TerminalReadRequest, TerminalReadResult, TerminalResizeRequest, TerminalRuntime, TerminalSessionInfo, TerminalSessionStatus, TerminalSignal, TerminalSource, TerminalWriteRequest, UpdateMemoryEntryInput, UpdateScheduledTaskInput, UpdateSessionGoalInput, UploadAttachmentInput, UsageFilter, UsagePrice, UsageReport, UsageRequest, UsageSettings, WorkMode, WorkspaceChangeFile, WorkspaceChangesMetadata };
4164
+ export type { AdmitClientPromptInput, AdmitPromptAttachmentInput, AgentEnvironmentCapabilities, AgentPersonaInfo, ApprovalMode, ApprovalReviewRecord, AttachmentAssetRecord, AttachmentStorageGcResult, AttachmentStorageIssue, AttachmentStorageRepairResult, AttachmentStorageReport, AuthStatus, BobanNomiClientOptions, BobanNomiClientState, BobanNomiServerHealth, CancelQueuedClientPromptInput, CancelQueuedPromptResponse, CancelResponseMode, ChannelConnectorRuntimeStatus, ChannelDeliveryRecord, ChannelDeliveryStatus, ChannelDenialNotice, ChannelDomain, ChannelQuery, ChannelRuntimeControlInput, ChannelRuntimeState, ChannelRuntimeStatus, ChannelStatusSnapshot, CleanupCandidate, CleanupPreview, CleanupResult, ClearMemoryInput, ClientModelConnection, ClientModelProvider, ClientProtocolSupport, CommandCatalogEntry, CommandKind, CommandSelection, CommandSource, ConfigureClientSessionInput, ContextBucketId, ContextUsageBucket, ContextUsageSnapshot, ContextUsageTip, ContextUsageTipCode, CreateBackgroundShellInput, CreateBackgroundShellResult, CreateClientSessionInput, CreateScheduledTaskInput, CreateSessionByProjectInput, CreateSessionGoalInput, CreateSessionWithDirectoryInput, CustomModelProviderInput, DaemonRestartPreview, DiagnosticExecutionQuery, DispatchedSessionCreation, DispatchedSessionCreationRequest, DownloadAttachmentOptions, DraftComposerOptions, DraftComposerTarget, DurableChannelMessageInput, DurableChannelMessageResult, EditLatestClientPromptInput, EventSyncOptions, ExecutionInstructions, ExpectedModelConnection, ExternalConversationRecord, FactReplacementResult, FeishuAllowInput, FeishuChannelSnapshot, FeishuComposedSnapshot, FeishuConnectInput, FeishuPatchInput, FeishuRegistrationSnapshot, FeishuRegistrationStartInput, FeishuRegistrationState, ForkClientSessionInput, GlobalSettingsPatch, GoalActionInput, GoalExternalWait, GoalStopReason, HookInfo, HostDiagnosticSnapshots, HttpRequestOptions, HttpTransportOptions, InputDelivery, InterruptSessionResponse, JobCancelReceipt, JobCapabilities, JobInputReceipt, JobKind, JobListResult, JobReadResult, JobSnapshot, JobStatus, JobTarget, JobWaitResult, JsonValue, ListClientMessagePartsOptions, ListCommandsOptions, ListEventsOptions, ListMessagePartsOptions, ListMessagesOptions, ListPermissionsOptions, ListProjectsOptions, ListSessionJobsOptions, ListSessionsOptions, MaintenanceBackupManifest, MaintenanceBackupResult, MarketplaceAddSourceRequest, MarketplaceCancelRequest, MarketplaceCancelResponse, MarketplaceCatalog, MarketplaceCatalogRequest, MarketplaceEntry, MarketplaceInstallInput, MarketplaceInstallRequest, MarketplaceOperation, MarketplacePreview, MarketplacePreviewRequest, MarketplaceProvenance, MarketplaceSelection, MarketplaceSource, MarketplaceSourceEnabledRequest, MarketplaceSourceView, MarketplaceSourcesResponse, McpConfigOperationResult, McpManagedServerConfig, McpManagedServerSummary, McpOAuthLoginInput, McpOAuthLoginResponse, McpOAuthStatusSnapshot, McpRuntimeStatus, McpRuntimeSyncResult, McpServerRuntimeRef, McpServerStatus, MemoryEntryRecord, MemoryListResponse, MemoryRevision, ModelInfo, ModelProviderConnection, ModelProviderInfo, ModelProviderRequest, OAuthOperationEvent, OAuthOperationView, OutputStyleInfo, PermissionRequestRecord, PermissionStatus, PluginArchiveError, PluginArchiveInstallInput, PluginArchivePreview, PluginArchivePreviewInput, PluginGitInstallInput, PluginGitPreview, PluginGitPreviewInput, PluginInfo, PluginListResult, PluginLocalInstallInput, PluginLocalPreview, PluginLocalPreviewInput, PluginRuntimeStatus, PluginUiInstanceRecord, PluginUiInventory, ProjectFactRecord, ProjectRecord, PromoteQueuedClientPromptInput, PromoteQueuedPromptResponse, PromptResponse, ProtocolCompatibility, ProviderConnectionTestResult, ProviderDefaultsRequest, ProviderDefaultsSnapshot, ProviderInfo, QueuedPromptCancelReceipt, RawRequestOptions, RecordChannelDeliveryInput, ReloadPluginsResponse, RememberSessionResponse, ReplyPermissionInput, ResolvedSessionConfiguration, ResumeInterruptedRunInput, ResumeInterruptedRunResponse, RewindSessionResponse, RunResult, ScheduledRunRecord, ScheduledTaskRecord, ScheduledTaskStatusSummary, SearchSessionsOptions, ServerCapabilities, SessionActivityPage, SessionAttachmentMessagePartRecord, SessionBucket, SessionComposerContext, SessionConfigurationInput, SessionConfigurationOptions, SessionConfigurationResultInput, SessionConfigurationSnapshot, SessionControlOriginal, SessionControlReceipt, SessionControls, SessionCreationInput, SessionCreationReceipt, SessionDirectoryEntry, SessionDirectoryPage, SessionDirectoryResult, SessionEventRecord, SessionExecutionRecord, SessionExportResponse, SessionFileErrorCode, SessionFileFindInput, SessionFileFindOptions, SessionFileInfo, SessionFileListInput, SessionFileListOptions, SessionFileReadInput, SessionFileReadOptions, SessionFileRequestOptions, SessionFileSearchInput, SessionFileSearchMatch, SessionFileSearchOptions, SessionFileStatInput, SessionFindFilesResult, SessionGoal, SessionGoalRequestReceipt, SessionHandle, SessionInputAttachmentRecord, SessionInputRecord, SessionManagementAction, SessionMessagePartRecord, SessionMessageRecord, SessionMessageWithParts, SessionModelRetryState, SessionModelUsageSummary, SessionMutationPublicReceipt, SessionRecord, SessionResourceRevision, SessionRunAttemptRecord, SessionRunRecord, SessionRuntimeConfig, SessionRuntimeConfigPatch, SessionSearchFilesResult, SessionSearchResult, AgentSessionStateSnapshot as SessionStateSnapshot, SessionSyncControllerOptions, SessionTextFileResult, SessionTransformationMessagePartRecord, SessionUsageResponse, SessionUserInputItem, SkillInfo, SkillMarketplaceEntry, SkillMarketplaceInstallInput, SkillProject, SkillSnapshot, SkillSource, StartDreamResponse, StorageCategory, StorageReport, StorageRetentionPolicy, SyncConnectionStatus, SyncEventUpdate, SyncEventsClient, TaskWorktreeRecord, TerminalCreateRequest, TerminalEvent, TerminalReadRequest, TerminalReadResult, TerminalResizeRequest, TerminalRuntime, TerminalSessionInfo, TerminalSessionStatus, TerminalSignal, TerminalSource, TerminalWriteRequest, UpdateMemoryEntryInput, UpdateScheduledTaskInput, UpdateSessionGoalInput, UploadAttachmentInput, UsageFilter, UsagePrice, UsageReport, UsageRequest, UsageSettings, WorkMode, WorkspaceChangeFile, WorkspaceChangesMetadata };
package/dist/index.js CHANGED
@@ -909,16 +909,25 @@ function validateSessionId(id2) {
909
909
  }
910
910
  function parseCreateSessionRequest(value) {
911
911
  const body = record3(value);
912
- fields2(body, ["id", "requestId", "cwd", "projectId", "title", "storage", "configuration", "optionsRevision", "metadata"]);
912
+ fields2(body, ["id", "requestId", "cwd", "projectId", "workspaceId", "outsideProject", "title", "storage", "configuration", "optionsRevision", "metadata"]);
913
913
  const cwd = optionalString2(body, "cwd");
914
+ const workspaceId = optionalString2(body, "workspaceId");
915
+ const outsideProject = optionalBoolean2(body, "outsideProject");
914
916
  const id2 = validateSessionId(requiredString2(body, "id"));
915
917
  const requestId = requiredString2(body, "requestId");
916
918
  if (cwd !== void 0 && !cwd.trim()) throw new ProtocolValidationError("cwd cannot be empty", "cwd");
917
919
  if (!requestId.trim()) throw new ProtocolValidationError("requestId cannot be empty", "requestId");
918
- const target = cwd === void 0 ? { projectId: requiredString2(body, "projectId") } : { cwd };
919
- if (cwd === void 0 && !target.projectId?.trim()) throw new ProtocolValidationError("projectId cannot be empty", "projectId");
920
+ if (workspaceId !== void 0 && !workspaceId.trim()) throw new ProtocolValidationError("workspaceId cannot be empty", "workspaceId");
921
+ if (outsideProject === false || outsideProject === true && workspaceId !== void 0)
922
+ throw new ProtocolValidationError("outsideProject must be true and used without workspaceId", "outsideProject");
923
+ if ((outsideProject === true || workspaceId !== void 0) && (cwd !== void 0 || body.projectId !== void 0))
924
+ throw new ProtocolValidationError("Supply one session directory choice", outsideProject === true ? "outsideProject" : "workspaceId");
925
+ const projectId = optionalString2(body, "projectId");
926
+ if (cwd === void 0 && outsideProject === void 0 && workspaceId === void 0 && !projectId?.trim())
927
+ throw new ProtocolValidationError("projectId cannot be empty", "projectId");
928
+ const target = workspaceId !== void 0 ? { workspaceId } : outsideProject === true ? { outsideProject } : cwd !== void 0 ? { cwd, ...projectId === void 0 ? {} : { projectId } } : { projectId };
920
929
  const result = { id: id2, requestId, ...target };
921
- for (const key of ["projectId", "title", "optionsRevision"]) if (body[key] !== void 0) result[key] = optionalString2(body, key);
930
+ for (const key of ["title", "optionsRevision"]) if (body[key] !== void 0) result[key] = optionalString2(body, key);
922
931
  if (body.storage !== void 0) result.storage = optionalEnum2(body, "storage", ["sqlite", "memory"]);
923
932
  if (body.configuration !== void 0) result.configuration = parseSessionConfiguration2(body.configuration);
924
933
  if (body.metadata !== void 0) result.metadata = appMetadata(optionalRecord(body, "metadata"));
@@ -2986,18 +2995,25 @@ async function getDraftComposerOptions(transport, input, options = {}) {
2986
2995
  }
2987
2996
  return result;
2988
2997
  }
2989
- async function create(transport, input, options = {}) {
2998
+ async function create(transport, input, options = {}, prepareModel) {
2990
2999
  const body = parseCreateSessionRequest({
2991
3000
  ...input,
2992
3001
  id: input.id ?? createSessionRequestId(),
2993
3002
  requestId: input.requestId ?? createSessionRequestId()
2994
3003
  });
2995
- if (body.cwd === void 0) await requireDaemonFeature(transport, "projectSessionCreation", options.signal);
3004
+ if (body.workspaceId !== void 0 || body.outsideProject)
3005
+ await requireDaemonFeature(transport, "sessionDirectoryCreation", options.signal);
3006
+ else if (body.cwd === void 0) await requireDaemonFeature(transport, "projectSessionCreation", options.signal);
3007
+ const modelConnection = await prepareModel?.(body.id, body.configuration?.model, options.signal);
2996
3008
  const response = await transport.request(
2997
3009
  "/sessions",
2998
3010
  {
2999
3011
  method: "POST",
3000
3012
  body,
3013
+ headers: {
3014
+ ...body.workspaceId === void 0 ? {} : { "x-bobannomi-workspace-id": body.workspaceId },
3015
+ ...modelConnection === void 0 ? {} : { "x-bobannomi-model-connection": modelConnection }
3016
+ },
3001
3017
  signal: options.signal
3002
3018
  }
3003
3019
  );
@@ -3011,7 +3027,9 @@ async function getConfigurationOptions(transport, input, options = {}) {
3011
3027
  );
3012
3028
  }
3013
3029
  async function getCreationResult(transport, input, options = {}) {
3014
- if (input.original.cwd === void 0) await requireDaemonFeature(transport, "projectSessionCreation", options.signal);
3030
+ if (input.original.workspaceId !== void 0 || input.original.outsideProject)
3031
+ await requireDaemonFeature(transport, "sessionDirectoryCreation", options.signal);
3032
+ else if (input.original.cwd === void 0) await requireDaemonFeature(transport, "projectSessionCreation", options.signal);
3015
3033
  return transport.request("/sessions/creation-result", {
3016
3034
  method: "POST",
3017
3035
  body: input,
@@ -3025,11 +3043,17 @@ async function getConfiguration(transport, sessionId, options = {}) {
3025
3043
  );
3026
3044
  return decodeSessionConfigurationSnapshot(value);
3027
3045
  }
3028
- async function configure(transport, sessionId, input, options = {}) {
3046
+ async function configure(transport, sessionId, input, options = {}, prepareModel) {
3029
3047
  const body = parseConfigureSessionRequest(input);
3048
+ const modelConnection = await prepareModel?.(sessionId, body.configuration.model, options.signal);
3030
3049
  const response = await transport.requestUnknown(
3031
3050
  `/sessions/${encodeURIComponent(sessionId)}/configure`,
3032
- { method: "POST", body, signal: options.signal }
3051
+ {
3052
+ method: "POST",
3053
+ body,
3054
+ signal: options.signal,
3055
+ ...modelConnection === void 0 ? {} : { headers: { "x-bobannomi-model-connection": modelConnection } }
3056
+ }
3033
3057
  );
3034
3058
  return decodeSessionConfigurationReceipt(response, {
3035
3059
  sessionId,
@@ -3995,7 +4019,7 @@ async function interrupt(transport, sessionId, options = {}) {
3995
4019
  }
3996
4020
 
3997
4021
  // src/resources/session/session-handle.ts
3998
- function createSessionHandle(transport, syncClient, management, sessionId) {
4022
+ function createSessionHandle(transport, syncClient, management, sessionId, prepareModel) {
3999
4023
  function cancelQueuedPrompt2(inputId, input, options) {
4000
4024
  return cancelQueuedPrompt(transport, sessionId, inputId, input, options);
4001
4025
  }
@@ -4156,7 +4180,7 @@ function createSessionHandle(transport, syncClient, management, sessionId) {
4156
4180
  return getConfiguration(transport, sessionId, options);
4157
4181
  },
4158
4182
  update(input, options = {}) {
4159
- return configure(transport, sessionId, input, options);
4183
+ return configure(transport, sessionId, input, options, prepareModel);
4160
4184
  },
4161
4185
  getResult(input, options = {}) {
4162
4186
  return getConfigurationResult(transport, sessionId, input, options);
@@ -4263,17 +4287,19 @@ function createSessionHandle(transport, syncClient, management, sessionId) {
4263
4287
 
4264
4288
  // src/resources/session/session-resource.ts
4265
4289
  var SessionResource = class {
4266
- #management;
4267
- #events;
4268
- #transport;
4269
- constructor(transport, events) {
4290
+ constructor(transport, events, prepareModel) {
4291
+ this.prepareModel = prepareModel;
4270
4292
  this.#transport = transport;
4271
4293
  this.#management = new SessionManagementResource(transport);
4272
4294
  this.#events = events ?? new EventResource(transport, new SseTransport(transport));
4273
4295
  }
4296
+ prepareModel;
4297
+ #management;
4298
+ #events;
4299
+ #transport;
4274
4300
  /** Bind a session ID locally. Operations use this resource's daemon connection when called. */
4275
4301
  byId(sessionId) {
4276
- return createSessionHandle(this.#transport, { sessions: this, events: this.#events }, this.#management, sessionId);
4302
+ return createSessionHandle(this.#transport, { sessions: this, events: this.#events }, this.#management, sessionId, this.prepareModel);
4277
4303
  }
4278
4304
  /** `GET /sessions/search` - search saved conversation text without opening it. */
4279
4305
  async search(options) {
@@ -4304,7 +4330,7 @@ var SessionResource = class {
4304
4330
  }
4305
4331
  /** `POST /sessions` */
4306
4332
  create(input, options = {}) {
4307
- return create(this.#transport, input, options);
4333
+ return create(this.#transport, input, options, this.prepareModel);
4308
4334
  }
4309
4335
  getConfigurationOptions(input, options = {}) {
4310
4336
  return getConfigurationOptions(this.#transport, input, options);
@@ -4427,7 +4453,54 @@ var PermissionResource = class {
4427
4453
 
4428
4454
  // src/resources/runtime/runtime-resource.ts
4429
4455
  function createRuntimeResources(transport, providers) {
4430
- const catalog = typeof providers === "function" || providers === void 0 ? providers : structuredClone([...providers]);
4456
+ const catalog = typeof providers === "function" || providers === void 0 ? providers : providers.map(({ connection, ...provider2 }) => ({
4457
+ ...structuredClone(provider2),
4458
+ connection: typeof connection === "function" ? connection : structuredClone(connection)
4459
+ }));
4460
+ async function load(source, signal) {
4461
+ signal?.throwIfAborted();
4462
+ const value = await waitForRequest(Promise.resolve().then(() => {
4463
+ signal?.throwIfAborted();
4464
+ return source({ signal });
4465
+ }), signal);
4466
+ signal?.throwIfAborted();
4467
+ return value;
4468
+ }
4469
+ function readCatalog(signal) {
4470
+ signal?.throwIfAborted();
4471
+ return typeof catalog === "function" ? load(catalog, signal) : Promise.resolve(catalog ?? []);
4472
+ }
4473
+ const prepareModel = catalog === void 0 ? void 0 : async (sessionId, selection, signal) => {
4474
+ if (!selection) return;
4475
+ const provider2 = (await readCatalog(signal)).find(({ name }) => name === selection.provider);
4476
+ if (!provider2?.connection) return;
4477
+ if (!provider2.models.some(({ id: id2 }) => id2 === selection.model)) throw new Error("The selected model is not in the supplied provider catalog");
4478
+ await requireDaemonFeature(transport, "sessionModelConnections", signal);
4479
+ const connection = typeof provider2.connection === "function" ? await load(provider2.connection, signal) : provider2.connection;
4480
+ const { ref } = await transport.request("/model-connections", {
4481
+ method: "POST",
4482
+ signal,
4483
+ body: {
4484
+ sessionId,
4485
+ provider: {
4486
+ id: provider2.name,
4487
+ displayName: provider2.displayName,
4488
+ baseUrl: connection.baseUrl,
4489
+ apiKey: connection.apiKey,
4490
+ apiFormat: connection.apiFormat,
4491
+ models: provider2.models.map(({ id: id2, label, contextWindow, outputLimit, inputCapabilities }) => ({
4492
+ id: id2,
4493
+ displayName: label,
4494
+ contextWindow,
4495
+ maxOutputTokens: outputLimit,
4496
+ imageInputSupport: inputCapabilities?.image
4497
+ }))
4498
+ }
4499
+ }
4500
+ });
4501
+ if (typeof ref !== "string" || !ref) throw new Error("Invalid prepared model connection");
4502
+ return ref;
4503
+ };
4431
4504
  async function modelProviders(input, options = {}) {
4432
4505
  const response = await transport.request("/providers/manage", { ...options, method: "POST", body: input });
4433
4506
  if (!validModelProviderConnections(response?.providers)) throw new Error("Invalid model provider response");
@@ -4440,19 +4513,14 @@ function createRuntimeResources(transport, providers) {
4440
4513
  return result;
4441
4514
  }
4442
4515
  return {
4516
+ prepareModel,
4443
4517
  models: {
4444
4518
  async list({ signal } = {}) {
4445
4519
  if (catalog === void 0) {
4446
4520
  const response = await transport.request("/models", { signal });
4447
4521
  return response.providers;
4448
4522
  }
4449
- signal?.throwIfAborted();
4450
- const providers2 = typeof catalog === "function" ? await waitForRequest(Promise.resolve().then(() => {
4451
- signal?.throwIfAborted();
4452
- return catalog({ signal });
4453
- }), signal) : catalog;
4454
- signal?.throwIfAborted();
4455
- return structuredClone([...providers2]);
4523
+ return (await readCatalog(signal)).map(({ name, displayName, models }) => structuredClone({ name, displayName, models }));
4456
4524
  }
4457
4525
  },
4458
4526
  agents: {
@@ -5355,7 +5423,7 @@ var BobanNomiClient = class {
5355
5423
  const sse = new SseTransport(transport);
5356
5424
  this.protocol = new ProtocolClient(transport);
5357
5425
  const providers = options instanceof HttpTransport ? void 0 : options.providers;
5358
- const { models, modelProviders, agents, skills } = createRuntimeResources(transport, providers);
5426
+ const { models, modelProviders, agents, skills, prepareModel } = createRuntimeResources(transport, providers);
5359
5427
  this.models = models;
5360
5428
  this.modelProviders = modelProviders;
5361
5429
  this.agents = agents;
@@ -5364,7 +5432,7 @@ var BobanNomiClient = class {
5364
5432
  this.attachments = new AttachmentResource(transport);
5365
5433
  this.permissions = new PermissionResource(transport);
5366
5434
  this.events = new EventResource(transport, sse);
5367
- this.sessions = new SessionResource(transport, this.events);
5435
+ this.sessions = new SessionResource(transport, this.events, prepareModel);
5368
5436
  this.plugins = new PluginResource(transport);
5369
5437
  this.channels = new ChannelResource(transport);
5370
5438
  this.projects = new ProjectResource(transport);