@kana-ai/edgar-sdk 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +430 -2
- package/dist/src/build/cli.d.ts +6 -0
- package/dist/src/build/cli.js +110 -0
- package/dist/src/build/json.d.ts +2 -0
- package/dist/src/build/json.js +71 -0
- package/dist/src/build/manifest.d.ts +15 -0
- package/dist/src/build/manifest.js +111 -0
- package/dist/src/define/card-block.d.ts +15 -0
- package/dist/src/define/card-block.js +66 -0
- package/dist/src/define/context.d.ts +60 -0
- package/dist/src/define/context.js +1 -0
- package/dist/src/define/extension.d.ts +58 -0
- package/dist/src/define/extension.js +14 -0
- package/dist/src/define/hook.d.ts +61 -0
- package/dist/src/define/hook.js +72 -0
- package/dist/src/define/service.d.ts +32 -0
- package/dist/src/define/service.js +33 -0
- package/dist/src/define/tool.d.ts +93 -0
- package/dist/src/define/tool.js +24 -0
- package/dist/src/define/tracker.d.ts +59 -0
- package/dist/src/define/tracker.js +27 -0
- package/dist/src/index.d.ts +15 -0
- package/dist/src/index.js +12 -0
- package/dist/src/outcome/end.d.ts +61 -0
- package/dist/src/outcome/end.js +292 -0
- package/dist/src/outcome/failures.d.ts +15 -0
- package/dist/src/outcome/failures.js +57 -0
- package/dist/src/outcome/limits.d.ts +13 -0
- package/dist/src/outcome/limits.js +115 -0
- package/dist/src/outcome/outcome.d.ts +32 -0
- package/dist/src/outcome/outcome.js +59 -0
- package/dist/src/outcome/plain.d.ts +7 -0
- package/dist/src/outcome/plain.js +55 -0
- package/dist/src/outcome/result.d.ts +35 -0
- package/dist/src/outcome/result.js +58 -0
- package/dist/src/provider/child.d.ts +51 -0
- package/dist/src/provider/child.js +152 -0
- package/dist/src/provider/serve.d.ts +42 -0
- package/dist/src/provider/serve.js +175 -0
- package/dist/src/runtime/index.d.ts +4 -0
- package/dist/src/runtime/index.js +3 -0
- package/dist/src/runtime/invoke.d.ts +10 -0
- package/dist/src/runtime/invoke.js +232 -0
- package/dist/src/runtime/network.d.ts +20 -0
- package/dist/src/runtime/network.js +120 -0
- package/dist/src/runtime/ports.d.ts +31 -0
- package/dist/src/runtime/ports.js +1 -0
- package/dist/src/runtime/secrets.d.ts +13 -0
- package/dist/src/runtime/secrets.js +33 -0
- package/dist/src/testing/context.d.ts +12 -0
- package/dist/src/testing/context.js +39 -0
- package/dist/src/testing/index.d.ts +3 -0
- package/dist/src/testing/index.js +3 -0
- package/dist/src/testing/mock.d.ts +16 -0
- package/dist/src/testing/mock.js +39 -0
- package/dist/src/wire/codec.d.ts +46 -0
- package/dist/src/wire/codec.js +134 -0
- package/dist/src/wire/lines.d.ts +10 -0
- package/dist/src/wire/lines.js +41 -0
- package/package.json +48 -3
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Thrown when a secret is read after its call ended. */
|
|
2
|
+
export class SecretsCleared extends Error {
|
|
3
|
+
_tag = "SecretsCleared";
|
|
4
|
+
}
|
|
5
|
+
class SecretMissing extends Error {
|
|
6
|
+
_tag = "SecretMissing";
|
|
7
|
+
}
|
|
8
|
+
/** Holds a call's secrets as bytes so that `clear` can zero them. */
|
|
9
|
+
export class SecretHolder {
|
|
10
|
+
#values = new Map();
|
|
11
|
+
#cleared = false;
|
|
12
|
+
constructor(secrets) {
|
|
13
|
+
const encoder = new TextEncoder();
|
|
14
|
+
for (const [name, value] of Object.entries(secrets))
|
|
15
|
+
this.#values.set(name, encoder.encode(value));
|
|
16
|
+
}
|
|
17
|
+
bytes(name) {
|
|
18
|
+
if (this.#cleared)
|
|
19
|
+
throw new SecretsCleared(`secret ${name} was read after its call ended`);
|
|
20
|
+
const value = this.#values.get(name);
|
|
21
|
+
if (value === undefined)
|
|
22
|
+
throw new SecretMissing(`secret ${name} was not handed to this call`);
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
get(name) {
|
|
26
|
+
return new TextDecoder().decode(this.bytes(name));
|
|
27
|
+
}
|
|
28
|
+
clear() {
|
|
29
|
+
for (const value of this.#values.values())
|
|
30
|
+
value.fill(0);
|
|
31
|
+
this.#cleared = true;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Ctx } from "#define/context";
|
|
2
|
+
/** A tool or service context for unit tests: fixed ids, the given secrets, config and signal, and ports that refuse all but the given `exec`, card, move, cancel and chat answers. */
|
|
3
|
+
export declare function testContext(options?: {
|
|
4
|
+
readonly config?: unknown;
|
|
5
|
+
readonly secrets?: Readonly<Record<string, string>>;
|
|
6
|
+
readonly exec?: Ctx["sandbox"]["exec"];
|
|
7
|
+
readonly signal?: AbortSignal;
|
|
8
|
+
readonly cards?: Partial<Ctx["cards"]>;
|
|
9
|
+
readonly moves?: Partial<Ctx["moves"]>;
|
|
10
|
+
readonly cancel?: Ctx["runs"]["cancel"];
|
|
11
|
+
readonly chat?: Ctx["runs"]["chat"];
|
|
12
|
+
}): Ctx<string>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { err } from "#outcome/result";
|
|
2
|
+
import { SecretHolder } from "#runtime/secrets";
|
|
3
|
+
const refuse = () => Promise.resolve(err({ code: "engine_error", message: "not in this test" }));
|
|
4
|
+
/** A tool or service context for unit tests: fixed ids, the given secrets, config and signal, and ports that refuse all but the given `exec`, card, move, cancel and chat answers. */
|
|
5
|
+
export function testContext(options = {}) {
|
|
6
|
+
return {
|
|
7
|
+
operation_id: "7:remediate:1:3",
|
|
8
|
+
run_id: "7",
|
|
9
|
+
stage: "remediate",
|
|
10
|
+
attempt: 1,
|
|
11
|
+
signal: options.signal ?? new AbortController().signal,
|
|
12
|
+
config: options.config,
|
|
13
|
+
secrets: new SecretHolder(options.secrets ?? {}),
|
|
14
|
+
sandbox: { read: refuse, write: refuse, exec: options.exec ?? refuse },
|
|
15
|
+
tracker: {
|
|
16
|
+
list_cards: refuse,
|
|
17
|
+
card: refuse,
|
|
18
|
+
comments: refuse,
|
|
19
|
+
attachments: refuse,
|
|
20
|
+
comment: refuse,
|
|
21
|
+
move: refuse,
|
|
22
|
+
set_labels: refuse,
|
|
23
|
+
create_card: refuse,
|
|
24
|
+
close: refuse,
|
|
25
|
+
whoami: refuse,
|
|
26
|
+
person: refuse,
|
|
27
|
+
},
|
|
28
|
+
cards: { open: options.cards?.open ?? refuse, reply: options.cards?.reply ?? refuse },
|
|
29
|
+
moves: {
|
|
30
|
+
complete: options.moves?.complete ?? refuse,
|
|
31
|
+
approve: options.moves?.approve ?? refuse,
|
|
32
|
+
deny: options.moves?.deny ?? refuse,
|
|
33
|
+
},
|
|
34
|
+
runs: { read: refuse, cancel: options.cancel ?? refuse, chat: options.chat ?? refuse },
|
|
35
|
+
complete: refuse,
|
|
36
|
+
progress: () => { },
|
|
37
|
+
log: () => { },
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { MockAgent } from "undici";
|
|
2
|
+
/** One request the mock received. */
|
|
3
|
+
export interface Seen {
|
|
4
|
+
readonly method: string;
|
|
5
|
+
readonly path: string;
|
|
6
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
7
|
+
readonly body: unknown;
|
|
8
|
+
}
|
|
9
|
+
/** A mock origin that records each request and answers with the queued replies; a query matches in any order. */
|
|
10
|
+
export interface Mock {
|
|
11
|
+
readonly agent: MockAgent;
|
|
12
|
+
readonly seen: Seen[];
|
|
13
|
+
reply(method: string, path: string, status: number, data: unknown, headers?: Readonly<Record<string, string>>): void;
|
|
14
|
+
}
|
|
15
|
+
/** Installs a `MockAgent` with no real network as the global dispatcher for `origin`. */
|
|
16
|
+
export declare function mockOrigin(origin: string): Mock;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { MockAgent, setGlobalDispatcher } from "undici";
|
|
2
|
+
function same(a, b) {
|
|
3
|
+
const normal = (path) => {
|
|
4
|
+
const url = new URL(path, "http://mock");
|
|
5
|
+
url.searchParams.sort();
|
|
6
|
+
return `${url.pathname}?${url.searchParams.toString()}`;
|
|
7
|
+
};
|
|
8
|
+
return normal(a) === normal(b);
|
|
9
|
+
}
|
|
10
|
+
/** Installs a `MockAgent` with no real network as the global dispatcher for `origin`. */
|
|
11
|
+
export function mockOrigin(origin) {
|
|
12
|
+
const agent = new MockAgent();
|
|
13
|
+
agent.disableNetConnect();
|
|
14
|
+
setGlobalDispatcher(agent);
|
|
15
|
+
const seen = [];
|
|
16
|
+
return {
|
|
17
|
+
agent,
|
|
18
|
+
seen,
|
|
19
|
+
reply(method, path, status, data, headers = {}) {
|
|
20
|
+
agent
|
|
21
|
+
.get(origin)
|
|
22
|
+
.intercept({ method, path: (p) => same(p, path) })
|
|
23
|
+
.reply((opts) => {
|
|
24
|
+
const body = typeof opts.body === "string" ? JSON.parse(opts.body) : undefined;
|
|
25
|
+
seen.push({
|
|
26
|
+
method: opts.method,
|
|
27
|
+
path: opts.path,
|
|
28
|
+
headers: Object.fromEntries(new Headers(opts.headers ?? {})),
|
|
29
|
+
body,
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
statusCode: status,
|
|
33
|
+
data: JSON.stringify(data),
|
|
34
|
+
responseOptions: { headers: { "content-type": "application/json", ...headers } },
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Readable, Writable } from "node:stream";
|
|
2
|
+
import type { Contract, Id } from "@kana-ai/edgar-contracts/rpc";
|
|
3
|
+
export { type Line, readLines } from "#wire/lines";
|
|
4
|
+
/** The contract of the manifest and of both JSON-RPC protocols this SDK speaks. */
|
|
5
|
+
export declare const CONTRACT: Contract;
|
|
6
|
+
/** The engine's answers are trusted as typed: the runtime validates nothing the engine validated. */
|
|
7
|
+
export declare function trusted<T>(value: unknown): T;
|
|
8
|
+
/** The JSON-RPC error codes by name (`rpc.schema.json#/$defs/ErrorCode`). */
|
|
9
|
+
export declare const errorCodes: {
|
|
10
|
+
readonly parse_error: -32700;
|
|
11
|
+
readonly invalid_request: -32600;
|
|
12
|
+
readonly method_not_found: -32601;
|
|
13
|
+
readonly invalid_params: -32602;
|
|
14
|
+
readonly internal_error: -32603;
|
|
15
|
+
readonly runtime_payload_too_large: -32001;
|
|
16
|
+
readonly unknown_id: -32002;
|
|
17
|
+
readonly busy: -32003;
|
|
18
|
+
readonly contract_mismatch: -32004;
|
|
19
|
+
readonly capability_refused: -32010;
|
|
20
|
+
readonly sandbox_refused: -32011;
|
|
21
|
+
};
|
|
22
|
+
/** A JSON object read from a line. */
|
|
23
|
+
export type JsonObject = Readonly<Record<string, unknown>>;
|
|
24
|
+
/** The engine's answer to a request this side sent; a request over the limit, or still open when the input ends, is answered by an error here. */
|
|
25
|
+
export type Answer = {
|
|
26
|
+
readonly ok: true;
|
|
27
|
+
readonly result: unknown;
|
|
28
|
+
} | {
|
|
29
|
+
readonly ok: false;
|
|
30
|
+
readonly code: number | undefined;
|
|
31
|
+
readonly message: string;
|
|
32
|
+
};
|
|
33
|
+
/** One side of the JSON-RPC 2.0 lines with the engine: answers, notifications and requests out, requests and answers in. */
|
|
34
|
+
export interface Peer {
|
|
35
|
+
/** Writes one message; `false` when it is over the limit and was not written. */
|
|
36
|
+
send(message: JsonObject): boolean;
|
|
37
|
+
reply(id: Id | null, result: unknown): void;
|
|
38
|
+
fail(id: Id | null, code: keyof typeof errorCodes, message: string): void;
|
|
39
|
+
request(method: string, params: unknown): Promise<Answer>;
|
|
40
|
+
/** Reads `input` to its end, hands each request to `onRequest`, and returns once every request has finished. */
|
|
41
|
+
listen(input: Readable, onRequest: (id: Id, method: string, params: JsonObject) => Promise<void>): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
/** The peer that writes to `output`; an answer to an id it did not issue is logged and dropped. */
|
|
44
|
+
export declare function peer(output: Writable, log: (line: string) => void): Peer;
|
|
45
|
+
/** Answers `contract_mismatch` and returns `false` when a `hello` names a contract other than `CONTRACT`. */
|
|
46
|
+
export declare function acceptHello(rpc: Peer, id: Id, params: JsonObject): boolean;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { encode, readLines } from "#wire/lines";
|
|
2
|
+
export { readLines } from "#wire/lines";
|
|
3
|
+
/** The contract of the manifest and of both JSON-RPC protocols this SDK speaks. */
|
|
4
|
+
export const CONTRACT = 1;
|
|
5
|
+
/** The engine's answers are trusted as typed: the runtime validates nothing the engine validated. */
|
|
6
|
+
export function trusted(value) {
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
/** The JSON-RPC error codes by name (`rpc.schema.json#/$defs/ErrorCode`). */
|
|
10
|
+
export const errorCodes = {
|
|
11
|
+
parse_error: -32700,
|
|
12
|
+
invalid_request: -32600,
|
|
13
|
+
method_not_found: -32601,
|
|
14
|
+
invalid_params: -32602,
|
|
15
|
+
internal_error: -32603,
|
|
16
|
+
runtime_payload_too_large: -32001,
|
|
17
|
+
unknown_id: -32002,
|
|
18
|
+
busy: -32003,
|
|
19
|
+
contract_mismatch: -32004,
|
|
20
|
+
capability_refused: -32010,
|
|
21
|
+
sandbox_refused: -32011,
|
|
22
|
+
};
|
|
23
|
+
function isRecord(value) {
|
|
24
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25
|
+
}
|
|
26
|
+
function isId(value) {
|
|
27
|
+
return typeof value === "number" || typeof value === "string";
|
|
28
|
+
}
|
|
29
|
+
/** The peer that writes to `output`; an answer to an id it did not issue is logged and dropped. */
|
|
30
|
+
export function peer(output, log) {
|
|
31
|
+
const pending = new Map();
|
|
32
|
+
let nextId = 1;
|
|
33
|
+
let open = true;
|
|
34
|
+
const send = (message) => {
|
|
35
|
+
const line = encode(message);
|
|
36
|
+
if (line === undefined)
|
|
37
|
+
return false;
|
|
38
|
+
output.write(line);
|
|
39
|
+
return true;
|
|
40
|
+
};
|
|
41
|
+
const fail = (id, code, message) => {
|
|
42
|
+
send({ jsonrpc: "2.0", id, error: { code: errorCodes[code], message: `${code}: ${message}` } });
|
|
43
|
+
};
|
|
44
|
+
const closed = {
|
|
45
|
+
ok: false,
|
|
46
|
+
code: errorCodes.internal_error,
|
|
47
|
+
message: "internal_error: the engine closed the input",
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
send,
|
|
51
|
+
fail,
|
|
52
|
+
reply: (id, result) => {
|
|
53
|
+
if (!send({ jsonrpc: "2.0", id, result }))
|
|
54
|
+
fail(id, "runtime_payload_too_large", "the answer is over 4 MiB");
|
|
55
|
+
},
|
|
56
|
+
request: async (method, params) => {
|
|
57
|
+
if (!open)
|
|
58
|
+
return closed;
|
|
59
|
+
const id = nextId++;
|
|
60
|
+
const answer = new Promise((resolve) => pending.set(id, resolve));
|
|
61
|
+
if (!send({ jsonrpc: "2.0", id, method, params })) {
|
|
62
|
+
pending.delete(id);
|
|
63
|
+
return {
|
|
64
|
+
ok: false,
|
|
65
|
+
code: errorCodes.runtime_payload_too_large,
|
|
66
|
+
message: `runtime_payload_too_large: ${method} is over 4 MiB`,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return await answer;
|
|
70
|
+
},
|
|
71
|
+
listen: async (input, onRequest) => {
|
|
72
|
+
const tasks = new Set();
|
|
73
|
+
for await (const line of readLines(input)) {
|
|
74
|
+
if (!line.ok) {
|
|
75
|
+
if (line.error === "too_large")
|
|
76
|
+
fail(null, "runtime_payload_too_large", "a line is over 4 MiB");
|
|
77
|
+
else
|
|
78
|
+
fail(null, "parse_error", "a line is not JSON");
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const message = line.value;
|
|
82
|
+
if (!isRecord(message) || message["jsonrpc"] !== "2.0") {
|
|
83
|
+
fail(null, "invalid_request", "not a JSON-RPC 2.0 object");
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const id = message["id"];
|
|
87
|
+
const method = message["method"];
|
|
88
|
+
if (typeof method === "string" && isId(id)) {
|
|
89
|
+
const params = message["params"];
|
|
90
|
+
const task = onRequest(id, method, isRecord(params) ? params : {})
|
|
91
|
+
.catch((error) => fail(id, "internal_error", error instanceof Error ? error.message : String(error)))
|
|
92
|
+
.finally(() => tasks.delete(task));
|
|
93
|
+
tasks.add(task);
|
|
94
|
+
}
|
|
95
|
+
else if (method === undefined &&
|
|
96
|
+
isId(id) &&
|
|
97
|
+
("result" in message || "error" in message)) {
|
|
98
|
+
const resolve = pending.get(id);
|
|
99
|
+
if (resolve === undefined)
|
|
100
|
+
log(`protocol error: an answer with id ${String(id)} the runtime did not issue`);
|
|
101
|
+
else {
|
|
102
|
+
pending.delete(id);
|
|
103
|
+
resolve(answerOf(message));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
fail(isId(id) ? id : null, "invalid_request", "neither a request nor an answer");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
open = false;
|
|
111
|
+
for (const resolve of pending.values())
|
|
112
|
+
resolve(closed);
|
|
113
|
+
pending.clear();
|
|
114
|
+
await Promise.all(tasks);
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function answerOf(message) {
|
|
119
|
+
const error = message["error"];
|
|
120
|
+
if (!isRecord(error))
|
|
121
|
+
return { ok: true, result: message["result"] };
|
|
122
|
+
return {
|
|
123
|
+
ok: false,
|
|
124
|
+
code: typeof error["code"] === "number" ? error["code"] : undefined,
|
|
125
|
+
message: typeof error["message"] === "string" ? error["message"] : "the engine answered an error",
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/** Answers `contract_mismatch` and returns `false` when a `hello` names a contract other than `CONTRACT`. */
|
|
129
|
+
export function acceptHello(rpc, id, params) {
|
|
130
|
+
if (params["contract"] === CONTRACT)
|
|
131
|
+
return true;
|
|
132
|
+
rpc.fail(id, "contract_mismatch", `this runtime speaks ${CONTRACT}`);
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MaxMessageBytes } from "@kana-ai/edgar-contracts/rpc";
|
|
2
|
+
import { type Result } from "#outcome/result";
|
|
3
|
+
/** The longest line either side sends, in bytes without the newline. */
|
|
4
|
+
export declare const MAX_MESSAGE_BYTES: MaxMessageBytes;
|
|
5
|
+
/** One line read from the engine: a parsed JSON value, or why it was refused. */
|
|
6
|
+
export type Line = Result<unknown, "too_large" | "parse_error">;
|
|
7
|
+
/** Splits a byte stream into JSON lines; a line over the limit is dropped without being buffered whole. */
|
|
8
|
+
export declare function readLines(input: AsyncIterable<unknown> | Iterable<unknown>, limit?: number): AsyncGenerator<Line>;
|
|
9
|
+
/** One JSON line with its newline, or nothing when it is over the limit. */
|
|
10
|
+
export declare function encode(message: unknown, limit?: number): string | undefined;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { attempt, err } from "#outcome/result";
|
|
2
|
+
/** The longest line either side sends, in bytes without the newline. */
|
|
3
|
+
export const MAX_MESSAGE_BYTES = 4194304;
|
|
4
|
+
const NEWLINE = 0x0a;
|
|
5
|
+
/** Splits a byte stream into JSON lines; a line over the limit is dropped without being buffered whole. */
|
|
6
|
+
export async function* readLines(input, limit = MAX_MESSAGE_BYTES) {
|
|
7
|
+
let parts = [];
|
|
8
|
+
let size = 0;
|
|
9
|
+
let overflow = false;
|
|
10
|
+
for await (const raw of input) {
|
|
11
|
+
let chunk = Buffer.isBuffer(raw) ? raw : Buffer.from(String(raw));
|
|
12
|
+
for (let at = chunk.indexOf(NEWLINE); at !== -1; at = chunk.indexOf(NEWLINE)) {
|
|
13
|
+
const head = chunk.subarray(0, at);
|
|
14
|
+
chunk = chunk.subarray(at + 1);
|
|
15
|
+
if (overflow || size + head.length > limit)
|
|
16
|
+
yield err("too_large");
|
|
17
|
+
else
|
|
18
|
+
yield parse(Buffer.concat([...parts, head]));
|
|
19
|
+
parts = [];
|
|
20
|
+
size = 0;
|
|
21
|
+
overflow = false;
|
|
22
|
+
}
|
|
23
|
+
if (overflow)
|
|
24
|
+
continue;
|
|
25
|
+
size += chunk.length;
|
|
26
|
+
if (size > limit) {
|
|
27
|
+
overflow = true;
|
|
28
|
+
parts = [];
|
|
29
|
+
}
|
|
30
|
+
else if (chunk.length > 0)
|
|
31
|
+
parts.push(chunk);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function parse(bytes) {
|
|
35
|
+
return attempt(() => JSON.parse(bytes.toString("utf8")), () => "parse_error");
|
|
36
|
+
}
|
|
37
|
+
/** One JSON line with its newline, or nothing when it is over the limit. */
|
|
38
|
+
export function encode(message, limit = MAX_MESSAGE_BYTES) {
|
|
39
|
+
const text = JSON.stringify(message);
|
|
40
|
+
return Buffer.byteLength(text, "utf8") > limit ? undefined : `${text}\n`;
|
|
41
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kana-ai/edgar-sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Define EDGAR extensions: tools, a tracker, environments and hooks, and build their manifest.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/kana-ai/edgar",
|
|
9
|
+
"directory": "packages/sdk"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"edgar-extension-build": "./dist/src/build/cli.js"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist/src"
|
|
16
|
+
],
|
|
17
|
+
"type": "module",
|
|
18
|
+
"imports": {
|
|
19
|
+
"#*": "./dist/src/*.js"
|
|
20
|
+
},
|
|
21
|
+
"exports": {
|
|
22
|
+
".": "./dist/src/index.js",
|
|
23
|
+
"./runtime": "./dist/src/runtime/index.js",
|
|
24
|
+
"./codec": "./dist/src/wire/codec.js",
|
|
25
|
+
"./result": "./dist/src/outcome/result.js",
|
|
26
|
+
"./provider": "./dist/src/provider/serve.js",
|
|
27
|
+
"./child": "./dist/src/provider/child.js",
|
|
28
|
+
"./build": "./dist/src/build/manifest.js",
|
|
29
|
+
"./testing": "./dist/src/testing/index.js"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@kana-ai/edgar-contracts": "0.1.1",
|
|
33
|
+
"smol-toml": "1.9.1",
|
|
34
|
+
"undici": "7.30.2"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "24.19.2",
|
|
38
|
+
"expect-type": "1.4.0",
|
|
39
|
+
"oxfmt": "0.76.0",
|
|
40
|
+
"oxlint": "1.91.0",
|
|
41
|
+
"oxlint-tsgolint": "7.0.2005",
|
|
42
|
+
"typescript": "7.0.2",
|
|
43
|
+
"zod": "4.6.7"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"check-types": "tsc --noEmit",
|
|
47
|
+
"lint": "oxlint --type-aware --deny-warnings",
|
|
48
|
+
"format:check": "oxfmt --check",
|
|
49
|
+
"test": "node --test"
|
|
50
|
+
}
|
|
6
51
|
}
|