1272
1273
const newItem = await this.chatSessionService.createNewChatSessionItem(getChatSessionType(untitledResource), { prompt: requestText, command: commandPart?.text, initialSessionOptions, untitledResource }, CancellationToken.None);
1275
materialized.complete(undefined);
1276
return undefined;
1277
}
1279
>
// Register the inverse alias before loading so session-option lookups
1280
>
// for the new resource resolve to the untitled session's options.
1281
>
this.chatSessionService.registerSessionResourceAlias(untitledResource, newItem.resource);
1282
>
1283
>
// Do not dispose tempRef as per 6bc5ae80de9caffb21e9eb58e18b5ca24fa2d6e8
1284
>
const tempRef = await this.loadRemoteSession(newItem.resource, untitledModel.initialLocation, CancellationToken.None);
1285
>
const realModel = tempRef?.object as ChatModel | undefined;
1286
if (!realModel) {
1287
throw new Error(`Failed to load session for resource: ${newItem.resource}`);
1288
}
1290
>
// Update the new model's contributed session with initialSessionOptions
1291
>
// so that the agent receives them when invoked.
1292
>
if (initialSessionOptions) {
1293
this.chatSessionService.updateSessionOptions(realModel.sessionResource, initialSessionOptions);
1294
}
1296
>
// Publish the forward mapping only after a successful load (see
1297
>
// `setMaterializedSessionResource`).
1298
>
this.chatSessionService.setMaterializedSessionResource(untitledResource, newItem.resource);
1299
>
materialized.complete(newItem.resource);
1300
>
// If this ever logs twice for the
1301
>
// same untitled resource (different real resources), a single send
1302
>
// produced duplicate sessions.
1303
>
this.info('materializeUntitledSession', `Materialized untitled session ${untitledResource.toString()} into real session ${newItem.resource.toString()}`);
1304
>
return { model: realModel, sessionResource: newItem.resource, newSessionResource: newItem.resource };
1305
} catch (err) {
1306
// Resolve (not reject) so a concurrent waiter degrades to the normal