import { env } from "../env.js";

//#region src/types/runExecutionContext.ts
/**
* Extract userId from execution context metadata (when available)
* Only available when request originates from an authenticated user session (e.g., playground)
*/
function getUserIdFromContext(ctx) {
	const metadata = ctx.metadata;
	if (metadata?.initiatedBy?.type === "user") return metadata.initiatedBy.id;
	return metadata?.endUserId;
}
/**
* Create execution context from middleware values
*/
function createBaseExecutionContext(params) {
	return {
		apiKey: params.apiKey,
		tenantId: params.tenantId,
		projectId: params.projectId,
		agentId: params.agentId,
		baseUrl: params.baseUrl || env.INKEEP_AGENTS_API_URL,
		apiKeyId: params.apiKeyId,
		subAgentId: params.subAgentId,
		ref: params.ref,
		metadata: params.metadata || {}
	};
}

//#endregion
export { createBaseExecutionContext, getUserIdFromContext };