Skip to content

Commit 2028988

Browse files
committed
make it simpler, fix issues
1 parent a177750 commit 2028988

7 files changed

Lines changed: 807 additions & 660 deletions

File tree

src/vs/base/common/buffer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export function binaryIndexOf(haystack: Uint8Array, needle: Uint8Array, offset =
213213
}
214214

215215
if (needleLen === 1) {
216-
return haystack.indexOf(needle[0]);
216+
return haystack.indexOf(needle[0], offset);
217217
}
218218

219219
if (needleLen > haystackLen - offset) {

src/vs/platform/files/common/inMemoryFilesystemProvider.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,6 @@ export class InMemoryFileSystemProvider extends Disposable implements
147147
if (!entry && !opts.create) {
148148
throw createFileSystemProviderError('file not found', FileSystemProviderErrorCode.FileNotFound);
149149
}
150-
if (entry && opts.create && !opts.overwrite) {
151-
throw createFileSystemProviderError('file exists already', FileSystemProviderErrorCode.FileExists);
152-
}
153150
if (!entry) {
154151
entry = new File(basename);
155152
parent.entries.set(basename, entry);

src/vs/workbench/contrib/chat/common/model/chatModel.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { ILanguageModelChatMetadata, ILanguageModelChatMetadataAndIdentifier } f
3737
import { IChatAgentCommand, IChatAgentData, IChatAgentResult, IChatAgentService, UserSelectedTools, reviveSerializedAgent } from '../participants/chatAgents.js';
3838
import { ChatRequestTextPart, IParsedChatRequest, reviveParsedChatRequest } from '../requestParser/chatParserTypes.js';
3939
import { LocalChatSessionUri } from './chatUri.js';
40+
import { ObjectMutationLog } from './objectMutationLog.js';
4041

4142

4243
export const CHAT_ATTACHABLE_IMAGE_MIME_TYPES: Record<string, string> = {
@@ -210,6 +211,8 @@ export interface IChatResponseModel {
210211
readonly completedAt?: number;
211212
/** The state of this response */
212213
readonly state: ResponseModelState;
214+
/** @internal */
215+
readonly stateT: ResponseModelStateT;
213216
/**
214217
* Adjusted millisecond timestamp that excludes the duration during which
215218
* the model was pending user confirmation. `Date.now() - confirmationAdjustedTimestamp`
@@ -792,7 +795,7 @@ export interface IChatResponseModelParameters {
792795
codeBlockInfos: ICodeBlockInfo[] | undefined;
793796
}
794797

795-
type ResponseModelStateT =
798+
export type ResponseModelStateT =
796799
| { value: ResponseModelState.Pending }
797800
| { value: ResponseModelState.NeedsInput }
798801
| { value: ResponseModelState.Complete | ResponseModelState.Cancelled | ResponseModelState.Failed; completedAt: number };
@@ -869,6 +872,10 @@ export class ChatResponseModel extends Disposable implements IChatResponseModel
869872
return state;
870873
}
871874

875+
public get stateT(): ResponseModelStateT {
876+
return this._modelState.get();
877+
}
878+
872879
public get vote(): ChatAgentVoteDirection | undefined {
873880
return this._vote;
874881
}
@@ -1398,9 +1405,7 @@ export interface ISerializableChatModelInputState {
13981405
*/
13991406
export type ISerializableChatData = ISerializableChatData3;
14001407

1401-
export interface IChatDataSerializerLog {
1402-
write(current: IChatModel): { op: 'append' | 'replace'; data: VSBuffer };
1403-
}
1408+
export type IChatDataSerializerLog = ObjectMutationLog<IChatModel, ISerializableChatData>;
14041409

14051410
export interface ISerializedChatDataReference {
14061411
value: ISerializableChatData | IExportableChatData;
@@ -1736,7 +1741,7 @@ export class ChatModel extends Disposable implements IChatModel {
17361741
public dataSerializer?: IChatDataSerializerLog;
17371742

17381743
constructor(
1739-
initialData: ISerializedChatDataReference | undefined,
1744+
dataRef: ISerializedChatDataReference | undefined,
17401745
initialModelProps: { initialLocation: ChatAgentLocation; canUseTools: boolean; inputState?: ISerializableChatModelInputState; resource?: URI; sessionId?: string; disableBackgroundKeepAlive?: boolean },
17411746
@IConfigurationService private readonly configurationService: IConfigurationService,
17421747
@ILogService private readonly logService: ILogService,
@@ -1746,6 +1751,7 @@ export class ChatModel extends Disposable implements IChatModel {
17461751
) {
17471752
super();
17481753

1754+
const initialData = dataRef?.value;
17491755
const isValidExportedData = isExportableSessionData(initialData);
17501756
const isValidFullData = isValidExportedData && isSerializableSessionData(initialData);
17511757
if (initialData && !isValidExportedData) {
@@ -1775,9 +1781,9 @@ export class ChatModel extends Disposable implements IChatModel {
17751781
selections: serializedInputState.selections
17761782
});
17771783

1778-
this.dataSerializer = initialData?.serializer;
1779-
this._initialResponderUsername = initialData?.value.responderUsername;
1780-
this._initialLocation = initialData?.value.initialLocation ?? initialModelProps.initialLocation;
1784+
this.dataSerializer = dataRef?.serializer;
1785+
this._initialResponderUsername = initialData?.responderUsername;
1786+
this._initialLocation = initialData?.initialLocation ?? initialModelProps.initialLocation;
17811787

17821788
this._canUseTools = initialModelProps.canUseTools;
17831789

@@ -1918,6 +1924,11 @@ export class ChatModel extends Disposable implements IChatModel {
19181924
const result = 'responseErrorDetails' in raw ?
19191925
// eslint-disable-next-line local/code-no-dangerous-type-assertions
19201926
{ errorDetails: raw.responseErrorDetails } as IChatAgentResult : raw.result;
1927+
let modelState = raw.modelState || { value: raw.isCanceled ? ResponseModelState.Cancelled : ResponseModelState.Complete, completedAt: Date.now() };
1928+
if (modelState.value === ResponseModelState.Pending || modelState.value === ResponseModelState.NeedsInput) {
1929+
modelState = { value: ResponseModelState.Cancelled, completedAt: Date.now() };
1930+
}
1931+
19211932
request.response = new ChatResponseModel({
19221933
responseContent: raw.response ?? [new MarkdownString(raw.response)],
19231934
session: this,

0 commit comments

Comments
 (0)