MCPcopy Create free account
hub / github.com/CommandCodeAI/BaseAI / getPipe

Function getPipe

packages/baseai/src/add/index.ts:56–103  ·  view source on GitHub ↗

* Fetches a pipe from Langbase using the provided login and name. * * @param {Object} params - The parameters for fetching the pipe. * @param {string} params.login - The login identifier. * @param {string} params.name - The name of the pipe. * @param {Spinner} params.spinner - The spinner insta

({
	login,
	name,
	spinner
}: {
	login: string;
	name: string;
	spinner: Spinner;
})

Source from the content-addressed store, hash-verified

54 * @returns {Promise<Pipe | null>} - A promise that resolves to the fetched pipe or null if an error occurs.
55 */
56async function getPipe({
57 login,
58 name,
59 spinner
60}: {
61 login: string;
62 name: string;
63 spinner: Spinner;
64}) {
65 try {
66 const account = await retrieveAuthentication({ spinner });
67 if (!account) {
68 p.log.error(
69 'Authentication failed. Please run "npx baseai auth" to authenticate.'
70 );
71 return;
72 }
73
74 spinner.start('Fetching pipe from Langbase');
75
76 const API_URL = `https://api.langbase.com/v1/pipes/${login}/${name}`;
77
78 const createResponse = await fetch(API_URL, {
79 method: 'GET',
80 headers: {
81 'Content-Type': 'application/json',
82 ...(account && { Authorization: `Bearer ${account.apiKey}` })
83 }
84 });
85
86 if (createResponse.ok) {
87 spinner.stop('Fetched pipe from Langbase');
88 return (await createResponse.json()) as Pipe;
89 }
90
91 const errorData = (await createResponse.json()) as ErrorResponse;
92
93 if (errorData) {
94 spinner.stop(
95 `Failed to fetch pipe from Langbase: ${errorData.error?.message}`
96 );
97 process.exit(1);
98 }
99 } catch (error: any) {
100 spinner.stop(error);
101 return null;
102 }
103}
104
105/**
106 * Asynchronously creates local tools based on the provided `Pipe` object.

Callers 1

addPipeFunction · 0.85

Calls 2

retrieveAuthenticationFunction · 0.90
startMethod · 0.45

Tested by

no test coverage detected