@tenphi/akno-client 0.1.0
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 +83 -0
- package/README.md +35 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +216 -0
- package/dist/index.js.map +1 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# PolyForm Noncommercial License 1.0.0
|
|
2
|
+
|
|
3
|
+
<https://polyformproject.org/licenses/noncommercial/1.0.0>
|
|
4
|
+
|
|
5
|
+
Required Notice: Copyright 2026 Andrey Yamanov (https://github.com/tenphi/akno)
|
|
6
|
+
|
|
7
|
+
Akno is source-available, not open source. Personal and other noncommercial
|
|
8
|
+
use is free. Using it commercially — including as part of, or to operate, a
|
|
9
|
+
paid product or service — is not permitted under these terms. For a commercial
|
|
10
|
+
licence, ask.
|
|
11
|
+
|
|
12
|
+
Third-party dependencies are not covered by these terms. Each remains under
|
|
13
|
+
its own licence and the copyright of its own authors.
|
|
14
|
+
|
|
15
|
+
## Acceptance
|
|
16
|
+
|
|
17
|
+
In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
|
|
18
|
+
|
|
19
|
+
## Copyright License
|
|
20
|
+
|
|
21
|
+
The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
|
|
22
|
+
|
|
23
|
+
## Distribution License
|
|
24
|
+
|
|
25
|
+
The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
|
|
26
|
+
|
|
27
|
+
## Notices
|
|
28
|
+
|
|
29
|
+
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
|
|
30
|
+
|
|
31
|
+
> Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
|
|
32
|
+
|
|
33
|
+
## Changes and New Works License
|
|
34
|
+
|
|
35
|
+
The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
|
|
36
|
+
|
|
37
|
+
## Patent License
|
|
38
|
+
|
|
39
|
+
The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
|
|
40
|
+
|
|
41
|
+
## Noncommercial Purposes
|
|
42
|
+
|
|
43
|
+
Any noncommercial purpose is a permitted purpose.
|
|
44
|
+
|
|
45
|
+
## Personal Uses
|
|
46
|
+
|
|
47
|
+
Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, is use for a permitted purpose.
|
|
48
|
+
|
|
49
|
+
## Noncommercial Organizations
|
|
50
|
+
|
|
51
|
+
Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution is use for a permitted purpose regardless of the source of funding or obligations resulting from the funding.
|
|
52
|
+
|
|
53
|
+
## Fair Use
|
|
54
|
+
|
|
55
|
+
You may have "fair use" rights for the software under the law. These terms do not limit them.
|
|
56
|
+
|
|
57
|
+
## No Other Rights
|
|
58
|
+
|
|
59
|
+
These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
|
|
60
|
+
|
|
61
|
+
## Patent Defense
|
|
62
|
+
|
|
63
|
+
If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
64
|
+
|
|
65
|
+
## Violations
|
|
66
|
+
|
|
67
|
+
The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
|
|
68
|
+
|
|
69
|
+
## No Liability
|
|
70
|
+
|
|
71
|
+
***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
|
|
72
|
+
|
|
73
|
+
## Definitions
|
|
74
|
+
|
|
75
|
+
The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
|
|
76
|
+
|
|
77
|
+
**You** refers to the individual or entity agreeing to these terms.
|
|
78
|
+
|
|
79
|
+
**Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
80
|
+
|
|
81
|
+
**Your licenses** are all the licenses granted to you for the software under these terms.
|
|
82
|
+
|
|
83
|
+
**Use** means anything you do with the software requiring one of your licenses.
|
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# @tenphi/akno-client
|
|
2
|
+
|
|
3
|
+
A thin typed client for a running [Akno](https://github.com/tenphi/akno) service — the same interface as
|
|
4
|
+
`@tenphi/akno-core`, with **no native dependencies**.
|
|
5
|
+
|
|
6
|
+
It requires Node 22.18 or newer and is portable across operating systems.
|
|
7
|
+
|
|
8
|
+
That is the point of it. A Linux container can reach a macOS host over the loopback HTTP door, or a local
|
|
9
|
+
process can reach the Unix socket, and neither one pulls `better-sqlite3` into its build. The knowledge base
|
|
10
|
+
and the index never enter the caller's sandbox, which is also what keeps Akno's single-writer property
|
|
11
|
+
intact.
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { connect } from '@tenphi/akno-client';
|
|
15
|
+
|
|
16
|
+
const akno = await connect(); // Uses ~/.akno/akno.sock by default.
|
|
17
|
+
const result = await akno.call('recall', { query: 'car insurance renewal' });
|
|
18
|
+
|
|
19
|
+
// A host may conservatively prepare evidence before its own model handles a turn.
|
|
20
|
+
const context = await akno.context({
|
|
21
|
+
profile: 'auto_recall',
|
|
22
|
+
query: 'When does the Zephyr QX-100 warranty end?',
|
|
23
|
+
budget: 1200,
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Schemas and error codes come from
|
|
28
|
+
[`@tenphi/akno-protocol`](https://www.npmjs.com/package/@tenphi/akno-protocol), so a call that is invalid
|
|
29
|
+
here is invalid in-process too, and fails the same way.
|
|
30
|
+
|
|
31
|
+
Full documentation: [github.com/tenphi/akno](https://github.com/tenphi/akno#readme)
|
|
32
|
+
|
|
33
|
+
## License
|
|
34
|
+
|
|
35
|
+
PolyForm Noncommercial License 1.0.0 © Andrey Yamanov — noncommercial use only.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type AknoOps, type Hello as HelloMessage, type OpInput, type OpName, type OpResult } from '@tenphi/akno-protocol';
|
|
2
|
+
export { isDocumentCard, isDocumentTimelineEvidence, isPageCard, isTimelineEvent, } from '@tenphi/akno-protocol';
|
|
3
|
+
export type { DocumentCard, DocumentTimelineEvidence, PageCard, RecallResult, TimelineEvent, TimelineResult, } from '@tenphi/akno-protocol';
|
|
4
|
+
/**
|
|
5
|
+
* `@tenphi/akno-client` has the **identical interface** to the library — same
|
|
6
|
+
* ops, same schemas, generated from the same registry. Swapping `open()` for
|
|
7
|
+
* `connect()` is the only difference between embedding and connecting, so the
|
|
8
|
+
* decision is reversible and nothing above the call site knows which is in use.
|
|
9
|
+
*
|
|
10
|
+
* No native dependencies live here: sqlite-vec and the SQLite bindings never
|
|
11
|
+
* enter the host's build.
|
|
12
|
+
*/
|
|
13
|
+
export interface ConnectOptions {
|
|
14
|
+
/** Unix socket path. Defaults to `~/.akno/akno.sock`. */
|
|
15
|
+
socket?: string;
|
|
16
|
+
/** `host:port` for a loopback HTTP door instead of a socket. */
|
|
17
|
+
http?: string;
|
|
18
|
+
timeoutMs?: number;
|
|
19
|
+
/** Fail rather than warn when the server's protocol version differs. */
|
|
20
|
+
strictVersion?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Who this connection speaks for. Default `agent`, which is what the gate assumes.
|
|
23
|
+
*
|
|
24
|
+
* A host that mediates between a person and an agent needs both, and can say so per call. The
|
|
25
|
+
* distinction is not cosmetic: `user` is never gated, so a proposal the agent could not write is
|
|
26
|
+
* answered by passing `actor: 'user'` on the replay — the mechanism `akno approve` uses.
|
|
27
|
+
*/
|
|
28
|
+
actor?: 'user' | 'agent' | 'akno';
|
|
29
|
+
}
|
|
30
|
+
export interface AknoClient extends AknoOps {
|
|
31
|
+
readonly hello: HelloMessage;
|
|
32
|
+
/** `actor` overrides the connection's default for this one call. */
|
|
33
|
+
call<N extends OpName>(op: N, input: OpInput<N>, options?: {
|
|
34
|
+
actor?: 'user' | 'agent' | 'akno';
|
|
35
|
+
}): Promise<OpResult<N>>;
|
|
36
|
+
/**
|
|
37
|
+
* Ask the writer to do maintenance: `index`, `inbox`, `dream`.
|
|
38
|
+
*
|
|
39
|
+
* Not an op — the registry ops are what an agent calls about memory, and these are operator
|
|
40
|
+
* commands about the process. They exist here because exactly one process may write: with a
|
|
41
|
+
* service running, work that writes is either reachable through it or not reachable at all.
|
|
42
|
+
*/
|
|
43
|
+
command(name: string, input?: unknown): Promise<unknown>;
|
|
44
|
+
close(): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
export declare function defaultSocketPath(): string;
|
|
47
|
+
export declare function connect(options?: ConnectOptions): Promise<AknoClient>;
|
|
48
|
+
export { PROTOCOL_VERSION, AknoError } from '@tenphi/akno-protocol';
|
|
49
|
+
export type { Card, AknoOps, GraphEdgeRef, GraphInput, GraphNodeRef, GraphOutput, GraphPath, Line, OpName, RecallMode, } from '@tenphi/akno-protocol';
|
|
50
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAO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E,cAAmB,GAAG,OAAO,CAAC,UAAU,CAAC,CAI/E;AAgPD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACpE,YAAY,EACV,IAAI,EACJ,OAAO,EACP,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,WAAW,EACX,SAAS,EACT,IAAI,EACJ,MAAM,EACN,UAAU,GACX,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import net from 'node:net';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { AknoError, Hello, OP_NAMES, PROTOCOL_VERSION, createLineDecoder, encodeLine, } from '@tenphi/akno-protocol';
|
|
5
|
+
// Hosts normally import only the transport package. Re-exporting the guards here lets them
|
|
6
|
+
// consume mixed recall results without adding a second direct dependency.
|
|
7
|
+
export { isDocumentCard, isDocumentTimelineEvidence, isPageCard, isTimelineEvent, } from '@tenphi/akno-protocol';
|
|
8
|
+
export function defaultSocketPath() {
|
|
9
|
+
return process.env.AKNO_SOCKET ?? path.join(os.homedir(), '.akno', 'akno.sock');
|
|
10
|
+
}
|
|
11
|
+
export async function connect(options = {}) {
|
|
12
|
+
return options.http
|
|
13
|
+
? connectHttp(options.http, options)
|
|
14
|
+
: connectSocket(options.socket ?? defaultSocketPath(), options);
|
|
15
|
+
}
|
|
16
|
+
// ─── Unix socket ────────────────────────────────────────────────────────────
|
|
17
|
+
/**
|
|
18
|
+
* The preferred door for a host on the same machine: no port, filesystem
|
|
19
|
+
* permissions are the auth, and it is the fastest. A round trip measures 18µs
|
|
20
|
+
* against a recall budget of 300ms — five thousandths of one percent, which is
|
|
21
|
+
* why IPC cost is not a reason to embed.
|
|
22
|
+
*/
|
|
23
|
+
async function connectSocket(socketPath, options) {
|
|
24
|
+
const socket = await new Promise((resolve, reject) => {
|
|
25
|
+
const candidate = net.createConnection(socketPath);
|
|
26
|
+
const onError = (err) => {
|
|
27
|
+
candidate.destroy();
|
|
28
|
+
reject(new AknoError('unavailable', `no Akno service at ${socketPath}: ${err.message}. Start one with \`akno serve\`.`));
|
|
29
|
+
};
|
|
30
|
+
candidate.once('error', onError);
|
|
31
|
+
candidate.once('connect', () => {
|
|
32
|
+
candidate.off('error', onError);
|
|
33
|
+
resolve(candidate);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
socket.setNoDelay(true);
|
|
37
|
+
const decode = createLineDecoder();
|
|
38
|
+
const pending = new Map();
|
|
39
|
+
let helloResolve = null;
|
|
40
|
+
const helloPromise = new Promise((resolve) => {
|
|
41
|
+
helloResolve = resolve;
|
|
42
|
+
});
|
|
43
|
+
let nextId = 1;
|
|
44
|
+
let closed = false;
|
|
45
|
+
socket.setEncoding('utf8');
|
|
46
|
+
socket.on('data', (chunk) => {
|
|
47
|
+
for (const raw of decode(chunk)) {
|
|
48
|
+
let message;
|
|
49
|
+
try {
|
|
50
|
+
message = JSON.parse(raw);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const maybeHello = Hello.safeParse(message);
|
|
56
|
+
if (maybeHello.success) {
|
|
57
|
+
helloResolve?.(maybeHello.data);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const envelope = message;
|
|
61
|
+
if (typeof envelope.id !== 'number')
|
|
62
|
+
continue;
|
|
63
|
+
const waiter = pending.get(envelope.id);
|
|
64
|
+
if (!waiter)
|
|
65
|
+
continue;
|
|
66
|
+
pending.delete(envelope.id);
|
|
67
|
+
if (envelope.ok)
|
|
68
|
+
waiter.resolve(envelope.result);
|
|
69
|
+
else
|
|
70
|
+
waiter.reject(AknoError.from(envelope.error));
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
const die = (err) => {
|
|
74
|
+
closed = true;
|
|
75
|
+
for (const waiter of pending.values())
|
|
76
|
+
waiter.reject(err);
|
|
77
|
+
pending.clear();
|
|
78
|
+
};
|
|
79
|
+
socket.on('error', (err) => die(AknoError.from(err)));
|
|
80
|
+
socket.on('close', () => die(new AknoError('unavailable', 'the Akno service closed the connection')));
|
|
81
|
+
const timeoutMs = options.timeoutMs ?? 30_000;
|
|
82
|
+
const resolved = await withTimeout(helloPromise, 5000, new AknoError('unavailable', `${socketPath} accepted a connection but sent no handshake`));
|
|
83
|
+
assertVersion(resolved, options);
|
|
84
|
+
async function send(op, input, kind, actor) {
|
|
85
|
+
if (closed)
|
|
86
|
+
throw new AknoError('unavailable', 'the connection is closed');
|
|
87
|
+
const id = nextId++;
|
|
88
|
+
const promise = new Promise((resolve, reject) => {
|
|
89
|
+
pending.set(id, { resolve, reject });
|
|
90
|
+
});
|
|
91
|
+
socket.write(encodeLine({
|
|
92
|
+
id,
|
|
93
|
+
op,
|
|
94
|
+
...(kind === 'command' ? { kind } : {}),
|
|
95
|
+
input,
|
|
96
|
+
...(actor ? { actor } : {}),
|
|
97
|
+
}));
|
|
98
|
+
// A command is maintenance: reconciling a large tree or running the cycle takes minutes,
|
|
99
|
+
// where an op that slow has already failed at its job.
|
|
100
|
+
const deadline = kind === 'command' ? Math.max(timeoutMs, 15 * 60_000) : timeoutMs;
|
|
101
|
+
return withTimeout(promise, deadline, new AknoError('unavailable', `${op} did not respond within ${deadline}ms`));
|
|
102
|
+
}
|
|
103
|
+
async function call(op, input, callOptions = {}) {
|
|
104
|
+
return (await send(op, input, 'op', callOptions.actor ?? options.actor));
|
|
105
|
+
}
|
|
106
|
+
async function command(name, input) {
|
|
107
|
+
if (resolved.commands && !resolved.commands.includes(name)) {
|
|
108
|
+
throw new AknoError('not_implemented', `the service on this socket does not accept '${name}'`);
|
|
109
|
+
}
|
|
110
|
+
return send(name, input ?? {}, 'command');
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
...bindOps(call),
|
|
114
|
+
hello: resolved,
|
|
115
|
+
call,
|
|
116
|
+
command,
|
|
117
|
+
async close() {
|
|
118
|
+
closed = true;
|
|
119
|
+
await new Promise((resolve) => socket.end(() => resolve()));
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
// ─── Loopback HTTP ──────────────────────────────────────────────────────────
|
|
124
|
+
/**
|
|
125
|
+
* The HTTP door matters for containerized agents: Akno runs on the host
|
|
126
|
+
* and the agent reaches it over the network, so the knowledge base and the index
|
|
127
|
+
* never need to be mounted into a sandbox — which also keeps the single-writer
|
|
128
|
+
* property that makes WAL concurrency safe.
|
|
129
|
+
*/
|
|
130
|
+
async function connectHttp(address, options) {
|
|
131
|
+
const base = address.startsWith('http') ? address.replace(/\/+$/, '') : `http://${address}`;
|
|
132
|
+
const timeoutMs = options.timeoutMs ?? 30_000;
|
|
133
|
+
let response;
|
|
134
|
+
try {
|
|
135
|
+
response = await fetch(`${base}/hello`);
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
throw new AknoError('unavailable', `no Akno service at ${base}: ${err instanceof Error ? err.message : String(err)}`);
|
|
139
|
+
}
|
|
140
|
+
const hello = Hello.parse(await response.json());
|
|
141
|
+
assertVersion(hello, options);
|
|
142
|
+
async function call(op, input, callOptions = {}) {
|
|
143
|
+
const controller = new AbortController();
|
|
144
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
145
|
+
const actor = callOptions.actor ?? options.actor;
|
|
146
|
+
try {
|
|
147
|
+
const result = await fetch(`${base}/op/${op}`, {
|
|
148
|
+
method: 'POST',
|
|
149
|
+
headers: {
|
|
150
|
+
'content-type': 'application/json',
|
|
151
|
+
...(actor ? { 'x-akno-actor': actor } : {}),
|
|
152
|
+
},
|
|
153
|
+
body: JSON.stringify(input ?? {}),
|
|
154
|
+
signal: controller.signal,
|
|
155
|
+
});
|
|
156
|
+
const body = (await result.json());
|
|
157
|
+
if (!body.ok)
|
|
158
|
+
throw AknoError.from(body.error);
|
|
159
|
+
return body.result;
|
|
160
|
+
}
|
|
161
|
+
finally {
|
|
162
|
+
clearTimeout(timer);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
...bindOps(call),
|
|
167
|
+
hello,
|
|
168
|
+
call,
|
|
169
|
+
// Deliberately not over HTTP. That door exists so a containerized agent can reach memory;
|
|
170
|
+
// asking the host to reconcile its filesystem or run its maintenance cycle is operator
|
|
171
|
+
// work, and the socket — where filesystem permissions are the auth — is where it belongs.
|
|
172
|
+
command: async (name) => {
|
|
173
|
+
throw new AknoError('forbidden', `'${name}' is not available over the HTTP door — use the socket`);
|
|
174
|
+
},
|
|
175
|
+
close: async () => { },
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
// ─── Shared ─────────────────────────────────────────────────────────────────
|
|
179
|
+
/** Generated from the registry, so a new op needs no change in this file. */
|
|
180
|
+
function bindOps(call) {
|
|
181
|
+
const ops = {};
|
|
182
|
+
for (const name of OP_NAMES) {
|
|
183
|
+
ops[name] = (input) => call(name, input);
|
|
184
|
+
}
|
|
185
|
+
return ops;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* A version handshake on connect, with the client refusing a server it cannot
|
|
189
|
+
* speak to rather than failing subtly later.
|
|
190
|
+
*/
|
|
191
|
+
function assertVersion(hello, options) {
|
|
192
|
+
if (hello.protocol === PROTOCOL_VERSION)
|
|
193
|
+
return;
|
|
194
|
+
const detail = `client speaks protocol ${PROTOCOL_VERSION}, server speaks ${hello.protocol}`;
|
|
195
|
+
if (options.strictVersion !== false) {
|
|
196
|
+
throw new AknoError('invalid', `Akno version mismatch: ${detail}. Upgrade one of them.`);
|
|
197
|
+
}
|
|
198
|
+
process.emitWarning(`Akno version mismatch: ${detail}`);
|
|
199
|
+
}
|
|
200
|
+
async function withTimeout(promise, ms, error) {
|
|
201
|
+
let timer;
|
|
202
|
+
try {
|
|
203
|
+
return await Promise.race([
|
|
204
|
+
promise,
|
|
205
|
+
new Promise((_, reject) => {
|
|
206
|
+
timer = setTimeout(() => reject(error), ms);
|
|
207
|
+
}),
|
|
208
|
+
]);
|
|
209
|
+
}
|
|
210
|
+
finally {
|
|
211
|
+
if (timer)
|
|
212
|
+
clearTimeout(timer);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
export { PROTOCOL_VERSION, AknoError } from '@tenphi/akno-protocol';
|
|
216
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,SAAS,EACT,KAAK,EACL,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,GAMX,MAAM,uBAAuB,CAAC;AAE/B,2FAA2F;AAC3F,0EAA0E;AAC1E,OAAO,EACL,cAAc,EACd,0BAA0B,EAC1B,UAAU,EACV,eAAe,GAChB,MAAM,uBAAuB,CAAC;AAyD/B,MAAM,UAAU,iBAAiB;IAC/B,OAAO,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;AAClF,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,UAA0B,EAAE;IACxD,OAAO,OAAO,CAAC,IAAI;QACjB,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;QACpC,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,IAAI,iBAAiB,EAAE,EAAE,OAAO,CAAC,CAAC;AACpE,CAAC;AAED,+EAA+E;AAE/E;;;;;GAKG;AACH,KAAK,UAAU,aAAa,CAAC,UAAkB,EAAE,OAAuB;IACtE,MAAM,MAAM,GAAG,MAAM,IAAI,OAAO,CAAa,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC/D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U,WAAW,CAAI,OAAmB,EAAE,EAAU,EAAE,KAAY;IACzE,IAAI,KAAiC,CAAC;IACtC,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC;YACxB,OAAO;YACP,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;gBAC/B,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YAC9C,CAAC,CAAC;SACH,CAAC,CAAC;IACL,CAAC;YAAS,CAAC;QACT,IAAI,KAAK;YAAE,YAAY,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;AACH,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tenphi/akno-client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Thin typed client for a running Akno service — identical interface to @tenphi/akno-core, no native dependencies",
|
|
5
|
+
"license": "PolyForm-Noncommercial-1.0.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@tenphi/akno-protocol": "0.1.0"
|
|
20
|
+
},
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=22.18"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/tenphi/akno.git",
|
|
30
|
+
"directory": "packages/client"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/tenphi/akno#readme",
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/tenphi/akno/issues"
|
|
35
|
+
},
|
|
36
|
+
"author": "Andrey Yamanov",
|
|
37
|
+
"scripts": {}
|
|
38
|
+
}
|