TangJieHao
TangJieHao
DDeno
Created by TangJieHao on 9/1/2024 in #help
WritableSteam not opening.
It looks like I may have found my solution. The reader doesn't actually know when the stream is done because its continious so I need to exit early.
async writeToStdin(data: string): Promise<void> {
const encoder = new TextEncoder();
const encoded = encoder.encode(data);
await this.stdinWriter.ready;
await this.stdinWriter.write(encoded);
}

async readFromStdout(): Promise<string> {
let buffer = "";
const decoder = new TextDecoder();
while (true) {
const { value, done } = await this.stdoutReader.read();
if (done) {
return buffer.trim();
}
buffer += decoder.decode(value, { stream: true });
console.log(buffer);

if (buffer.endsWith("\n")) {
return buffer.trim();
}
}
}
async writeToStdin(data: string): Promise<void> {
const encoder = new TextEncoder();
const encoded = encoder.encode(data);
await this.stdinWriter.ready;
await this.stdinWriter.write(encoded);
}

async readFromStdout(): Promise<string> {
let buffer = "";
const decoder = new TextDecoder();
while (true) {
const { value, done } = await this.stdoutReader.read();
if (done) {
return buffer.trim();
}
buffer += decoder.decode(value, { stream: true });
console.log(buffer);

if (buffer.endsWith("\n")) {
return buffer.trim();
}
}
}
3 replies
DDeno
Created by TangJieHao on 9/1/2024 in #help
WritableSteam not opening.
So if I put releaseLock at the end this seems to unlock the stdin however it still gives me the error that even though the stream isn't locked anymore writer wont write anymore
async writeToStdin(data: string): Promise<void> {
console.log("Writing to stdin");
const encoder = new TextEncoder();
const encoded = encoder.encode(data);
console.log(this.stdin);
const writer = await this.stdin.getWriter();
console.log(writer);
await writer.write(encoded);
writer.close();
writer.releaseLock();
}
async writeToStdin(data: string): Promise<void> {
console.log("Writing to stdin");
const encoder = new TextEncoder();
const encoded = encoder.encode(data);
console.log(this.stdin);
const writer = await this.stdin.getWriter();
console.log(writer);
await writer.write(encoded);
writer.close();
writer.releaseLock();
}
Writing to stdin
WritableStream { locked: false }
WritableStreamDefaultWriter {
closed: Promise { undefined },
desiredSize: 0,
ready: Promise { undefined }
}
error: Uncaught (in promise) TypeError: The stream is closing or is closed.
await writer.write(encoded);
Writing to stdin
WritableStream { locked: false }
WritableStreamDefaultWriter {
closed: Promise { undefined },
desiredSize: 0,
ready: Promise { undefined }
}
error: Uncaught (in promise) TypeError: The stream is closing or is closed.
await writer.write(encoded);
3 replies
DDeno
Created by TangJieHao on 9/1/2024 in #help
dwm hot reload
or how would I go about making my own?
2 replies
DDeno
Created by kindly on 8/3/2024 in #help
Vue example doesn't work out of the box
Might need to manually import types
9 replies
DDeno
Created by kindly on 8/3/2024 in #help
Vue example doesn't work out of the box
Just to make sure it was done properly did you copy and paste
deno run --allow-read --allow-write --allow-env npm:create-vite-extra@latest
deno run --allow-read --allow-write --allow-env npm:create-vite-extra@latest
9 replies
DDeno
Created by 🎀𝔸ℕ𝔾𝔼𝕃 𝔻𝕆𝕃𝕃𝔽𝔸ℂ𝔼🎀🇵🇸 on 6/28/2024 in #help
Event Loop for a bot
6 replies
DDeno
Created by 🎀𝔸ℕ𝔾𝔼𝕃 𝔻𝕆𝕃𝕃𝔽𝔸ℂ𝔼🎀🇵🇸 on 6/28/2024 in #help
Event Loop for a bot
Which I have looked deep through but it probably has what you want
6 replies
DDeno
Created by 🎀𝔸ℕ𝔾𝔼𝕃 𝔻𝕆𝕃𝕃𝔽𝔸ℂ𝔼🎀🇵🇸 on 6/28/2024 in #help
Event Loop for a bot
Only thing I could find was this: https://activitypub.software/TransFem-org/Sharkey
6 replies
DDeno
Created by TangJieHao on 6/26/2024 in #help
command.spawn() stdin and stdout
9 replies
DDeno
Created by TangJieHao on 6/26/2024 in #help
command.spawn() stdin and stdout
as for why I am concatenating the output lines is because katago returns a giant JSON text.
9 replies
DDeno
Created by TangJieHao on 6/26/2024 in #help
command.spawn() stdin and stdout
this is what I have set up as a test. and recreating the writer seems to work.
async function SubProcess() {
console.log("Starting subprocess...");
const EXE: string = "./katago/katago.exe";
const MODEL: string = "./katago/model.bin.gz";
const CONFIG: string = "./katago/config.cfg";
const command = new Deno.Command(EXE, {
args: ["analysis", "-model", MODEL, "-config", CONFIG],
stdin: "piped",
stdout: "piped",
stderr: "piped",
});

const process = command.spawn();
console.log("Subprocess spawned.");
return process;
}

