@bobannomi/client 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +6 -6
- package/dist/index.js +23 -23
- package/dist/index.js.map +1 -1
- package/dist/service.js +17 -17
- package/dist/service.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -2909,7 +2909,7 @@ declare function selectSessionMessagesWithParts(bucket: SessionBucket | undefine
|
|
|
2909
2909
|
* Default display view: hides superseded parts and drops assistant messages that
|
|
2910
2910
|
* have no visible parts left. The raw state keeps the diagnostic records.
|
|
2911
2911
|
*/
|
|
2912
|
-
declare function
|
|
2912
|
+
declare function getVisibleSessionMessages(bucket: SessionBucket | undefined): SessionMessageWithParts[];
|
|
2913
2913
|
declare function selectSessionInputs(bucket: SessionBucket | undefined): SessionInputRecord[];
|
|
2914
2914
|
declare function selectSessionOrderedMessages(bucket: SessionBucket | undefined): SessionMessageRecord[];
|
|
2915
2915
|
declare function selectSessionParts(bucket: SessionBucket | undefined): SessionMessagePartRecord[];
|
|
@@ -3120,8 +3120,8 @@ declare class SessionResource {
|
|
|
3120
3120
|
}): Promise<SessionCreationReceipt | null>;
|
|
3121
3121
|
}
|
|
3122
3122
|
|
|
3123
|
-
/** Generate a
|
|
3124
|
-
declare function
|
|
3123
|
+
/** Generate an ID to save before sending a session request that may need recovery. */
|
|
3124
|
+
declare function createSessionRequestId(): string;
|
|
3125
3125
|
|
|
3126
3126
|
declare class AttachmentResource {
|
|
3127
3127
|
private readonly transport;
|
|
@@ -4082,11 +4082,11 @@ declare class UnsupportedSessionEventSchemaVersionError extends Error {
|
|
|
4082
4082
|
constructor(event: SessionEventRecord);
|
|
4083
4083
|
}
|
|
4084
4084
|
/** 空客户端状态,作为 replay/hydrate 起点。 */
|
|
4085
|
-
declare function
|
|
4085
|
+
declare function createClientState(): BobanNomiClientState;
|
|
4086
4086
|
/** 按序批量应用事件。 */
|
|
4087
4087
|
declare function applyEvents(state: BobanNomiClientState, events: Iterable<SessionEventRecord>): BobanNomiClientState;
|
|
4088
4088
|
/** Replace one session bucket with an atomic server snapshot. */
|
|
4089
|
-
declare function
|
|
4089
|
+
declare function replaceSessionState(state: BobanNomiClientState, snapshot: AgentSessionStateSnapshot): BobanNomiClientState;
|
|
4090
4090
|
/**
|
|
4091
4091
|
* 应用单条事件。已见过的 `seq` 直接返回原 state(引用相等,便于 live 去重)。
|
|
4092
4092
|
*/
|
|
@@ -4133,5 +4133,5 @@ declare function isWorkMode(value: unknown): value is WorkMode;
|
|
|
4133
4133
|
declare function readSessionRuntimeConfig(session: SessionRecord, defaults?: Partial<SessionRuntimeConfig>): SessionRuntimeConfig;
|
|
4134
4134
|
declare function patchSessionRuntimeMetadata(metadata: Record<string, unknown>, patch: SessionRuntimeConfigPatch): Record<string, unknown>;
|
|
4135
4135
|
|
|
4136
|
-
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,
|
|
4136
|
+
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
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 };
|
package/dist/index.js
CHANGED
|
@@ -2958,13 +2958,13 @@ var ScheduleResource = class {
|
|
|
2958
2958
|
};
|
|
2959
2959
|
|
|
2960
2960
|
// src/resources/session/session-request-id.ts
|
|
2961
|
-
var
|
|
2962
|
-
function
|
|
2961
|
+
var sessionRequestCounter = 0;
|
|
2962
|
+
function createSessionRequestId() {
|
|
2963
2963
|
if (typeof globalThis.crypto?.randomUUID === "function") {
|
|
2964
2964
|
return globalThis.crypto.randomUUID();
|
|
2965
2965
|
}
|
|
2966
|
-
|
|
2967
|
-
return `prompt-${Date.now().toString(36)}-${
|
|
2966
|
+
sessionRequestCounter += 1;
|
|
2967
|
+
return `prompt-${Date.now().toString(36)}-${sessionRequestCounter.toString(36)}`;
|
|
2968
2968
|
}
|
|
2969
2969
|
|
|
2970
2970
|
// src/resources/session/session-configuration-requests.ts
|
|
@@ -2989,8 +2989,8 @@ async function getDraftComposerOptions(transport, input, options = {}) {
|
|
|
2989
2989
|
async function create(transport, input, options = {}) {
|
|
2990
2990
|
const body = parseCreateSessionRequest({
|
|
2991
2991
|
...input,
|
|
2992
|
-
id: input.id ??
|
|
2993
|
-
requestId: input.requestId ??
|
|
2992
|
+
id: input.id ?? createSessionRequestId(),
|
|
2993
|
+
requestId: input.requestId ?? createSessionRequestId()
|
|
2994
2994
|
});
|
|
2995
2995
|
if (body.cwd === void 0) await requireDaemonFeature(transport, "projectSessionCreation", options.signal);
|
|
2996
2996
|
const response = await transport.request(
|
|
@@ -3142,7 +3142,7 @@ function selectSessionMessagesWithParts(bucket) {
|
|
|
3142
3142
|
parts: [...bucket.partsByMessageId[message.id] ?? []].sort((a, b) => a.seq - b.seq)
|
|
3143
3143
|
}));
|
|
3144
3144
|
}
|
|
3145
|
-
function
|
|
3145
|
+
function getVisibleSessionMessages(bucket) {
|
|
3146
3146
|
return selectSessionMessagesWithParts(bucket).map(({ message, parts }) => ({
|
|
3147
3147
|
message,
|
|
3148
3148
|
parts: parts.filter((part) => !isSupersededModelPart(part))
|
|
@@ -3215,7 +3215,7 @@ var UnsupportedSessionEventSchemaVersionError = class extends Error {
|
|
|
3215
3215
|
};
|
|
3216
3216
|
}
|
|
3217
3217
|
};
|
|
3218
|
-
function
|
|
3218
|
+
function createClientState() {
|
|
3219
3219
|
return {
|
|
3220
3220
|
sessions: {},
|
|
3221
3221
|
sessionOrder: [],
|
|
@@ -3231,7 +3231,7 @@ function applyEvents(state, events) {
|
|
|
3231
3231
|
for (const event of events) next = applyEvent(next, event);
|
|
3232
3232
|
return next;
|
|
3233
3233
|
}
|
|
3234
|
-
function
|
|
3234
|
+
function replaceSessionState(state, snapshot) {
|
|
3235
3235
|
const knownCursor = state.snapshotCursorBySession[snapshot.session.id] ?? 0;
|
|
3236
3236
|
if (snapshot.cursor < knownCursor) return state;
|
|
3237
3237
|
if (Object.values(state.eventsBySeq).some((event) => event.sessionId === snapshot.session.id && event.seq > snapshot.cursor)) return state;
|
|
@@ -3589,7 +3589,7 @@ function applySessionStreamEvent(state, event) {
|
|
|
3589
3589
|
}
|
|
3590
3590
|
function applySessionStreamSnapshot(state, snapshot) {
|
|
3591
3591
|
if (snapshot.cursor < state.lastSeq) return state;
|
|
3592
|
-
return { ...
|
|
3592
|
+
return { ...replaceSessionState(state, snapshot), eventsBySeq: {} };
|
|
3593
3593
|
}
|
|
3594
3594
|
|
|
3595
3595
|
// src/state/sync.ts
|
|
@@ -3597,7 +3597,7 @@ var DEFAULT_RECONNECT_DELAY_MS = (attempt) => Math.min(3e4, 250 * 2 ** Math.max(
|
|
|
3597
3597
|
var DEFAULT_SESSION_IDLE_TIMEOUT_MS = 6e4;
|
|
3598
3598
|
var EVENT_REPLAY_PAGE_SIZE = 128;
|
|
3599
3599
|
function hydrateState(events) {
|
|
3600
|
-
return applyEvents(
|
|
3600
|
+
return applyEvents(createClientState(), events);
|
|
3601
3601
|
}
|
|
3602
3602
|
async function* syncEvents(client, options = {}) {
|
|
3603
3603
|
yield* runEventSync(client, {
|
|
@@ -3607,7 +3607,7 @@ async function* syncEvents(client, options = {}) {
|
|
|
3607
3607
|
idleTimeoutMs: options.idleTimeoutMs ?? DEFAULT_SESSION_IDLE_TIMEOUT_MS
|
|
3608
3608
|
});
|
|
3609
3609
|
}
|
|
3610
|
-
async function* runEventSync(client, options, initialState =
|
|
3610
|
+
async function* runEventSync(client, options, initialState = createClientState(), onLiveEvent) {
|
|
3611
3611
|
let state = initialState;
|
|
3612
3612
|
let cursor = Math.max(0, options.cursor ?? 0, state.lastSeq);
|
|
3613
3613
|
let attempt = 0;
|
|
@@ -3622,7 +3622,7 @@ async function* runEventSync(client, options, initialState = createInitialClient
|
|
|
3622
3622
|
partView: options.partView
|
|
3623
3623
|
});
|
|
3624
3624
|
if (signal?.aborted) return;
|
|
3625
|
-
const next = initial ?
|
|
3625
|
+
const next = initial ? replaceSessionState(state, snapshot) : applySessionStreamSnapshot(state, snapshot);
|
|
3626
3626
|
state = Object.keys(next.eventsBySeq).length ? { ...next, eventsBySeq: {} } : next;
|
|
3627
3627
|
cursor = Math.max(cursor, snapshot.cursor, state.lastSeq);
|
|
3628
3628
|
};
|
|
@@ -3732,7 +3732,7 @@ async function waitForRun(client, options) {
|
|
|
3732
3732
|
if (!run || run.status === "pending" || run.status === "running") continue;
|
|
3733
3733
|
return {
|
|
3734
3734
|
run,
|
|
3735
|
-
messages:
|
|
3735
|
+
messages: getVisibleSessionMessages(bucket).filter((item) => item.message.runId === options.runId)
|
|
3736
3736
|
};
|
|
3737
3737
|
}
|
|
3738
3738
|
options.signal?.throwIfAborted();
|
|
@@ -3926,7 +3926,7 @@ async function admitPrompt(transport, sessionId, input, options = {}) {
|
|
|
3926
3926
|
`/sessions/${encodeURIComponent(sessionId)}/prompts`,
|
|
3927
3927
|
{
|
|
3928
3928
|
method: "POST",
|
|
3929
|
-
body: { ...input, expectedModelConnection, id: input.id ??
|
|
3929
|
+
body: { ...input, expectedModelConnection, id: input.id ?? createSessionRequestId() },
|
|
3930
3930
|
signal: options.signal
|
|
3931
3931
|
}
|
|
3932
3932
|
);
|
|
@@ -3978,7 +3978,7 @@ async function resumeInterruptedRun(transport, sessionId, runId, input = {}, opt
|
|
|
3978
3978
|
`/sessions/${encodeURIComponent(sessionId)}/runs/${encodeURIComponent(runId)}/resume`,
|
|
3979
3979
|
{
|
|
3980
3980
|
method: "POST",
|
|
3981
|
-
body: { ...input, id: input.id ??
|
|
3981
|
+
body: { ...input, id: input.id ?? createSessionRequestId() },
|
|
3982
3982
|
signal: options.signal
|
|
3983
3983
|
}
|
|
3984
3984
|
);
|
|
@@ -4110,8 +4110,8 @@ function createSessionHandle(transport, syncClient, management, sessionId) {
|
|
|
4110
4110
|
method: "POST",
|
|
4111
4111
|
body: parseForkSessionRequest({
|
|
4112
4112
|
...input,
|
|
4113
|
-
id: input.id ??
|
|
4114
|
-
requestId: input.requestId ??
|
|
4113
|
+
id: input.id ?? createSessionRequestId(),
|
|
4114
|
+
requestId: input.requestId ?? createSessionRequestId()
|
|
4115
4115
|
}),
|
|
4116
4116
|
signal: options.signal
|
|
4117
4117
|
}
|
|
@@ -5393,7 +5393,7 @@ var SessionSyncController = class {
|
|
|
5393
5393
|
running = false;
|
|
5394
5394
|
constructor(options) {
|
|
5395
5395
|
this.options = { ...options };
|
|
5396
|
-
this.state = options.initialState ??
|
|
5396
|
+
this.state = options.initialState ?? createClientState();
|
|
5397
5397
|
if ((options.cursor ?? 0) > 0 && !options.initialState) {
|
|
5398
5398
|
throw new Error("A non-zero cursor requires initialState so durable state is not skipped");
|
|
5399
5399
|
}
|
|
@@ -5566,11 +5566,11 @@ export {
|
|
|
5566
5566
|
UnsupportedSessionEventSchemaVersionError,
|
|
5567
5567
|
applyEvent,
|
|
5568
5568
|
applyEvents,
|
|
5569
|
-
applySessionSnapshot,
|
|
5570
5569
|
attachmentRangeHeader,
|
|
5571
5570
|
checkProtocolCompatibility,
|
|
5572
|
-
|
|
5573
|
-
|
|
5571
|
+
createClientState,
|
|
5572
|
+
createSessionRequestId,
|
|
5573
|
+
getVisibleSessionMessages,
|
|
5574
5574
|
hydrateState,
|
|
5575
5575
|
isSupersededModelPart,
|
|
5576
5576
|
isWorkMode,
|
|
@@ -5587,6 +5587,7 @@ export {
|
|
|
5587
5587
|
readSessionModelUsage,
|
|
5588
5588
|
readSessionRuntimeConfig,
|
|
5589
5589
|
readWorkspaceChangesMetadata,
|
|
5590
|
+
replaceSessionState,
|
|
5590
5591
|
responseArray2 as responseArray,
|
|
5591
5592
|
responseField,
|
|
5592
5593
|
selectFirstPendingPermission,
|
|
@@ -5599,7 +5600,6 @@ export {
|
|
|
5599
5600
|
selectSessionPermissions,
|
|
5600
5601
|
selectSessionRuns,
|
|
5601
5602
|
selectSessionTasks,
|
|
5602
|
-
selectVisibleSessionMessagesWithParts,
|
|
5603
5603
|
streamServerSentEvents,
|
|
5604
5604
|
supportsFeature,
|
|
5605
5605
|
syncEvents
|