MCPcopy Create free account
hub / github.com/ShipSecAI/studio / createExecutionContext

Function createExecutionContext

packages/component-sdk/src/context.ts:53–217  ·  view source on GitHub ↗
(options: CreateContextOptions)

Source from the content-addressed store, hash-verified

51}
52
53export function createExecutionContext(options: CreateContextOptions): ExecutionContext {
54 const { runId, componentRef, metadata: metadataInput, storage, secrets, artifacts, trace, logCollector, terminalCollector, agentTracePublisher, workflowId, workflowName, organizationId } =
55 options;
56 const metadata = createMetadata(runId, componentRef, metadataInput);
57 const scopedTrace = trace ? createScopedTrace(trace, metadata) : undefined;
58
59 const pushLog = (
60 stream: LogEventInput['stream'],
61 level: LogEventInput['level'],
62 args: unknown[],
63 ) => {
64 if (args.length === 0) {
65 return;
66 }
67 const message = format(...args);
68 if (message.length === 0) {
69 return;
70 }
71 const entry: LogEventInput = {
72 runId,
73 nodeRef: componentRef,
74 stream,
75 level,
76 message,
77 timestamp: new Date().toISOString(),
78 metadata,
79 };
80
81 if (logCollector) {
82 logCollector(entry);
83 }
84
85 if (scopedTrace) {
86 scopedTrace.record({
87 type: 'NODE_PROGRESS',
88 runId,
89 nodeRef: componentRef,
90 timestamp: entry.timestamp,
91 level: level ?? 'info',
92 message,
93 data: { stream, origin: 'log' },
94 });
95 }
96 };
97
98 const logger: Logger = Object.freeze({
99 debug: (...args: unknown[]) => {
100 pushLog('stdout', 'debug', args);
101 console.debug(`[${componentRef}]`, ...args);
102 },
103 info: (...args: unknown[]) => {
104 pushLog('stdout', 'info', args);
105 console.log(`[${componentRef}]`, ...args);
106 },
107 warn: (...args: unknown[]) => {
108 pushLog('stdout', 'warn', args);
109 console.warn(`[${componentRef}]`, ...args);
110 },

Calls 8

createHttpClientFunction · 0.90
createMetadataFunction · 0.85
createScopedTraceFunction · 0.85
pushLogFunction · 0.85
formatFunction · 0.85
debugMethod · 0.80
warnMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected