Skip to content

Commit bc1c48e

Browse files
Deploy documentation: snapshot
1 parent 3016abb commit bc1c48e

564 files changed

Lines changed: 14144 additions & 2800 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: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,119 @@ <h2>OpenTelemetry</h2>
12151215
<td>Whether to capture message content</td></tr></tbody>
12161216
</table>
12171217

1218-
<p>See <a href="apidocs/com/github/copilot/sdk/json/TelemetryConfig.html">TelemetryConfig</a> Javadoc for details.</p><hr /></section><section><a id="Next_Steps"></a>
1218+
<p>See <a href="apidocs/com/github/copilot/sdk/json/TelemetryConfig.html">TelemetryConfig</a> Javadoc for details.</p><hr /></section><section><a id="Slash_Commands"></a>
1219+
<h2>Slash Commands</h2>
1220+
<p>Register custom slash commands that users can invoke from the CLI TUI with <code>/commandname</code>.</p><section><a id="Registering_Commands"></a>
1221+
<h3>Registering Commands</h3>
1222+
1223+
<pre class="prettyprint"><code class="language-java">var config = new SessionConfig()
1224+
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
1225+
.setCommands(List.of(
1226+
new CommandDefinition()
1227+
.setName(&quot;deploy&quot;)
1228+
.setDescription(&quot;Deploy the current branch&quot;)
1229+
.setHandler(context -&gt; {
1230+
System.out.println(&quot;Deploying with args: &quot; + context.getArgs());
1231+
// perform deployment ...
1232+
return CompletableFuture.completedFuture(null);
1233+
}),
1234+
new CommandDefinition()
1235+
.setName(&quot;rollback&quot;)
1236+
.setDescription(&quot;Roll back the last deployment&quot;)
1237+
.setHandler(context -&gt; {
1238+
// perform rollback ...
1239+
return CompletableFuture.completedFuture(null);
1240+
})
1241+
));
1242+
1243+
try (CopilotClient client = new CopilotClient()) {
1244+
client.start().get();
1245+
var session = client.createSession(config).get();
1246+
// Users can now type /deploy or /rollback in the TUI
1247+
}
1248+
</code></pre>
1249+
<p>Each <code>CommandDefinition</code> requires a <code>name</code> (without the leading <code>/</code>), an optional <code>description</code> shown in the TUI's command completion UI, and a <code>CommandHandler</code> that is invoked when the user executes the command.</p>
1250+
<p>The <code>CommandContext</code> passed to the handler provides:</p>
1251+
<ul>
1252+
1253+
<li><code>getSessionId()</code> &#x2014; the ID of the session where the command was invoked</li>
1254+
<li><code>getCommand()</code> &#x2014; the full command text (e.g., <code>/deploy production</code>)</li>
1255+
<li><code>getCommandName()</code> &#x2014; command name without the leading <code>/</code> (e.g., <code>deploy</code>)</li>
1256+
<li><code>getArgs()</code> &#x2014; the argument string after the command name (e.g., <code>production</code>)</li>
1257+
</ul><hr /></section></section><section><a id="Elicitation_.28UI_Dialogs.29"></a>
1258+
<h2>Elicitation (UI Dialogs)</h2>
1259+
<p>Elicitation allows your application to present structured UI dialogs to the user. There are two directions:</p>
1260+
<ol style="list-style-type: decimal;">
1261+
1262+
<li><strong>Incoming</strong> &#x2014; The server or an MCP tool requests input from the user via your <code>onElicitationRequest</code> handler.</li>
1263+
<li><strong>Outgoing</strong> &#x2014; Your session-side code proactively requests input via <code>session.getUi()</code>.</li>
1264+
</ol><section><a id="Incoming_Elicitation_Handler"></a>
1265+
<h3>Incoming Elicitation Handler</h3>
1266+
<p>Register a handler to receive elicitation requests from the server:</p>
1267+
1268+
<pre class="prettyprint"><code class="language-java">var config = new SessionConfig()
1269+
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
1270+
.setOnElicitationRequest(context -&gt; {
1271+
System.out.println(&quot;Elicitation request: &quot; + context.getMessage());
1272+
// Show the form to the user ...
1273+
var content = Map.of(&quot;confirmed&quot;, true);
1274+
return CompletableFuture.completedFuture(
1275+
new ElicitationResult()
1276+
.setAction(ElicitationResultAction.ACCEPT)
1277+
.setContent(content)
1278+
);
1279+
});
1280+
</code></pre>
1281+
<p>When <code>onElicitationRequest</code> is set, the SDK reports elicitation as a supported capability and the server will route elicitation requests to your handler.</p></section><section><a id="Session_Capabilities"></a>
1282+
<h3>Session Capabilities</h3>
1283+
<p>After <code>createSession</code> or <code>resumeSession</code>, check <code>session.getCapabilities()</code> to see what the host supports:</p>
1284+
1285+
<pre class="prettyprint"><code class="language-java">var session = client.createSession(config).get();
1286+
1287+
var caps = session.getCapabilities();
1288+
if (caps.getUi() != null &amp;&amp; Boolean.TRUE.equals(caps.getUi().getElicitation())) {
1289+
System.out.println(&quot;Elicitation is supported&quot;);
1290+
}
1291+
</code></pre>
1292+
<p>Capabilities are updated in real time when a <code>capabilities.changed</code> event is received.</p></section><section><a id="Outgoing_Elicitation_via_session.getUi.28.29"></a>
1293+
<h3>Outgoing Elicitation via <code>session.getUi()</code></h3>
1294+
<p>If the host reports elicitation support, you can call the convenience methods on <code>session.getUi()</code>:</p>
1295+
1296+
<pre class="prettyprint"><code class="language-java">var ui = session.getUi();
1297+
1298+
// Boolean confirmation
1299+
boolean confirmed = ui.confirm(&quot;Are you sure you want to proceed?&quot;).get();
1300+
1301+
// Selection from options
1302+
String choice = ui.select(&quot;Choose an environment&quot;, new String[]{&quot;dev&quot;, &quot;staging&quot;, &quot;prod&quot;}).get();
1303+
1304+
// Text input
1305+
String value = ui.input(&quot;Enter your name&quot;, null).get();
1306+
1307+
// Custom schema
1308+
var result = ui.elicitation(new ElicitationParams()
1309+
.setMessage(&quot;Enter deployment details&quot;)
1310+
.setRequestedSchema(new ElicitationSchema()
1311+
.setProperties(Map.of(
1312+
&quot;branch&quot;, Map.of(&quot;type&quot;, &quot;string&quot;),
1313+
&quot;environment&quot;, Map.of(&quot;type&quot;, &quot;string&quot;, &quot;enum&quot;, List.of(&quot;dev&quot;, &quot;staging&quot;, &quot;prod&quot;))
1314+
))
1315+
.setRequired(List.of(&quot;branch&quot;, &quot;environment&quot;))
1316+
)).get();
1317+
</code></pre>
1318+
<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>
1319+
<h2>Getting Session Metadata by ID</h2>
1320+
<p>Retrieve metadata for a specific session without listing all sessions:</p>
1321+
1322+
<pre class="prettyprint"><code class="language-java">SessionMetadata metadata = client.getSessionMetadata(&quot;session-123&quot;).get();
1323+
if (metadata != null) {
1324+
System.out.println(&quot;Session: &quot; + metadata.getSessionId());
1325+
System.out.println(&quot;Started: &quot; + metadata.getStartTime());
1326+
} else {
1327+
System.out.println(&quot;Session not found&quot;);
1328+
}
1329+
</code></pre>
1330+
<p>This is more efficient than <code>listSessions()</code> when you already know the session ID, as it performs a direct O(1) lookup instead of scanning all sessions.</p><hr /></section><section><a id="Next_Steps"></a>
12191331
<h2>Next Steps</h2>
12201332
<ul>
12211333

0 commit comments

Comments
 (0)