async function sendQuery(process: Deno.ChildProcess, query: Query) {
console.log(`Sending query with id: ${query.id}`);
const writer = process.stdin.getWriter();
const data = new TextEncoder().encode(JSON.stringify(query) + "\n");
await writer.write(data);
writer.releaseLock();
console.log(`Query ${query.id} sent.`);
}

async function readOutput(process: Deno.ChildProcess) {
console.log("Reading output from subprocess...");
const decoder = new TextDecoder();
const reader = process.stdout.getReader();
let output = "";

try {
while (true) {
const { value, done } = await reader.read();
if (done) {
break;
}
output += decoder.decode(value, { stream: true });
// Assuming that each response from Katago ends with a newline
if (output.includes("\n")) {
break;
}
}
} catch (error) {
console.error("Error reading subprocess output: ", error);
} finally {
reader.releaseLock();
}
const AIData: AIObject = JSON.parse(output) as AIObject
return AIData;
}
async function SubProcess() {
console.log("Starting subprocess...");
const EXE: string = "./katago/katago.exe";
const MODEL: string = "./katago/model.bin.gz";
const CONFIG: string = "./katago/config.cfg";
const command = new Deno.Command(EXE, {
args: ["analysis", "-model", MODEL, "-config", CONFIG],
stdin: "piped",
stdout: "piped",
stderr: "piped",
});

const process = command.spawn();
console.log("Subprocess spawned.");
return process;
}

async function sendQuery(process: Deno.ChildProcess, query: Query) {
console.log(`Sending query with id: ${query.id}`);
const writer = process.stdin.getWriter();
const data = new TextEncoder().encode(JSON.stringify(query) + "\n");
await writer.write(data);
writer.releaseLock();
console.log(`Query ${query.id} sent.`);
}

async function readOutput(process: Deno.ChildProcess) {
console.log("Reading output from subprocess...");
const decoder = new TextDecoder();
const reader = process.stdout.getReader();
let output = "";

try {
while (true) {
const { value, done } = await reader.read();
if (done) {
break;
}
output += decoder.decode(value, { stream: true });
// Assuming that each response from Katago ends with a newline
if (output.includes("\n")) {
break;
}
}
} catch (error) {
console.error("Error reading subprocess output: ", error);
} finally {
reader.releaseLock();
}
const AIData: AIObject = JSON.parse(output) as AIObject
return AIData;
}
9 replies
DDeno
Created by TangJieHao on 6/26/2024 in #help
command.spawn() stdin and stdout
What about continuous stream? I can't seem to get any output when I want to keep the writer open.
9 replies
DDeno
Created by TangJieHao on 2/13/2024 in #help
deno command stdin, stdout continous reading
W/e the issue was. Katago doesn't exit immediately
4 replies
DDeno
Created by TangJieHao on 2/13/2024 in #help
deno command stdin, stdout continous reading
The issue for me was that the program wasn't persistent and it ended immediately. Even when I hard coded it. I got reading the stream to work.
async function readStream(stream, handler) {
const reader = stream.getReader();
try {
while (true) {
const { done, value } = await reader.read();
if (done) break;
const text = new TextDecoder().decode(value);
handler(text);
}
} catch (error) {
console.error('Stream reading error:', error);
} finally {
reader.releaseLock();
}
}
async function readStream(stream, handler) {
const reader = stream.getReader();
try {
while (true) {
const { done, value } = await reader.read();
if (done) break;
const text = new TextDecoder().decode(value);
handler(text);
}
} catch (error) {
console.error('Stream reading error:', error);
} finally {
reader.releaseLock();
}
}
And used this:
async function main() {
const cli_kata_config = await load_cli_config();
const katago = await load_kata_go(cli_kata_config);

// Setup continuous reading of stdout and stderr
readStream(katago.stdout, (text) => console.log('stdout:', text));
readStream(katago.stderr, (text) => console.error('stderr:', text));

const analysisRequest = {
//...
};
await gameAnalysis(game, katago)
await katago.stdin.close();

const status = await katago.status;
console.log('Subprocess exited with:', status.code);
}

main().catch(console.error);
async function main() {
const cli_kata_config = await load_cli_config();
const katago = await load_kata_go(cli_kata_config);

// Setup continuous reading of stdout and stderr
readStream(katago.stdout, (text) => console.log('stdout:', text));
readStream(katago.stderr, (text) => console.error('stderr:', text));

const analysisRequest = {
//...
};
await gameAnalysis(game, katago)
await katago.stdin.close();

const status = await katago.status;
console.log('Subprocess exited with:', status.code);
}

main().catch(console.error);
4 replies
DDeno
Created by TangJieHao on 1/4/2024 in #help
compile to target, 'unzip' not found.
figured out the issue, I think the cargo finished the install without protoc
5 replies
DDeno
Created by TangJieHao on 1/4/2024 in #help
compile to target, 'unzip' not found.
hmm, I can try. I installed deno using cargo. Ill try it on my windows machine as well and see if has the same issue
5 replies
DDeno
Created by TangJieHao on 1/4/2024 in #help
compile to target, 'unzip' not found.
I have done, unzip -v and I have checked which unzip also done ls -l /usr/local/bin/unzip to check where it was exactly.
5 replies