* Resumes an existing conversation session by its ID. * * This allows you to continue a previous conversation, maintaining all * conversation history. The session must have been previously created * and not deleted. * * @param sessionId - The ID of the session to resume
(sessionId: string, config: ResumeSessionConfig)
| 1522 | * ``` |
| 1523 | */ |
| 1524 | async resumeSession(sessionId: string, config: ResumeSessionConfig): Promise<CopilotSession> { |
| 1525 | if (!this.connection) { |
| 1526 | await this.start(); |
| 1527 | } |
| 1528 | |
| 1529 | // Create and register the session before issuing the RPC so that |
| 1530 | // events emitted by the CLI (e.g. session.start) are not dropped. |
| 1531 | const session = new CopilotSession( |
| 1532 | sessionId, |
| 1533 | this.connection!, |
| 1534 | undefined, |
| 1535 | this.onGetTraceContext, |
| 1536 | { mcpAuthHandler: config.onMcpAuthRequest } |
| 1537 | ); |
| 1538 | session.registerTools(config.tools); |
| 1539 | session.registerCanvases(config.canvases); |
| 1540 | session.registerCommands(config.commands); |
| 1541 | const { |
| 1542 | wireProvider: bearerWireProvider, |
| 1543 | wireProviders: bearerWireProviders, |
| 1544 | callbacks: bearerTokenCallbacks, |
| 1545 | } = extractBearerTokenProviders(config.provider, config.providers); |
| 1546 | if (bearerTokenCallbacks.size > 0) { |
| 1547 | session.registerBearerTokenProviders(bearerTokenCallbacks); |
| 1548 | } |
| 1549 | session.registerPermissionHandler(config.onPermissionRequest); |
| 1550 | if (config.onUserInputRequest) { |
| 1551 | session.registerUserInputHandler(config.onUserInputRequest); |
| 1552 | } |
| 1553 | if (config.onElicitationRequest) { |
| 1554 | session.registerElicitationHandler(config.onElicitationRequest); |
| 1555 | } |
| 1556 | if (config.onExitPlanModeRequest) { |
| 1557 | session.registerExitPlanModeHandler(config.onExitPlanModeRequest); |
| 1558 | } |
| 1559 | if (config.onAutoModeSwitchRequest) { |
| 1560 | session.registerAutoModeSwitchHandler(config.onAutoModeSwitchRequest); |
| 1561 | } |
| 1562 | if (config.hooks) { |
| 1563 | session.registerHooks(config.hooks); |
| 1564 | } |
| 1565 | |
| 1566 | config = { ...this.configDefaultsForMode(), ...config }; |
| 1567 | config.systemMessage = this.getSystemMessageConfigForMode(config.systemMessage); |
| 1568 | |
| 1569 | const { wirePayload: wireSystemMessage, transformCallbacks } = extractTransformCallbacks( |
| 1570 | config.systemMessage |
| 1571 | ); |
| 1572 | if (transformCallbacks) { |
| 1573 | session.registerTransformCallbacks(transformCallbacks); |
| 1574 | } |
| 1575 | |
| 1576 | if (config.onEvent) { |
| 1577 | session.on(config.onEvent); |
| 1578 | } |
| 1579 | this.sessions.set(sessionId, session); |
| 1580 | this.setupSessionFs(session, config); |
| 1581 |
no test coverage detected