Skip to content

Commit e262db2

Browse files
Deploy documentation: snapshot
1 parent b1a86c2 commit e262db2

1,224 files changed

Lines changed: 9289 additions & 3726 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

snapshot/advanced.html

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ <h2>Table of Contents</h2>
274274
<li><a href="#Session_Capabilities">Session Capabilities</a></li>
275275
<li><a href="#Outgoing_Elicitation_via_session.getUi">Outgoing Elicitation via session.getUi()</a></li>
276276
</ul></li>
277+
<li><a href="#Mode_Handlers">Mode Handlers</a>
278+
<ul>
279+
280+
<li><a href="#Exit_Plan_Mode">Exit Plan Mode</a></li>
281+
<li><a href="#Auto_Mode_Switch">Auto Mode Switch</a></li>
282+
</ul></li>
277283
<li><a href="#Getting_Session_Metadata_by_ID">Getting Session Metadata by ID</a></li>
278284
</ul><hr /></section><section><a id="Custom_Tools"></a>
279285
<h2>Custom Tools</h2>
@@ -1373,7 +1379,76 @@ <h3>Outgoing Elicitation via <code>session.getUi()</code></h3>
13731379
.setRequired(List.of(&quot;branch&quot;, &quot;environment&quot;))
13741380
)).get();
13751381
</code></pre>
1376-
<p>All <code>getUi()</code> methods throw <code>IllegalStateException</code> if the host does not support elicitation. Always check capabilities first.</p><hr /></section></section><section><a id="Getting_Session_Metadata_by_ID"></a>
1382+
<p>All <code>getUi()</code> methods throw <code>IllegalStateException</code> if the host does not support elicitation. Always check capabilities first.</p><hr /></section></section><section><a id="Mode_Handlers"></a>
1383+
<h2>Mode Handlers</h2>
1384+
<p>Mode handlers let your application respond to mode transitions requested by the Copilot CLI.</p><section><a id="Exit_Plan_Mode"></a>
1385+
<h3>Exit Plan Mode</h3>
1386+
<p>When the model finishes creating a plan and wants to transition out of plan mode, it invokes the <code>exitPlanMode</code> handler. Register the handler via <code>SessionConfig.setOnExitPlanMode()</code>:</p>
1387+
1388+
<pre class="prettyprint"><code class="language-java">var session = client.createSession(new SessionConfig()
1389+
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
1390+
.setOnExitPlanMode((request, invocation) -&gt; {
1391+
System.out.println(&quot;Plan summary: &quot; + request.getSummary());
1392+
System.out.println(&quot;Available actions: &quot; + request.getActions());
1393+
System.out.println(&quot;Recommended: &quot; + request.getRecommendedAction());
1394+
1395+
return CompletableFuture.completedFuture(
1396+
new ExitPlanModeResult()
1397+
.setApproved(true)
1398+
.setSelectedAction(&quot;interactive&quot;)
1399+
.setFeedback(&quot;Looks good, proceed!&quot;));
1400+
})).get();
1401+
</code></pre>
1402+
<p>When no handler is registered, the SDK automatically approves the plan (<code>approved=true</code>). The handler receives an <code>ExitPlanModeRequest</code> with:</p>
1403+
<table class="table table-striped">
1404+
<thead>
1405+
<tr class="a">
1406+
<th>Field</th>
1407+
<th>Description</th></tr></thead><tbody>
1408+
<tr class="b">
1409+
<td><code>summary</code></td>
1410+
<td>Summary of the plan that was created</td></tr>
1411+
<tr class="a">
1412+
<td><code>planContent</code></td>
1413+
<td>Full content of the plan file</td></tr>
1414+
<tr class="b">
1415+
<td><code>actions</code></td>
1416+
<td>Available actions (e.g., interactive, autopilot)</td></tr>
1417+
<tr class="a">
1418+
<td><code>recommendedAction</code></td>
1419+
<td>The recommended action for the user</td></tr></tbody>
1420+
</table>
1421+
</section><section><a id="Auto_Mode_Switch"></a>
1422+
<h3>Auto Mode Switch</h3>
1423+
<p>When the model encounters a rate limit or similar constraint, it may request to switch modes automatically. Register the handler via <code>SessionConfig.setOnAutoModeSwitch()</code>:</p>
1424+
1425+
<pre class="prettyprint"><code class="language-java">var session = client.createSession(new SessionConfig()
1426+
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
1427+
.setOnAutoModeSwitch((request, invocation) -&gt; {
1428+
System.out.println(&quot;Error: &quot; + request.getErrorCode());
1429+
System.out.println(&quot;Retry after: &quot; + request.getRetryAfterSeconds() + &quot;s&quot;);
1430+
1431+
return CompletableFuture.completedFuture(AutoModeSwitchResponse.YES);
1432+
})).get();
1433+
</code></pre>
1434+
<p>When no handler is registered, the SDK returns <code>NO</code> (declining the mode switch). The response options are:</p>
1435+
<table class="table table-striped">
1436+
<thead>
1437+
<tr class="a">
1438+
<th>Response</th>
1439+
<th>Description</th></tr></thead><tbody>
1440+
<tr class="b">
1441+
<td><code>AutoModeSwitchResponse.YES</code></td>
1442+
<td>Allow the mode switch this time</td></tr>
1443+
<tr class="a">
1444+
<td><code>AutoModeSwitchResponse.YES_ALWAYS</code></td>
1445+
<td>Always allow automatic mode switches</td></tr>
1446+
<tr class="b">
1447+
<td><code>AutoModeSwitchResponse.NO</code></td>
1448+
<td>Decline the mode switch</td></tr></tbody>
1449+
</table>
1450+
1451+
<p>Both handlers are also available on <code>ResumeSessionConfig</code> for resumed sessions.</p><hr /></section></section><section><a id="Getting_Session_Metadata_by_ID"></a>
13771452
<h2>Getting Session Metadata by ID</h2>
13781453
<p>Retrieve metadata for a specific session without listing all sessions:</p>
13791454

0 commit comments

Comments
 (0)