@@ -324,11 +324,11 @@ hooks: {
324324` ` ` js
325325hooks: {
326326 onSessionStart: async (input) => {
327- console.log( ` Session started (source : ${ input .source }) ` );
327+ // input.source is "startup", "resume", or "new"
328328 return { additionalContext: "Remember to write tests for all changes." };
329329 },
330330 onSessionEnd: async (input) => {
331- console.log( ` Session ended (reason : ${ input .reason }) ` );
331+ // input.reason is "complete", "error", "abort", "timeout", or "user_exit"
332332 },
333333}
334334` ` `
@@ -343,15 +343,15 @@ After calling `resumeSession`, use `session.on()` to react to events in real tim
343343
344344` ` ` js
345345session.on("assistant.message", (event) => {
346- console.log("Agent said:", event.data.content);
346+ // event.data.content has the agent's response text
347347});
348348` ` `
349349
350350### Listening to all events
351351
352352` ` ` js
353353session.on((event) => {
354- console.log( ` [${ event .type }] ` , event.data);
354+ // event.type and event.data are available for all events
355355});
356356` ` `
357357
@@ -361,7 +361,7 @@ session.on((event) => {
361361
362362` ` ` js
363363const unsubscribe = session.on("tool.execution_complete", (event) => {
364- console.log( ` Tool ${ event .data .toolName } finished ` );
364+ // event.data.toolName, event.data.success, event.data.result, event.data.error
365365});
366366
367367// Later, stop listening
@@ -546,7 +546,7 @@ await session.send({ prompt: "Analyze the test results." });
546546
547547` ` ` js
548548const response = await session.sendAndWait({ prompt: "What is 2 + 2?" });
549- console.log( response?.data.content); // "4"
549+ // response?.data.content contains the agent's reply
550550` ` `
551551
552552### Send with file attachments
@@ -570,7 +570,7 @@ await session.send({
570570const session = await extension.resumeSession(process.env.SESSION_ID, {
571571 onPermissionRequest: async (request) => {
572572 if (request.kind === "shell") {
573- console.log( ` Shell command : ${ request .fullCommandText } ` );
573+ // request.fullCommandText has the shell command
574574 return { kind: "approved" };
575575 }
576576 if (request.kind === "write") {
@@ -589,11 +589,8 @@ Register `onUserInputRequest` to enable the agent's `ask_user` tool:
589589const session = await extension.resumeSession(process.env.SESSION_ID, {
590590 onPermissionRequest: approveAll,
591591 onUserInputRequest: async (request) => {
592- console.log(`Agent asks: ${request.question}`);
593- if (request.choices) {
594- console.log(`Options: ${request.choices.join(", ")}`);
595- }
596- // Return the user' s answer
592+ // request.question has the agent' s question
593+ // request.choices has the options (if multiple choice)
597594 return { answer: " yes" , wasFreeform: false };
598595 } ,
599596});
@@ -684,8 +681,7 @@ session.on("assistant.message", (event) => {
684681});
685682
686683session.on("tool.execution_complete", (event) => {
687- const status = event.data.success ? "✓" : "✗";
688- console.log(` [${status}] ${event .data .toolName }` );
684+ // event.data.success, event.data.toolName, event.data.result
689685});
690686` ` `
691687
0 commit comments