diff --git a/packages/langbase/src/langbase/langbase.ts b/packages/langbase/src/langbase/langbase.ts index 3176569..b6e886f 100644 --- a/packages/langbase/src/langbase/langbase.ts +++ b/packages/langbase/src/langbase/langbase.ts @@ -640,7 +640,7 @@ export class Langbase { }; }; - public workflow: (config: {debug?: boolean; name?: string}) => Workflow; + public workflow: (config?: {debug?: boolean; name?: string}) => Workflow; public traces: { create: (trace: any) => Promise; @@ -731,7 +731,8 @@ export class Langbase { run: this.runAgent.bind(this), }; - this.workflow = config => new Workflow({...config, langbase: this}); + this.workflow = (config = {}) => + new Workflow({...config, langbase: this}); this.traces = { create: this.createTrace.bind(this), diff --git a/packages/langbase/src/langbase/workflows.ts b/packages/langbase/src/langbase/workflows.ts index 5e5640f..0212c1e 100644 --- a/packages/langbase/src/langbase/workflows.ts +++ b/packages/langbase/src/langbase/workflows.ts @@ -58,11 +58,11 @@ export class Workflow { private originalMethods: Map = new Map(); public readonly step: (config: StepConfig) => Promise; - constructor(config: WorkflowConfig) { + constructor(config?: WorkflowConfig) { this.context = {outputs: {}}; - this.debug = config.debug ?? false; - this.name = config.name ?? 'workflow'; - this.langbase = config.langbase; + this.debug = config?.debug ?? false; + this.name = config?.name ?? 'workflow'; + this.langbase = config?.langbase; // Only initialize tracing if langbase is provided if (this.langbase) { @@ -131,10 +131,11 @@ export class Workflow { // Notify collector if traceId was found if (traceId && _global._activeTraceCollector) { - if (debug) + if (debug) { console.log( `🔍 Trace ID extracted: ${traceId}`, ); + } _global._activeTraceCollector(traceId); } } @@ -391,7 +392,9 @@ export class Workflow { if (!this.langbase || !this.traceManager || !this.traceId) return; // Finalise and grab the trace this.traceManager.endTrace(this.traceId); - this.traceManager.printTrace(this.traceId); + if (this.debug) { + this.traceManager.printTrace(this.traceId); + } const traceData = this.traceManager.getTrace(this.traceId); // --- send to LB API v1/traces/create using SDK method ---