Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/next/pages/api/v2/jupyter/execute.ts
Views: 687
/*1Evaluation of code using a Jupyter kernel as a service.23The INPUT parameters are:45- kernel: the name of the Jupyter kernel6- history: list of previous inputs as string (in order) that were sent to the kernel.7- input: a new input89ALTERNATIVELY, can just give:1011- hash: hash of kernel/history/input1213and if output is known it is returned. Otherwise, nothing happens.14We are trusting that there aren't hash collisions for this applications,15since we're using a sha1 hash.1617The OUTPUT is:1819- a list of messages that describe the output of the last code execution.2021*/22import { execute } from "@cocalc/server/jupyter/execute";23import getAccountId from "lib/account/get-account";24import getParams from "lib/api/get-params";25import { analytics_cookie_name } from "@cocalc/util/misc";2627export default async function handle(req, res) {28try {29const result = await doIt(req);30res.json({ ...result, success: true });31} catch (err) {32res.json({ error: `${err.message}` });33return;34}35}3637async function doIt(req) {38const { input, kernel, history, tag, noCache, hash, project_id, path } =39getParams(req);40const account_id = await getAccountId(req);41const analytics_cookie = req.cookies[analytics_cookie_name];42return await execute({43account_id,44project_id,45path,46analytics_cookie,47input,48hash,49history,50kernel,51tag,52noCache,53});54}555657