@openartifactsai/server-sdk 0.0.0-stage → 0.23.0-rc.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 +202 -0
- package/NOTICE +5 -0
- package/README.md +5 -2
- package/bin/frame-host.d.ts +2 -0
- package/bin/frame-host.js +47 -0
- package/package.json +124 -4
- package/src/child.d.ts +37 -0
- package/src/child.js +64 -0
- package/src/connectors/connectors.d.ts +101 -0
- package/src/connectors/connectors.js +256 -0
- package/src/connectors/daemon-connectors.d.ts +34 -0
- package/src/connectors/daemon-connectors.js +73 -0
- package/src/connectors/index.d.ts +7 -0
- package/src/connectors/index.js +7 -0
- package/src/connectors/mcp-client.d.ts +157 -0
- package/src/connectors/mcp-client.js +483 -0
- package/src/daemon.d.ts +119 -0
- package/src/daemon.js +301 -0
- package/src/frame/access.d.ts +69 -0
- package/src/frame/access.js +168 -0
- package/src/frame/client/comments.css +1 -0
- package/src/frame/client/comments.js +58 -0
- package/src/frame/client/imports.d.ts +6 -0
- package/src/frame/client/imports.js +112 -0
- package/src/frame/client/mcp-shell.js +345 -0
- package/src/frame/client/mcp.js +253 -0
- package/src/frame/client/runtime.js +1363 -0
- package/src/frame/client/sample.js +762 -0
- package/src/frame/client/shell.css +51 -0
- package/src/frame/client/shell.html +29 -0
- package/src/frame/client/shell.js +1417 -0
- package/src/frame/comments.d.ts +102 -0
- package/src/frame/comments.js +379 -0
- package/src/frame/core.d.ts +313 -0
- package/src/frame/core.js +1757 -0
- package/src/frame/db.d.ts +162 -0
- package/src/frame/db.js +604 -0
- package/src/frame/declaration.d.ts +30 -0
- package/src/frame/declaration.js +60 -0
- package/src/frame/env.d.ts +262 -0
- package/src/frame/env.js +13 -0
- package/src/frame/files.d.ts +130 -0
- package/src/frame/files.js +472 -0
- package/src/frame/index.d.ts +35 -0
- package/src/frame/index.js +33 -0
- package/src/frame/local.d.ts +126 -0
- package/src/frame/local.js +612 -0
- package/src/frame/mcp-relay.d.ts +79 -0
- package/src/frame/mcp-relay.js +191 -0
- package/src/frame/page-api.d.ts +48 -0
- package/src/frame/page-api.js +1 -0
- package/src/frame/page-comments.d.ts +109 -0
- package/src/frame/page-comments.js +1 -0
- package/src/frame/page-db.d.ts +88 -0
- package/src/frame/page-db.js +1 -0
- package/src/frame/page-imports.d.ts +2 -0
- package/src/frame/page-imports.js +2 -0
- package/src/frame/page-services.d.ts +124 -0
- package/src/frame/page-services.js +1 -0
- package/src/frame/page-values.d.ts +90 -0
- package/src/frame/page-values.js +1 -0
- package/src/frame/sample-relay.d.ts +42 -0
- package/src/frame/sample-relay.js +186 -0
- package/src/frame/snapshot-action.d.ts +18 -0
- package/src/frame/snapshot-action.js +82 -0
- package/src/frame/wire.d.ts +198 -0
- package/src/frame/wire.js +21 -0
- package/src/index.d.ts +17 -0
- package/src/index.js +17 -0
- package/src/lan.d.ts +75 -0
- package/src/lan.js +200 -0
- package/src/legacy-env.d.ts +7 -0
- package/src/legacy-env.js +14 -0
- package/src/serve.d.ts +375 -0
- package/src/serve.js +811 -0
- package/src/snapshot.d.ts +41 -0
- package/src/snapshot.js +224 -0
- package/src/type-package.d.ts +48 -0
- package/src/type-package.js +114 -0
- package/src/ws.d.ts +50 -0
- package/src/ws.js +203 -0
- package/src/zip.d.ts +197 -0
- package/src/zip.js +662 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The db capability's local backend: documents are JSON files at
|
|
3
|
+
* `<root>/db/<collection>/<doc>.json`, a subcollection is a folder beside its
|
|
4
|
+
* document (`db/a/b.json` and `db/a/b/c/`). Paths follow the capability's
|
|
5
|
+
* grammar; queries (where / one orderBy / limit) run over one collection's
|
|
6
|
+
* files. Leases (`acquire`) live in memory.
|
|
7
|
+
*
|
|
8
|
+
* `readDb` / `writeDb` are the agent's view (`open-artifacts.db.read` / `open-artifacts.db.write`),
|
|
9
|
+
* in the shapes the CLI libraries answer.
|
|
10
|
+
*/
|
|
11
|
+
import { EventEmitter } from 'node:events';
|
|
12
|
+
import { FrameError, type PathGuard } from './files.js';
|
|
13
|
+
import type { JsonObject } from './page-values.js';
|
|
14
|
+
export type { Json, JsonObject } from './page-values.js';
|
|
15
|
+
export declare const DB_DIR = "db";
|
|
16
|
+
export declare const DOC_MAX_BYTES: number;
|
|
17
|
+
/** Largest page of an agent's read. */
|
|
18
|
+
export declare const READ_MAX = 1000;
|
|
19
|
+
export declare const dbError: (code: string, message: string, extra?: Record<string, unknown>) => FrameError;
|
|
20
|
+
/**
|
|
21
|
+
* A document's hash for `if_match`: the sha256 (lowercase hex) of its data as
|
|
22
|
+
* compact JSON, so reformatting a file by hand does not change it.
|
|
23
|
+
*/
|
|
24
|
+
export declare function docSha256(data: unknown): string;
|
|
25
|
+
/** The fix for a `set` / `delete` over an existing document without `if_match`. */
|
|
26
|
+
export declare const IF_MATCH_FIX = "Read the document with ArtifactData {action: \"get\"} and pass its sha256 as if_match, or pass \"*\" to replace it anyway.";
|
|
27
|
+
/** A new random document id (what `add()` names a document). */
|
|
28
|
+
export declare function newDocId(): string;
|
|
29
|
+
/** Splits and checks a db path. `kind`: 'doc', 'collection' or 'any' ('' is the root, allowed for 'any' only). */
|
|
30
|
+
export declare function splitPath(p: unknown, kind?: 'doc' | 'collection' | 'any'): string[];
|
|
31
|
+
/** RFC 7386-style merge for `update`: objects merge, arrays and scalars replace, `{__delete__: true}` removes a key. */
|
|
32
|
+
export declare function mergePatch(target: unknown, patch: Record<string, unknown>): JsonObject;
|
|
33
|
+
export interface Where {
|
|
34
|
+
field: string;
|
|
35
|
+
op: string;
|
|
36
|
+
value: unknown;
|
|
37
|
+
}
|
|
38
|
+
export interface QuerySpec {
|
|
39
|
+
where: Where[];
|
|
40
|
+
orderBy: {
|
|
41
|
+
field: string;
|
|
42
|
+
dir: 'asc' | 'desc';
|
|
43
|
+
} | null;
|
|
44
|
+
limit: number | null;
|
|
45
|
+
}
|
|
46
|
+
export interface Doc {
|
|
47
|
+
id: string;
|
|
48
|
+
data: JsonObject;
|
|
49
|
+
}
|
|
50
|
+
/** Checks a query spec from a page: `{where?: [{field, op, value}], orderBy?: {field, dir}, limit?}`. */
|
|
51
|
+
export declare function checkSpec(raw?: unknown): QuerySpec;
|
|
52
|
+
export interface Lease {
|
|
53
|
+
holder: string;
|
|
54
|
+
expiresAt: number;
|
|
55
|
+
version: number;
|
|
56
|
+
}
|
|
57
|
+
export interface DbWrite {
|
|
58
|
+
op: 'set' | 'update' | 'delete' | 'str_replace';
|
|
59
|
+
path?: string;
|
|
60
|
+
collection?: string;
|
|
61
|
+
doc_id?: string;
|
|
62
|
+
data?: unknown;
|
|
63
|
+
file_path?: string;
|
|
64
|
+
/** The sha256 the writer read: write only while the document still has it. `null`: only while it does not exist. `"*"`: whatever it is now. */
|
|
65
|
+
if_match?: string | null;
|
|
66
|
+
/** `str_replace`: the field (a dot path) holding the text. */
|
|
67
|
+
field?: string;
|
|
68
|
+
/** `str_replace`: the text to find; it must occur exactly once. */
|
|
69
|
+
old?: string;
|
|
70
|
+
/** `str_replace`: what replaces it. */
|
|
71
|
+
new?: string;
|
|
72
|
+
}
|
|
73
|
+
/** Options of {@link DbStore.readDb}. */
|
|
74
|
+
export interface ReadOptions {
|
|
75
|
+
/** A query over a collection: `{where?, orderBy?, limit?}` as pages give it. */
|
|
76
|
+
query?: unknown;
|
|
77
|
+
/** Page size (1 to 1000). Default: everything. */
|
|
78
|
+
limit?: unknown;
|
|
79
|
+
/** Where a page starts: the `next_cursor` of the page before. */
|
|
80
|
+
cursor?: unknown;
|
|
81
|
+
}
|
|
82
|
+
/** Options of {@link DbStore.writeDb}. */
|
|
83
|
+
export interface WriteOptions {
|
|
84
|
+
/** Refuse a `set` or `delete` over an existing document that has no `if_match`. */
|
|
85
|
+
requireIfMatch?: boolean;
|
|
86
|
+
}
|
|
87
|
+
/** A store of one artifact's documents. Emits `change` with the doc paths a write touched. */
|
|
88
|
+
export declare class DbStore extends EventEmitter {
|
|
89
|
+
readonly root: string;
|
|
90
|
+
readonly dir: string;
|
|
91
|
+
readonly leases: Map<string, Lease>;
|
|
92
|
+
private readonly guard;
|
|
93
|
+
private readonly imports;
|
|
94
|
+
/**
|
|
95
|
+
* `guard`: how it keeps inside the artifact folder (default {@link LINK_GUARD}: links followed). `imports`: where a
|
|
96
|
+
* write's `file_path` may be read from (it checks the path, or throws); none: anywhere.
|
|
97
|
+
*/
|
|
98
|
+
constructor(root: string, options?: {
|
|
99
|
+
guard?: PathGuard;
|
|
100
|
+
imports?: {
|
|
101
|
+
resolve(path: string): string;
|
|
102
|
+
} | undefined;
|
|
103
|
+
});
|
|
104
|
+
/** The bytes of a document's file as they are on disk (history and validation compare them); throws when it has none. */
|
|
105
|
+
readDocumentFile(p: string): string;
|
|
106
|
+
/** A document's file; refused when a link (db/ itself, or a folder in it) leads it out of the artifact folder. */
|
|
107
|
+
private fileOf;
|
|
108
|
+
readDoc(p: string): JsonObject | null;
|
|
109
|
+
/** Documents of one collection, sorted by id. */
|
|
110
|
+
listCollection(p: string): Doc[];
|
|
111
|
+
query(p: string, rawSpec?: unknown): Doc[];
|
|
112
|
+
set(p: string, data: unknown): {
|
|
113
|
+
bytes: number;
|
|
114
|
+
created: boolean;
|
|
115
|
+
};
|
|
116
|
+
update(p: string, patch: unknown): {
|
|
117
|
+
bytes: number;
|
|
118
|
+
};
|
|
119
|
+
delete(p: string): {
|
|
120
|
+
existed: boolean;
|
|
121
|
+
};
|
|
122
|
+
/** A new document in `collection`, under `id` (default: a new random one, {@link newDocId}). */
|
|
123
|
+
add(collection: string, data: unknown, id?: string): {
|
|
124
|
+
id: string;
|
|
125
|
+
path: string;
|
|
126
|
+
};
|
|
127
|
+
/** A lease on a document. */
|
|
128
|
+
acquire(p: string, opts?: {
|
|
129
|
+
holder?: unknown;
|
|
130
|
+
ttlMs?: unknown;
|
|
131
|
+
data?: unknown;
|
|
132
|
+
}): {
|
|
133
|
+
acquired: boolean;
|
|
134
|
+
version?: number;
|
|
135
|
+
expiresAt?: number;
|
|
136
|
+
holder?: string;
|
|
137
|
+
};
|
|
138
|
+
release(p: string, holder: unknown): {
|
|
139
|
+
released: boolean;
|
|
140
|
+
};
|
|
141
|
+
changed(paths: string[]): void;
|
|
142
|
+
/** Every document file. */
|
|
143
|
+
listAll(): {
|
|
144
|
+
path: string;
|
|
145
|
+
bytes: number;
|
|
146
|
+
}[];
|
|
147
|
+
/**
|
|
148
|
+
* The agent's read (`open-artifacts.db.read`): the root lists every document path, a
|
|
149
|
+
* collection its documents (filtered by `query`), a document its data.
|
|
150
|
+
* Documents carry `sha256` for `if_match`; a page that stops early carries
|
|
151
|
+
* `next_cursor`.
|
|
152
|
+
*/
|
|
153
|
+
readDb(p?: unknown, opts?: ReadOptions): unknown;
|
|
154
|
+
/**
|
|
155
|
+
* The agent's batch (`open-artifacts.db.write`): every write is checked before any is
|
|
156
|
+
* made. A write with `if_match` that no longer holds fails the whole batch
|
|
157
|
+
* with `conflict`, its `current` holding what each such document is now.
|
|
158
|
+
*/
|
|
159
|
+
writeDb(writes: unknown, opts?: WriteOptions): Record<string, unknown>[];
|
|
160
|
+
}
|
|
161
|
+
/** Doc paths of the db files a watcher saw change (paths relative to the artifact folder). */
|
|
162
|
+
export declare function docPathsOf(relPaths: Iterable<string>): string[];
|