77import type { SentryContext } from "../../context.js" ;
88import { getConversationSpans } from "../../lib/api-client.js" ;
99import { buildCommand } from "../../lib/command.js" ;
10+ import { ContextError } from "../../lib/errors.js" ;
1011import {
1112 buildTranscriptResult ,
1213 formatTranscriptResult ,
@@ -19,6 +20,7 @@ import {
1920 FRESH_FLAG ,
2021} from "../../lib/list-command.js" ;
2122import { withProgress } from "../../lib/polling.js" ;
23+ import { resolveOrg } from "../../lib/resolve-target.js" ;
2224
2325type ViewFlags = {
2426 readonly json : boolean ;
@@ -43,8 +45,9 @@ export const viewCommand = buildCommand({
4345 parameters : [
4446 {
4547 placeholder : "org" ,
46- brief : "Organization slug" ,
48+ brief : "Organization slug (optional if auto-detected) " ,
4749 parse : String ,
50+ optional : true ,
4851 } ,
4952 {
5053 placeholder : "conversation-id" ,
@@ -61,12 +64,31 @@ export const viewCommand = buildCommand({
6164 async * func (
6265 this : SentryContext ,
6366 flags : ViewFlags ,
64- org : string ,
65- conversationId : string
67+ orgOrConversationId : string ,
68+ maybeConversationId ? : string
6669 ) {
6770 applyFreshFlag ( flags ) ;
71+ const { cwd } = this ;
6872
69- const spans = await withProgress (
73+ let org : string ;
74+ let conversationId : string ;
75+
76+ if ( maybeConversationId ) {
77+ org = orgOrConversationId ;
78+ conversationId = maybeConversationId ;
79+ } else {
80+ const resolved = await resolveOrg ( { cwd } ) ;
81+ if ( ! resolved ) {
82+ throw new ContextError (
83+ "Organization" ,
84+ "sentry ai-conversations view <org> <conversation-id>"
85+ ) ;
86+ }
87+ org = resolved . org ;
88+ conversationId = orgOrConversationId ;
89+ }
90+
91+ const { spans, truncated } = await withProgress (
7092 {
7193 message : "Fetching conversation spans..." ,
7294 json : flags . json ,
@@ -75,6 +97,7 @@ export const viewCommand = buildCommand({
7597 ) ;
7698
7799 const result = buildTranscriptResult ( conversationId , org , spans ) ;
100+ result . truncated = truncated ;
78101 yield new CommandOutput < TranscriptResult > ( result ) ;
79102 } ,
80103} ) ;
0 commit comments