-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Executa): Add session parameter to execute functions
- Loading branch information
1 parent
9ba7dce
commit 7cf0513
Showing
6 changed files
with
164 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* A simple console for testing connection to, and configuration of, | ||
* executors. | ||
* | ||
* Usage: | ||
* | ||
* ```bash | ||
* ts-node console | ||
* ``` | ||
* | ||
* For full debug level log messages use: | ||
* | ||
* ```bash | ||
* ts-node console --debug | ||
* ``` | ||
* | ||
* Sends requests to execute a `CodeChunk` with `programmingLanguage: 'sh'` | ||
* to the VM and prints it's `outputs` to the console. | ||
*/ | ||
|
||
import { ClientType } from './base/Client' | ||
import { Executor } from './base/Executor' | ||
import discoverHttp from './http/discover' | ||
import HttpClient from './http/HttpClient' | ||
// import discoverTcp from './tcp/discover' | ||
// import TcpClient from './tcp/TcpClient' | ||
import WSClient from './ws/WebSocketClient' | ||
|
||
const red = '\u001b[31;1m' | ||
const blue = '\u001b[34;1m' | ||
const reset = '\u001b[0m' | ||
|
||
// @ts-ignore | ||
window.process = { | ||
// @ts-ignore | ||
emit: console.log // eslint-disable-line | ||
} | ||
|
||
// eslint-disable-next-line | ||
;(async () => { | ||
// Create executor (no need to start it, since it has no servers) | ||
const executor = new Executor( | ||
[discoverHttp], | ||
[HttpClient as ClientType, WSClient as ClientType] | ||
) | ||
|
||
const makeCodeChunk = async (text: string): Promise<string> => | ||
executor.encode({ | ||
type: 'CodeChunk', | ||
programmingLanguage: 'python', | ||
text: text | ||
}) | ||
|
||
const inputs = document.querySelector<HTMLTextAreaElement>('textarea') | ||
if (inputs === null) return | ||
|
||
inputs.addEventListener('keydown', e => { | ||
if (e.key === 'Enter' && e.shiftKey === true) { | ||
console.log() | ||
// const result = await makeCodeChunk(inputs.textContent) | ||
// window.alert(result) | ||
} | ||
}) | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import '@stencila/components' | ||
import { Executor } from '../base/Executor' | ||
import discover from '../http/discover' | ||
import { default as HttpClient } from '../http/HttpClient' | ||
import { default as WSClient } from '../ws/WebSocketClient' | ||
import { ClientType } from '../base/Client' | ||
import { codeChunk, SoftwareSession } from '@stencila/schema' | ||
|
||
const jwt = | ||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1NzE3ODA0NDd9.Q33AWdLDiJJQrWFfVkFgOT94dipKCXEzSPze0OS49C0' | ||
|
||
const discoverStub = [ | ||
async () => [ | ||
{ | ||
addresses: { | ||
ws: { | ||
type: 'ws', | ||
host: '127.0.0.1', | ||
port: '9000', | ||
jwt | ||
} | ||
}, | ||
capabilities: { | ||
execute: true | ||
} | ||
} | ||
] | ||
] | ||
|
||
// @ts-ignore | ||
const executor = new Executor(discoverStub, [ | ||
HttpClient as ClientType, | ||
WSClient as ClientType | ||
]) | ||
|
||
let sessionRef: undefined | SoftwareSession | ||
|
||
const makeCodeChunk = async (text: string): Promise<string> => { | ||
const code = codeChunk(text, { programmingLanguage: 'python' }) | ||
// @ts-ignore | ||
console.log(JSON.stringify(code, null, 2)) | ||
// TODO: Check for session, if not executor.begin().then(session => seessionRef = session; executor.execute(code, session)) | ||
// return executor.execute(code, sessionRef) | ||
return executor.execute(code) | ||
} | ||
|
||
const executeHandler = (text: string) => makeCodeChunk(text).then(console.log) | ||
|
||
const setCodeChunkProps = () => { | ||
const codeChunks = document.querySelectorAll('stencila-code-chunk') | ||
codeChunks.forEach(chunk => { | ||
// @ts-ignore | ||
chunk.executeHandler = executeHandler | ||
}) | ||
} | ||
|
||
const onReadyHandler = (): void => { | ||
setCodeChunkProps() | ||
// TODO: Store session info | ||
} | ||
|
||
export const init = (): void => { | ||
if (document.readyState === 'loading') { | ||
document.addEventListener('DOMContentLoaded', onReadyHandler) | ||
} else { | ||
onReadyHandler() | ||
} | ||
} | ||
|
||
init() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters