Skip to content

Commit 1c267a6

Browse files
📦 NEW: Make workflow config object (#114)
* 📦 NEW: Make workflow config object * 📦 NEW: Handle langbase.workflow --------- Co-authored-by: Ahmad Bilal <[email protected]>
1 parent 06e0b25 commit 1c267a6

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

packages/langbase/src/langbase/langbase.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ export class Langbase {
640640
};
641641
};
642642

643-
public workflow: (config: {debug?: boolean; name?: string}) => Workflow;
643+
public workflow: (config?: {debug?: boolean; name?: string}) => Workflow;
644644

645645
public traces: {
646646
create: (trace: any) => Promise<any>;
@@ -731,7 +731,8 @@ export class Langbase {
731731
run: this.runAgent.bind(this),
732732
};
733733

734-
this.workflow = config => new Workflow({...config, langbase: this});
734+
this.workflow = (config = {}) =>
735+
new Workflow({...config, langbase: this});
735736

736737
this.traces = {
737738
create: this.createTrace.bind(this),

packages/langbase/src/langbase/workflows.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ export class Workflow {
5858
private originalMethods: Map<string, Function> = new Map();
5959
public readonly step: <T = any>(config: StepConfig<T>) => Promise<T>;
6060

61-
constructor(config: WorkflowConfig) {
61+
constructor(config?: WorkflowConfig) {
6262
this.context = {outputs: {}};
63-
this.debug = config.debug ?? false;
64-
this.name = config.name ?? 'workflow';
65-
this.langbase = config.langbase;
63+
this.debug = config?.debug ?? false;
64+
this.name = config?.name ?? 'workflow';
65+
this.langbase = config?.langbase;
6666

6767
// Only initialize tracing if langbase is provided
6868
if (this.langbase) {
@@ -131,10 +131,11 @@ export class Workflow {
131131

132132
// Notify collector if traceId was found
133133
if (traceId && _global._activeTraceCollector) {
134-
if (debug)
134+
if (debug) {
135135
console.log(
136136
`🔍 Trace ID extracted: ${traceId}`,
137137
);
138+
}
138139
_global._activeTraceCollector(traceId);
139140
}
140141
}
@@ -391,7 +392,9 @@ export class Workflow {
391392
if (!this.langbase || !this.traceManager || !this.traceId) return;
392393
// Finalise and grab the trace
393394
this.traceManager.endTrace(this.traceId);
394-
this.traceManager.printTrace(this.traceId);
395+
if (this.debug) {
396+
this.traceManager.printTrace(this.traceId);
397+
}
395398
const traceData = this.traceManager.getTrace(this.traceId);
396399

397400
// --- send to LB API v1/traces/create using SDK method ---

0 commit comments

Comments
 (0)