@milaboratories/pl-mcp-server 54.0.0 → 55.0.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/README.md +15 -25
- package/dist/_virtual/_rolldown/runtime.cjs +22 -0
- package/dist/agent-tables.cjs +116 -0
- package/dist/agent-tables.cjs.map +1 -0
- package/dist/agent-tables.js +115 -0
- package/dist/agent-tables.js.map +1 -0
- package/dist/instructions.cjs +15 -12
- package/dist/instructions.cjs.map +1 -1
- package/dist/instructions.js +15 -12
- package/dist/instructions.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/project-holds.cjs +58 -8
- package/dist/project-holds.cjs.map +1 -1
- package/dist/project-holds.js +58 -8
- package/dist/project-holds.js.map +1 -1
- package/dist/project-list.cjs +16 -0
- package/dist/project-list.cjs.map +1 -0
- package/dist/project-list.js +16 -0
- package/dist/project-list.js.map +1 -0
- package/dist/server-log.cjs +40 -18
- package/dist/server-log.cjs.map +1 -1
- package/dist/server-log.js +40 -19
- package/dist/server-log.js.map +1 -1
- package/dist/server.cjs +48 -18
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.ts +21 -20
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +48 -18
- package/dist/server.js.map +1 -1
- package/dist/tools/agent-tables.cjs +424 -0
- package/dist/tools/agent-tables.cjs.map +1 -0
- package/dist/tools/agent-tables.js +417 -0
- package/dist/tools/agent-tables.js.map +1 -0
- package/dist/tools/await.cjs +216 -73
- package/dist/tools/await.cjs.map +1 -1
- package/dist/tools/await.js +212 -75
- package/dist/tools/await.js.map +1 -1
- package/dist/tools/block-action-context.cjs +3 -0
- package/dist/tools/block-action-context.cjs.map +1 -1
- package/dist/tools/block-action-context.js +3 -0
- package/dist/tools/block-action-context.js.map +1 -1
- package/dist/tools/block-api.cjs +17 -2
- package/dist/tools/block-api.cjs.map +1 -1
- package/dist/tools/block-api.js +17 -3
- package/dist/tools/block-api.js.map +1 -1
- package/dist/tools/block-params.cjs +272 -4
- package/dist/tools/block-params.cjs.map +1 -1
- package/dist/tools/block-params.js +270 -6
- package/dist/tools/block-params.js.map +1 -1
- package/dist/tools/block-state.cjs +323 -42
- package/dist/tools/block-state.cjs.map +1 -1
- package/dist/tools/block-state.js +317 -46
- package/dist/tools/block-state.js.map +1 -1
- package/dist/tools/block-storage.cjs +153 -0
- package/dist/tools/block-storage.cjs.map +1 -0
- package/dist/tools/block-storage.js +147 -0
- package/dist/tools/block-storage.js.map +1 -0
- package/dist/tools/block-updates.cjs +405 -0
- package/dist/tools/block-updates.cjs.map +1 -0
- package/dist/tools/block-updates.js +397 -0
- package/dist/tools/block-updates.js.map +1 -0
- package/dist/tools/blocks.cjs +183 -70
- package/dist/tools/blocks.cjs.map +1 -1
- package/dist/tools/blocks.js +177 -70
- package/dist/tools/blocks.js.map +1 -1
- package/dist/tools/data-query.cjs +451 -113
- package/dist/tools/data-query.cjs.map +1 -1
- package/dist/tools/data-query.js +446 -118
- package/dist/tools/data-query.js.map +1 -1
- package/dist/tools/errors.cjs +21 -0
- package/dist/tools/errors.cjs.map +1 -0
- package/dist/tools/errors.js +20 -0
- package/dist/tools/errors.js.map +1 -0
- package/dist/tools/files.cjs +643 -0
- package/dist/tools/files.cjs.map +1 -0
- package/dist/tools/files.js +613 -0
- package/dist/tools/files.js.map +1 -0
- package/dist/tools/ids.cjs +56 -0
- package/dist/tools/ids.cjs.map +1 -1
- package/dist/tools/ids.js +51 -2
- package/dist/tools/ids.js.map +1 -1
- package/dist/tools/imports.cjs +195 -0
- package/dist/tools/imports.cjs.map +1 -0
- package/dist/tools/imports.js +186 -0
- package/dist/tools/imports.js.map +1 -0
- package/dist/tools/logs.cjs +98 -19
- package/dist/tools/logs.cjs.map +1 -1
- package/dist/tools/logs.js +95 -20
- package/dist/tools/logs.js.map +1 -1
- package/dist/tools/paging.cjs +27 -0
- package/dist/tools/paging.cjs.map +1 -0
- package/dist/tools/paging.js +26 -0
- package/dist/tools/paging.js.map +1 -0
- package/dist/tools/params-merge.cjs +106 -0
- package/dist/tools/params-merge.cjs.map +1 -0
- package/dist/tools/params-merge.js +106 -0
- package/dist/tools/params-merge.js.map +1 -0
- package/dist/tools/project-template.cjs +75 -0
- package/dist/tools/project-template.cjs.map +1 -0
- package/dist/tools/project-template.js +72 -0
- package/dist/tools/project-template.js.map +1 -0
- package/dist/tools/projects.cjs +66 -19
- package/dist/tools/projects.cjs.map +1 -1
- package/dist/tools/projects.js +66 -20
- package/dist/tools/projects.js.map +1 -1
- package/dist/tools/readiness.cjs +104 -0
- package/dist/tools/readiness.cjs.map +1 -0
- package/dist/tools/readiness.js +99 -0
- package/dist/tools/readiness.js.map +1 -0
- package/dist/tools/result-pool.cjs +260 -0
- package/dist/tools/result-pool.cjs.map +1 -0
- package/dist/tools/result-pool.js +252 -0
- package/dist/tools/result-pool.js.map +1 -0
- package/dist/tools/sandbox.cjs +112 -14
- package/dist/tools/sandbox.cjs.map +1 -1
- package/dist/tools/sandbox.js +110 -15
- package/dist/tools/sandbox.js.map +1 -1
- package/dist/tools/sdk-types.cjs +24 -0
- package/dist/tools/sdk-types.cjs.map +1 -0
- package/dist/tools/sdk-types.js +24 -0
- package/dist/tools/sdk-types.js.map +1 -0
- package/dist/tools/settle.cjs +155 -0
- package/dist/tools/settle.cjs.map +1 -0
- package/dist/tools/settle.js +148 -0
- package/dist/tools/settle.js.map +1 -0
- package/dist/tools/tokens.cjs +49 -8
- package/dist/tools/tokens.cjs.map +1 -1
- package/dist/tools/tokens.js +45 -9
- package/dist/tools/tokens.js.map +1 -1
- package/dist/tools/types.cjs +62 -11
- package/dist/tools/types.cjs.map +1 -1
- package/dist/tools/types.js +60 -12
- package/dist/tools/types.js.map +1 -1
- package/dist/tools/value-outline.cjs +119 -0
- package/dist/tools/value-outline.cjs.map +1 -0
- package/dist/tools/value-outline.js +117 -0
- package/dist/tools/value-outline.js.map +1 -0
- package/package.json +9 -8
- package/src/agent-tables.test.ts +246 -0
- package/src/agent-tables.ts +145 -0
- package/src/instructions.ts +15 -12
- package/src/project-holds.test.ts +179 -0
- package/src/project-holds.ts +114 -12
- package/src/project-list.test.ts +38 -0
- package/src/project-list.ts +25 -0
- package/src/server-log.test.ts +54 -1
- package/src/server-log.ts +49 -27
- package/src/server.logging.test.ts +38 -46
- package/src/server.test.ts +151 -17
- package/src/server.ts +62 -34
- package/src/tools/agent-tables.test.ts +650 -0
- package/src/tools/agent-tables.ts +673 -0
- package/src/tools/await.test.ts +287 -0
- package/src/tools/await.ts +393 -123
- package/src/tools/block-action-context.ts +3 -0
- package/src/tools/block-api.ts +19 -4
- package/src/tools/block-params.test.ts +828 -0
- package/src/tools/block-params.ts +623 -8
- package/src/tools/block-state.test.ts +480 -0
- package/src/tools/block-state.ts +659 -66
- package/src/tools/block-storage.test.ts +270 -0
- package/src/tools/block-storage.ts +195 -0
- package/src/tools/block-updates.test.ts +605 -0
- package/src/tools/block-updates.ts +751 -0
- package/src/tools/blocks.test.ts +169 -22
- package/src/tools/blocks.ts +336 -105
- package/src/tools/data-query.test.ts +641 -0
- package/src/tools/data-query.ts +807 -157
- package/src/tools/errors.test.ts +33 -0
- package/src/tools/errors.ts +23 -0
- package/src/tools/files.test.ts +842 -0
- package/src/tools/files.ts +990 -0
- package/src/tools/ids.test.ts +87 -0
- package/src/tools/ids.ts +67 -0
- package/src/tools/imports.ts +304 -0
- package/src/tools/logs.test.ts +70 -0
- package/src/tools/logs.ts +130 -21
- package/src/tools/paging.test.ts +39 -0
- package/src/tools/paging.ts +39 -0
- package/src/tools/params-merge.test.ts +274 -0
- package/src/tools/params-merge.ts +149 -0
- package/src/tools/project-template.test.ts +230 -0
- package/src/tools/project-template.ts +135 -0
- package/src/tools/projects.test.ts +122 -0
- package/src/tools/projects.ts +135 -25
- package/src/tools/readiness.test.ts +195 -0
- package/src/tools/readiness.ts +189 -0
- package/src/tools/result-pool.test.ts +377 -0
- package/src/tools/result-pool.ts +483 -0
- package/src/tools/sandbox.test.ts +128 -10
- package/src/tools/sandbox.ts +132 -18
- package/src/tools/sdk-types.ts +54 -0
- package/src/tools/settle.test.ts +340 -0
- package/src/tools/settle.ts +312 -0
- package/src/tools/tokens.ts +74 -9
- package/src/tools/types.ts +77 -12
- package/src/tools/value-outline.ts +143 -0
- package/dist/tools/screenshot.cjs +0 -44
- package/dist/tools/screenshot.cjs.map +0 -1
- package/dist/tools/screenshot.js +0 -44
- package/dist/tools/screenshot.js.map +0 -1
- package/dist/tools/ui-interaction.cjs +0 -140
- package/dist/tools/ui-interaction.cjs.map +0 -1
- package/dist/tools/ui-interaction.js +0 -140
- package/dist/tools/ui-interaction.js.map +0 -1
- package/src/tools/screenshot.ts +0 -61
- package/src/tools/ui-interaction.ts +0 -184
package/README.md
CHANGED
|
@@ -1,42 +1,38 @@
|
|
|
1
1
|
# Platforma MCP Server
|
|
2
2
|
|
|
3
|
-
MCP (Model Context Protocol) server that enables AI assistants to interact with the Platforma Desktop App. It exposes tools for project management, block control
|
|
3
|
+
MCP (Model Context Protocol) server that enables AI assistants to interact with the Platforma Desktop App. It exposes tools for project management, block control and data queries through the standardized MCP interface. It does not drive the application window: no screenshots, clicks, typing or JavaScript in the renderer. `select_block` only shows a block to the user.
|
|
4
4
|
|
|
5
5
|
## Capabilities
|
|
6
6
|
|
|
7
|
-
| Tool group
|
|
8
|
-
|
|
|
9
|
-
| **Connection**
|
|
10
|
-
| **Projects**
|
|
11
|
-
| **Blocks**
|
|
12
|
-
| **
|
|
13
|
-
| **
|
|
14
|
-
| **Data query** | Query PColumn data and result pool contents |
|
|
15
|
-
| **Logs** | Retrieve application logs |
|
|
16
|
-
| **Sandbox** | Execute JavaScript in the app's renderer process |
|
|
7
|
+
| Tool group | What it does |
|
|
8
|
+
| -------------- | -------------------------------------------------------- |
|
|
9
|
+
| **Connection** | Connect/disconnect to a running Platforma backend server |
|
|
10
|
+
| **Projects** | List, open, and manage projects |
|
|
11
|
+
| **Blocks** | Add blocks, read block state, configure inputs/arguments |
|
|
12
|
+
| **Data query** | Query PColumn data and result pool contents |
|
|
13
|
+
| **Logs** | Retrieve application logs |
|
|
17
14
|
|
|
18
15
|
## How It Works
|
|
19
16
|
|
|
20
|
-
The MCP server runs
|
|
17
|
+
The MCP server runs in the worker process of the Platforma Desktop App (Electron), next to the middle layer, and serves MCP over Streamable HTTP on `127.0.0.1` at a secret path (protocol revision 2026-07-28; 2025-era clients are served statelessly). Projects are reached through the middle layer, shared with the app's tabs; for what the app owns (connections, block listing, the app log, showing a block) the server calls callbacks the app provides.
|
|
21
18
|
|
|
22
19
|
```
|
|
23
|
-
Claude Code ──MCP──▶ pl-mcp-server (worker)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
└── Modals
|
|
20
|
+
Claude Code ──MCP over HTTP──▶ pl-mcp-server (worker) ──▶ middle layer ──▶ Platforma backend
|
|
21
|
+
│
|
|
22
|
+
└──callbacks──▶ Desktop App: connections, block listing, app log, select_block
|
|
27
23
|
```
|
|
28
24
|
|
|
29
25
|
## Connecting From Claude Code
|
|
30
26
|
|
|
31
27
|
1. **Start the Platforma Desktop App and enable MCP** — the MCP server feature marked as Alpha for now. To enable it open Settings, scroll down to the bottom, enable checkbox "Enable MCP Server". Then copy MCP Server URL.
|
|
32
28
|
|
|
33
|
-
2. **Add the MCP server to Claude Code**
|
|
29
|
+
2. **Add the MCP server to Claude Code** with `claude mcp add --transport http pl <MCP Server URL>`, or in `.mcp.json` at the project root (keep the URL's token out of version control):
|
|
34
30
|
|
|
35
31
|
```json
|
|
36
32
|
{
|
|
37
33
|
"mcpServers": {
|
|
38
34
|
"pl": {
|
|
39
|
-
"type": "
|
|
35
|
+
"type": "http",
|
|
40
36
|
"url": "http://127.0.0.1:4200/<!!CHANGE ME!!>/mcp"
|
|
41
37
|
}
|
|
42
38
|
}
|
|
@@ -76,12 +72,6 @@ Claude Desktop App uses stdio transport, so it cannot connect to the HTTP MCP en
|
|
|
76
72
|
|
|
77
73
|
There is a `mcp-desktop-testing` skill for Claude in ecosystem overlay. Should be found and used automatically if overlay enabled.
|
|
78
74
|
|
|
79
|
-
## Coordinate System
|
|
80
|
-
|
|
81
|
-
The desktop app uses Electron with potentially multiple WebContents layers. Screenshots are captured in **device pixels** (2x on Retina displays), while input events use **CSS pixels**.
|
|
82
|
-
|
|
83
|
-
To click on an element visible in a screenshot: divide the screenshot pixel coordinates by the device pixel ratio (typically 2 on macOS Retina).
|
|
84
|
-
|
|
85
75
|
## Log
|
|
86
76
|
|
|
87
77
|
Give the server a logger (`PlMcpServerOptions.logger`, the `MiLogger` of the middle layer) and it writes what it does; without one it writes nothing. Every entry is one string that starts with its kind and continues with `key=value` fields; a value that is not a plain token is written as a JSON string.
|
|
@@ -105,7 +95,7 @@ mcp-call call=mcp-1a2b3c4d#57 tool=set_block_data project=NG:0x35B1EB block=0b6d
|
|
|
105
95
|
- `call`: the id of the server instance (also the author id of the writes it makes) and the number of the call. The other lines about the same call carry the same id.
|
|
106
96
|
- `project`, `block`: the `projectId` and `blockId` arguments, when the call has them.
|
|
107
97
|
- `argsBytes`: the size of the arguments as JSON, in bytes.
|
|
108
|
-
- `resultBytes`: the size of the content of the result: the UTF-8 bytes of its texts plus the length of its base64 data (
|
|
98
|
+
- `resultBytes`: the size of the content of the result: the UTF-8 bytes of its texts plus the length of its base64 data (binary resources). The JSON around the content is not counted. 0 when the handler threw.
|
|
109
99
|
- `outcome`: `ok`, `error` (the handler returned `isError: true`) or `thrown`.
|
|
110
100
|
- `inflight`: other calls that were being served when this one started.
|
|
111
101
|
- `txConflictsDuring`: commit conflicts of the backend client between the start and the end of the call. The client counts them for all its work, so calls in flight at the same time report the same conflicts. Absent without a backend.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
exports.__toESM = __toESM;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
const require_project_holds = require("./project-holds.cjs");
|
|
2
|
+
// src/agent-tables.ts
|
|
3
|
+
/**
|
|
4
|
+
* The tables agents built with `create_table`, by handle.
|
|
5
|
+
*
|
|
6
|
+
* A table is given back (its computable reset, which releases the driver's reference) at the
|
|
7
|
+
* earliest of: {@link drop}; {@link AgentTablesOptions.idleMs} after it was built or last used;
|
|
8
|
+
* {@link releaseProject} of its project, when the server lets go of it; {@link releaseAll}; or
|
|
9
|
+
* when more than {@link AgentTablesOptions.maxTables} are open and it is the least recently used.
|
|
10
|
+
* A read of a table that went meanwhile fails as a read of any stale handle does.
|
|
11
|
+
*
|
|
12
|
+
* The same definition over the same data gives the same handle: building it again replaces the
|
|
13
|
+
* entry, and the newer reference is in place before the older one is given back.
|
|
14
|
+
*/
|
|
15
|
+
var AgentTables = class {
|
|
16
|
+
options;
|
|
17
|
+
/** The open tables; the map's order is the order of use, oldest first. */
|
|
18
|
+
open = /* @__PURE__ */ new Map();
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.options = options;
|
|
21
|
+
}
|
|
22
|
+
/** How many tables are open. */
|
|
23
|
+
get size() {
|
|
24
|
+
return this.open.size;
|
|
25
|
+
}
|
|
26
|
+
/** The idle time of a table, in whole seconds. */
|
|
27
|
+
get expiresInSec() {
|
|
28
|
+
return Math.round(this.options.idleMs / 1e3);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Keeps `table`, built over project `projectId`, under `handle`. Gives the handles of the tables
|
|
32
|
+
* let go to stay within the cap.
|
|
33
|
+
*/
|
|
34
|
+
add(projectId, handle, table) {
|
|
35
|
+
const previous = this.open.get(handle);
|
|
36
|
+
const entry = {
|
|
37
|
+
projectId,
|
|
38
|
+
table,
|
|
39
|
+
timer: setTimeout(() => this.release(handle, entry), this.options.idleMs)
|
|
40
|
+
};
|
|
41
|
+
entry.timer.unref();
|
|
42
|
+
this.open.delete(handle);
|
|
43
|
+
this.open.set(handle, entry);
|
|
44
|
+
if (previous !== void 0) {
|
|
45
|
+
clearTimeout(previous.timer);
|
|
46
|
+
previous.table.resetState();
|
|
47
|
+
}
|
|
48
|
+
const evicted = [];
|
|
49
|
+
for (const [oldest, old] of this.open) {
|
|
50
|
+
if (this.open.size <= this.options.maxTables) break;
|
|
51
|
+
evicted.push(oldest);
|
|
52
|
+
this.release(oldest, old);
|
|
53
|
+
}
|
|
54
|
+
return evicted;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The table under `handle`, counted as used: its idle time starts again. `stale`: what it was
|
|
58
|
+
* built from may have changed. `undefined` when no such table is open.
|
|
59
|
+
*/
|
|
60
|
+
use(handle) {
|
|
61
|
+
const entry = this.open.get(handle);
|
|
62
|
+
if (entry === void 0) return void 0;
|
|
63
|
+
entry.timer.refresh();
|
|
64
|
+
this.open.delete(handle);
|
|
65
|
+
this.open.set(handle, entry);
|
|
66
|
+
return {
|
|
67
|
+
projectId: entry.projectId,
|
|
68
|
+
stale: entry.table.isChanged()
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** Gives back the table under `handle`. False when no such table is open. */
|
|
72
|
+
drop(handle) {
|
|
73
|
+
const entry = this.open.get(handle);
|
|
74
|
+
if (entry === void 0) return false;
|
|
75
|
+
this.release(handle, entry);
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
/** Gives back every table built over `projectId`. */
|
|
79
|
+
releaseProject(projectId) {
|
|
80
|
+
for (const [handle, entry] of this.open) if (entry.projectId === projectId) this.release(handle, entry);
|
|
81
|
+
}
|
|
82
|
+
/** Gives back every table. */
|
|
83
|
+
releaseAll() {
|
|
84
|
+
for (const [handle, entry] of this.open) this.release(handle, entry);
|
|
85
|
+
}
|
|
86
|
+
release(handle, entry) {
|
|
87
|
+
if (this.open.get(handle) !== entry) return;
|
|
88
|
+
clearTimeout(entry.timer);
|
|
89
|
+
this.open.delete(handle);
|
|
90
|
+
entry.table.resetState();
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* The server's holds on projects, wired to its agent tables: the tables built over a project go
|
|
95
|
+
* when the server's kept hold on it is given back or ended, but not while a call on the project is
|
|
96
|
+
* still running. Such a call ends by keeping the project again ({@link ProjectHolds}), and the
|
|
97
|
+
* release of that hold lets the tables go then.
|
|
98
|
+
*/
|
|
99
|
+
function projectHoldsWithTables(tables, options) {
|
|
100
|
+
const holds = new require_project_holds.ProjectHolds({
|
|
101
|
+
...options,
|
|
102
|
+
onRelease: (projectId, reason) => {
|
|
103
|
+
if (holds.callsInFlight(projectId) === 0) tables.releaseProject(projectId);
|
|
104
|
+
options.onRelease?.(projectId, reason);
|
|
105
|
+
},
|
|
106
|
+
onEnded: (projectId) => {
|
|
107
|
+
tables.releaseProject(projectId);
|
|
108
|
+
options.onEnded?.(projectId);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
return holds;
|
|
112
|
+
}
|
|
113
|
+
exports.AgentTables = AgentTables;
|
|
114
|
+
exports.projectHoldsWithTables = projectHoldsWithTables;
|
|
115
|
+
|
|
116
|
+
//# sourceMappingURL=agent-tables.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-tables.cjs","names":["ProjectHolds"],"sources":["../src/agent-tables.ts"],"sourcesContent":["import type { PTableHandle, ProjectId } from \"@milaboratories/pl-model-common\";\nimport { ProjectHolds, type ProjectHoldsOptions } from \"./project-holds\";\n\n/**\n * What the server keeps of a table an agent built: the computable that holds the driver's\n * reference to it (the middle layer's `Project.createPoolTable`).\n */\nexport interface HeldTable {\n /** Gives the driver's reference back. */\n resetState(): void;\n /** Whether what the table was built from may have changed since it was built. */\n isChanged(): boolean;\n}\n\nexport interface AgentTablesOptions {\n /** How long a table is kept after it was built or last read. */\n idleMs: number;\n /** How many tables are kept; the least recently used goes when one more is added. */\n maxTables: number;\n}\n\ntype Entry = {\n readonly projectId: ProjectId;\n readonly table: HeldTable;\n readonly timer: NodeJS.Timeout;\n};\n\n/**\n * The tables agents built with `create_table`, by handle.\n *\n * A table is given back (its computable reset, which releases the driver's reference) at the\n * earliest of: {@link drop}; {@link AgentTablesOptions.idleMs} after it was built or last used;\n * {@link releaseProject} of its project, when the server lets go of it; {@link releaseAll}; or\n * when more than {@link AgentTablesOptions.maxTables} are open and it is the least recently used.\n * A read of a table that went meanwhile fails as a read of any stale handle does.\n *\n * The same definition over the same data gives the same handle: building it again replaces the\n * entry, and the newer reference is in place before the older one is given back.\n */\nexport class AgentTables {\n /** The open tables; the map's order is the order of use, oldest first. */\n private readonly open = new Map<PTableHandle, Entry>();\n\n constructor(private readonly options: AgentTablesOptions) {}\n\n /** How many tables are open. */\n get size(): number {\n return this.open.size;\n }\n\n /** The idle time of a table, in whole seconds. */\n get expiresInSec(): number {\n return Math.round(this.options.idleMs / 1000);\n }\n\n /**\n * Keeps `table`, built over project `projectId`, under `handle`. Gives the handles of the tables\n * let go to stay within the cap.\n */\n add(projectId: ProjectId, handle: PTableHandle, table: HeldTable): PTableHandle[] {\n const previous = this.open.get(handle);\n const entry: Entry = {\n projectId,\n table,\n timer: setTimeout(() => this.release(handle, entry), this.options.idleMs),\n };\n entry.timer.unref();\n this.open.delete(handle);\n this.open.set(handle, entry);\n if (previous !== undefined) {\n clearTimeout(previous.timer);\n previous.table.resetState();\n }\n const evicted: PTableHandle[] = [];\n for (const [oldest, old] of this.open) {\n if (this.open.size <= this.options.maxTables) break;\n evicted.push(oldest);\n this.release(oldest, old);\n }\n return evicted;\n }\n\n /**\n * The table under `handle`, counted as used: its idle time starts again. `stale`: what it was\n * built from may have changed. `undefined` when no such table is open.\n */\n use(handle: PTableHandle): { projectId: ProjectId; stale: boolean } | undefined {\n const entry = this.open.get(handle);\n if (entry === undefined) return undefined;\n entry.timer.refresh();\n this.open.delete(handle);\n this.open.set(handle, entry);\n return { projectId: entry.projectId, stale: entry.table.isChanged() };\n }\n\n /** Gives back the table under `handle`. False when no such table is open. */\n drop(handle: PTableHandle): boolean {\n const entry = this.open.get(handle);\n if (entry === undefined) return false;\n this.release(handle, entry);\n return true;\n }\n\n /** Gives back every table built over `projectId`. */\n releaseProject(projectId: ProjectId): void {\n for (const [handle, entry] of this.open)\n if (entry.projectId === projectId) this.release(handle, entry);\n }\n\n /** Gives back every table. */\n releaseAll(): void {\n for (const [handle, entry] of this.open) this.release(handle, entry);\n }\n\n private release(handle: PTableHandle, entry: Entry): void {\n if (this.open.get(handle) !== entry) return;\n clearTimeout(entry.timer);\n this.open.delete(handle);\n entry.table.resetState();\n }\n}\n\n/**\n * The server's holds on projects, wired to its agent tables: the tables built over a project go\n * when the server's kept hold on it is given back or ended, but not while a call on the project is\n * still running. Such a call ends by keeping the project again ({@link ProjectHolds}), and the\n * release of that hold lets the tables go then.\n */\nexport function projectHoldsWithTables<P>(\n tables: AgentTables,\n options: ProjectHoldsOptions<P>,\n): ProjectHolds<P> {\n const holds: ProjectHolds<P> = new ProjectHolds<P>({\n ...options,\n onRelease: (projectId, reason) => {\n if (holds.callsInFlight(projectId) === 0) tables.releaseProject(projectId);\n options.onRelease?.(projectId, reason);\n },\n onEnded: (projectId) => {\n tables.releaseProject(projectId);\n options.onEnded?.(projectId);\n },\n });\n return holds;\n}\n"],"mappings":";;;;;;;;;;;;;;AAuCA,IAAa,cAAb,MAAyB;CAIM;;CAF7B,uBAAwB,IAAI,IAAyB;CAErD,YAAY,SAA8C;EAA7B,KAAA,UAAA;CAA8B;;CAG3D,IAAI,OAAe;EACjB,OAAO,KAAK,KAAK;CACnB;;CAGA,IAAI,eAAuB;EACzB,OAAO,KAAK,MAAM,KAAK,QAAQ,SAAS,GAAI;CAC9C;;;;;CAMA,IAAI,WAAsB,QAAsB,OAAkC;EAChF,MAAM,WAAW,KAAK,KAAK,IAAI,MAAM;EACrC,MAAM,QAAe;GACnB;GACA;GACA,OAAO,iBAAiB,KAAK,QAAQ,QAAQ,KAAK,GAAG,KAAK,QAAQ,MAAM;EAC1E;EACA,MAAM,MAAM,MAAM;EAClB,KAAK,KAAK,OAAO,MAAM;EACvB,KAAK,KAAK,IAAI,QAAQ,KAAK;EAC3B,IAAI,aAAa,KAAA,GAAW;GAC1B,aAAa,SAAS,KAAK;GAC3B,SAAS,MAAM,WAAW;EAC5B;EACA,MAAM,UAA0B,CAAC;EACjC,KAAK,MAAM,CAAC,QAAQ,QAAQ,KAAK,MAAM;GACrC,IAAI,KAAK,KAAK,QAAQ,KAAK,QAAQ,WAAW;GAC9C,QAAQ,KAAK,MAAM;GACnB,KAAK,QAAQ,QAAQ,GAAG;EAC1B;EACA,OAAO;CACT;;;;;CAMA,IAAI,QAA4E;EAC9E,MAAM,QAAQ,KAAK,KAAK,IAAI,MAAM;EAClC,IAAI,UAAU,KAAA,GAAW,OAAO,KAAA;EAChC,MAAM,MAAM,QAAQ;EACpB,KAAK,KAAK,OAAO,MAAM;EACvB,KAAK,KAAK,IAAI,QAAQ,KAAK;EAC3B,OAAO;GAAE,WAAW,MAAM;GAAW,OAAO,MAAM,MAAM,UAAU;EAAE;CACtE;;CAGA,KAAK,QAA+B;EAClC,MAAM,QAAQ,KAAK,KAAK,IAAI,MAAM;EAClC,IAAI,UAAU,KAAA,GAAW,OAAO;EAChC,KAAK,QAAQ,QAAQ,KAAK;EAC1B,OAAO;CACT;;CAGA,eAAe,WAA4B;EACzC,KAAK,MAAM,CAAC,QAAQ,UAAU,KAAK,MACjC,IAAI,MAAM,cAAc,WAAW,KAAK,QAAQ,QAAQ,KAAK;CACjE;;CAGA,aAAmB;EACjB,KAAK,MAAM,CAAC,QAAQ,UAAU,KAAK,MAAM,KAAK,QAAQ,QAAQ,KAAK;CACrE;CAEA,QAAgB,QAAsB,OAAoB;EACxD,IAAI,KAAK,KAAK,IAAI,MAAM,MAAM,OAAO;EACrC,aAAa,MAAM,KAAK;EACxB,KAAK,KAAK,OAAO,MAAM;EACvB,MAAM,MAAM,WAAW;CACzB;AACF;;;;;;;AAQA,SAAgB,uBACd,QACA,SACiB;CACjB,MAAM,QAAyB,IAAIA,sBAAAA,aAAgB;EACjD,GAAG;EACH,YAAY,WAAW,WAAW;GAChC,IAAI,MAAM,cAAc,SAAS,MAAM,GAAG,OAAO,eAAe,SAAS;GACzE,QAAQ,YAAY,WAAW,MAAM;EACvC;EACA,UAAU,cAAc;GACtB,OAAO,eAAe,SAAS;GAC/B,QAAQ,UAAU,SAAS;EAC7B;CACF,CAAC;CACD,OAAO;AACT"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { ProjectHolds } from "./project-holds.js";
|
|
2
|
+
// src/agent-tables.ts
|
|
3
|
+
/**
|
|
4
|
+
* The tables agents built with `create_table`, by handle.
|
|
5
|
+
*
|
|
6
|
+
* A table is given back (its computable reset, which releases the driver's reference) at the
|
|
7
|
+
* earliest of: {@link drop}; {@link AgentTablesOptions.idleMs} after it was built or last used;
|
|
8
|
+
* {@link releaseProject} of its project, when the server lets go of it; {@link releaseAll}; or
|
|
9
|
+
* when more than {@link AgentTablesOptions.maxTables} are open and it is the least recently used.
|
|
10
|
+
* A read of a table that went meanwhile fails as a read of any stale handle does.
|
|
11
|
+
*
|
|
12
|
+
* The same definition over the same data gives the same handle: building it again replaces the
|
|
13
|
+
* entry, and the newer reference is in place before the older one is given back.
|
|
14
|
+
*/
|
|
15
|
+
var AgentTables = class {
|
|
16
|
+
options;
|
|
17
|
+
/** The open tables; the map's order is the order of use, oldest first. */
|
|
18
|
+
open = /* @__PURE__ */ new Map();
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.options = options;
|
|
21
|
+
}
|
|
22
|
+
/** How many tables are open. */
|
|
23
|
+
get size() {
|
|
24
|
+
return this.open.size;
|
|
25
|
+
}
|
|
26
|
+
/** The idle time of a table, in whole seconds. */
|
|
27
|
+
get expiresInSec() {
|
|
28
|
+
return Math.round(this.options.idleMs / 1e3);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Keeps `table`, built over project `projectId`, under `handle`. Gives the handles of the tables
|
|
32
|
+
* let go to stay within the cap.
|
|
33
|
+
*/
|
|
34
|
+
add(projectId, handle, table) {
|
|
35
|
+
const previous = this.open.get(handle);
|
|
36
|
+
const entry = {
|
|
37
|
+
projectId,
|
|
38
|
+
table,
|
|
39
|
+
timer: setTimeout(() => this.release(handle, entry), this.options.idleMs)
|
|
40
|
+
};
|
|
41
|
+
entry.timer.unref();
|
|
42
|
+
this.open.delete(handle);
|
|
43
|
+
this.open.set(handle, entry);
|
|
44
|
+
if (previous !== void 0) {
|
|
45
|
+
clearTimeout(previous.timer);
|
|
46
|
+
previous.table.resetState();
|
|
47
|
+
}
|
|
48
|
+
const evicted = [];
|
|
49
|
+
for (const [oldest, old] of this.open) {
|
|
50
|
+
if (this.open.size <= this.options.maxTables) break;
|
|
51
|
+
evicted.push(oldest);
|
|
52
|
+
this.release(oldest, old);
|
|
53
|
+
}
|
|
54
|
+
return evicted;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The table under `handle`, counted as used: its idle time starts again. `stale`: what it was
|
|
58
|
+
* built from may have changed. `undefined` when no such table is open.
|
|
59
|
+
*/
|
|
60
|
+
use(handle) {
|
|
61
|
+
const entry = this.open.get(handle);
|
|
62
|
+
if (entry === void 0) return void 0;
|
|
63
|
+
entry.timer.refresh();
|
|
64
|
+
this.open.delete(handle);
|
|
65
|
+
this.open.set(handle, entry);
|
|
66
|
+
return {
|
|
67
|
+
projectId: entry.projectId,
|
|
68
|
+
stale: entry.table.isChanged()
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** Gives back the table under `handle`. False when no such table is open. */
|
|
72
|
+
drop(handle) {
|
|
73
|
+
const entry = this.open.get(handle);
|
|
74
|
+
if (entry === void 0) return false;
|
|
75
|
+
this.release(handle, entry);
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
/** Gives back every table built over `projectId`. */
|
|
79
|
+
releaseProject(projectId) {
|
|
80
|
+
for (const [handle, entry] of this.open) if (entry.projectId === projectId) this.release(handle, entry);
|
|
81
|
+
}
|
|
82
|
+
/** Gives back every table. */
|
|
83
|
+
releaseAll() {
|
|
84
|
+
for (const [handle, entry] of this.open) this.release(handle, entry);
|
|
85
|
+
}
|
|
86
|
+
release(handle, entry) {
|
|
87
|
+
if (this.open.get(handle) !== entry) return;
|
|
88
|
+
clearTimeout(entry.timer);
|
|
89
|
+
this.open.delete(handle);
|
|
90
|
+
entry.table.resetState();
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* The server's holds on projects, wired to its agent tables: the tables built over a project go
|
|
95
|
+
* when the server's kept hold on it is given back or ended, but not while a call on the project is
|
|
96
|
+
* still running. Such a call ends by keeping the project again ({@link ProjectHolds}), and the
|
|
97
|
+
* release of that hold lets the tables go then.
|
|
98
|
+
*/
|
|
99
|
+
function projectHoldsWithTables(tables, options) {
|
|
100
|
+
const holds = new ProjectHolds({
|
|
101
|
+
...options,
|
|
102
|
+
onRelease: (projectId, reason) => {
|
|
103
|
+
if (holds.callsInFlight(projectId) === 0) tables.releaseProject(projectId);
|
|
104
|
+
options.onRelease?.(projectId, reason);
|
|
105
|
+
},
|
|
106
|
+
onEnded: (projectId) => {
|
|
107
|
+
tables.releaseProject(projectId);
|
|
108
|
+
options.onEnded?.(projectId);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
return holds;
|
|
112
|
+
}
|
|
113
|
+
export { AgentTables, projectHoldsWithTables };
|
|
114
|
+
|
|
115
|
+
//# sourceMappingURL=agent-tables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-tables.js","names":[],"sources":["../src/agent-tables.ts"],"sourcesContent":["import type { PTableHandle, ProjectId } from \"@milaboratories/pl-model-common\";\nimport { ProjectHolds, type ProjectHoldsOptions } from \"./project-holds\";\n\n/**\n * What the server keeps of a table an agent built: the computable that holds the driver's\n * reference to it (the middle layer's `Project.createPoolTable`).\n */\nexport interface HeldTable {\n /** Gives the driver's reference back. */\n resetState(): void;\n /** Whether what the table was built from may have changed since it was built. */\n isChanged(): boolean;\n}\n\nexport interface AgentTablesOptions {\n /** How long a table is kept after it was built or last read. */\n idleMs: number;\n /** How many tables are kept; the least recently used goes when one more is added. */\n maxTables: number;\n}\n\ntype Entry = {\n readonly projectId: ProjectId;\n readonly table: HeldTable;\n readonly timer: NodeJS.Timeout;\n};\n\n/**\n * The tables agents built with `create_table`, by handle.\n *\n * A table is given back (its computable reset, which releases the driver's reference) at the\n * earliest of: {@link drop}; {@link AgentTablesOptions.idleMs} after it was built or last used;\n * {@link releaseProject} of its project, when the server lets go of it; {@link releaseAll}; or\n * when more than {@link AgentTablesOptions.maxTables} are open and it is the least recently used.\n * A read of a table that went meanwhile fails as a read of any stale handle does.\n *\n * The same definition over the same data gives the same handle: building it again replaces the\n * entry, and the newer reference is in place before the older one is given back.\n */\nexport class AgentTables {\n /** The open tables; the map's order is the order of use, oldest first. */\n private readonly open = new Map<PTableHandle, Entry>();\n\n constructor(private readonly options: AgentTablesOptions) {}\n\n /** How many tables are open. */\n get size(): number {\n return this.open.size;\n }\n\n /** The idle time of a table, in whole seconds. */\n get expiresInSec(): number {\n return Math.round(this.options.idleMs / 1000);\n }\n\n /**\n * Keeps `table`, built over project `projectId`, under `handle`. Gives the handles of the tables\n * let go to stay within the cap.\n */\n add(projectId: ProjectId, handle: PTableHandle, table: HeldTable): PTableHandle[] {\n const previous = this.open.get(handle);\n const entry: Entry = {\n projectId,\n table,\n timer: setTimeout(() => this.release(handle, entry), this.options.idleMs),\n };\n entry.timer.unref();\n this.open.delete(handle);\n this.open.set(handle, entry);\n if (previous !== undefined) {\n clearTimeout(previous.timer);\n previous.table.resetState();\n }\n const evicted: PTableHandle[] = [];\n for (const [oldest, old] of this.open) {\n if (this.open.size <= this.options.maxTables) break;\n evicted.push(oldest);\n this.release(oldest, old);\n }\n return evicted;\n }\n\n /**\n * The table under `handle`, counted as used: its idle time starts again. `stale`: what it was\n * built from may have changed. `undefined` when no such table is open.\n */\n use(handle: PTableHandle): { projectId: ProjectId; stale: boolean } | undefined {\n const entry = this.open.get(handle);\n if (entry === undefined) return undefined;\n entry.timer.refresh();\n this.open.delete(handle);\n this.open.set(handle, entry);\n return { projectId: entry.projectId, stale: entry.table.isChanged() };\n }\n\n /** Gives back the table under `handle`. False when no such table is open. */\n drop(handle: PTableHandle): boolean {\n const entry = this.open.get(handle);\n if (entry === undefined) return false;\n this.release(handle, entry);\n return true;\n }\n\n /** Gives back every table built over `projectId`. */\n releaseProject(projectId: ProjectId): void {\n for (const [handle, entry] of this.open)\n if (entry.projectId === projectId) this.release(handle, entry);\n }\n\n /** Gives back every table. */\n releaseAll(): void {\n for (const [handle, entry] of this.open) this.release(handle, entry);\n }\n\n private release(handle: PTableHandle, entry: Entry): void {\n if (this.open.get(handle) !== entry) return;\n clearTimeout(entry.timer);\n this.open.delete(handle);\n entry.table.resetState();\n }\n}\n\n/**\n * The server's holds on projects, wired to its agent tables: the tables built over a project go\n * when the server's kept hold on it is given back or ended, but not while a call on the project is\n * still running. Such a call ends by keeping the project again ({@link ProjectHolds}), and the\n * release of that hold lets the tables go then.\n */\nexport function projectHoldsWithTables<P>(\n tables: AgentTables,\n options: ProjectHoldsOptions<P>,\n): ProjectHolds<P> {\n const holds: ProjectHolds<P> = new ProjectHolds<P>({\n ...options,\n onRelease: (projectId, reason) => {\n if (holds.callsInFlight(projectId) === 0) tables.releaseProject(projectId);\n options.onRelease?.(projectId, reason);\n },\n onEnded: (projectId) => {\n tables.releaseProject(projectId);\n options.onEnded?.(projectId);\n },\n });\n return holds;\n}\n"],"mappings":";;;;;;;;;;;;;;AAuCA,IAAa,cAAb,MAAyB;CAIM;;CAF7B,uBAAwB,IAAI,IAAyB;CAErD,YAAY,SAA8C;EAA7B,KAAA,UAAA;CAA8B;;CAG3D,IAAI,OAAe;EACjB,OAAO,KAAK,KAAK;CACnB;;CAGA,IAAI,eAAuB;EACzB,OAAO,KAAK,MAAM,KAAK,QAAQ,SAAS,GAAI;CAC9C;;;;;CAMA,IAAI,WAAsB,QAAsB,OAAkC;EAChF,MAAM,WAAW,KAAK,KAAK,IAAI,MAAM;EACrC,MAAM,QAAe;GACnB;GACA;GACA,OAAO,iBAAiB,KAAK,QAAQ,QAAQ,KAAK,GAAG,KAAK,QAAQ,MAAM;EAC1E;EACA,MAAM,MAAM,MAAM;EAClB,KAAK,KAAK,OAAO,MAAM;EACvB,KAAK,KAAK,IAAI,QAAQ,KAAK;EAC3B,IAAI,aAAa,KAAA,GAAW;GAC1B,aAAa,SAAS,KAAK;GAC3B,SAAS,MAAM,WAAW;EAC5B;EACA,MAAM,UAA0B,CAAC;EACjC,KAAK,MAAM,CAAC,QAAQ,QAAQ,KAAK,MAAM;GACrC,IAAI,KAAK,KAAK,QAAQ,KAAK,QAAQ,WAAW;GAC9C,QAAQ,KAAK,MAAM;GACnB,KAAK,QAAQ,QAAQ,GAAG;EAC1B;EACA,OAAO;CACT;;;;;CAMA,IAAI,QAA4E;EAC9E,MAAM,QAAQ,KAAK,KAAK,IAAI,MAAM;EAClC,IAAI,UAAU,KAAA,GAAW,OAAO,KAAA;EAChC,MAAM,MAAM,QAAQ;EACpB,KAAK,KAAK,OAAO,MAAM;EACvB,KAAK,KAAK,IAAI,QAAQ,KAAK;EAC3B,OAAO;GAAE,WAAW,MAAM;GAAW,OAAO,MAAM,MAAM,UAAU;EAAE;CACtE;;CAGA,KAAK,QAA+B;EAClC,MAAM,QAAQ,KAAK,KAAK,IAAI,MAAM;EAClC,IAAI,UAAU,KAAA,GAAW,OAAO;EAChC,KAAK,QAAQ,QAAQ,KAAK;EAC1B,OAAO;CACT;;CAGA,eAAe,WAA4B;EACzC,KAAK,MAAM,CAAC,QAAQ,UAAU,KAAK,MACjC,IAAI,MAAM,cAAc,WAAW,KAAK,QAAQ,QAAQ,KAAK;CACjE;;CAGA,aAAmB;EACjB,KAAK,MAAM,CAAC,QAAQ,UAAU,KAAK,MAAM,KAAK,QAAQ,QAAQ,KAAK;CACrE;CAEA,QAAgB,QAAsB,OAAoB;EACxD,IAAI,KAAK,KAAK,IAAI,MAAM,MAAM,OAAO;EACrC,aAAa,MAAM,KAAK;EACxB,KAAK,KAAK,OAAO,MAAM;EACvB,MAAM,MAAM,WAAW;CACzB;AACF;;;;;;;AAQA,SAAgB,uBACd,QACA,SACiB;CACjB,MAAM,QAAyB,IAAI,aAAgB;EACjD,GAAG;EACH,YAAY,WAAW,WAAW;GAChC,IAAI,MAAM,cAAc,SAAS,MAAM,GAAG,OAAO,eAAe,SAAS;GACzE,QAAQ,YAAY,WAAW,MAAM;EACvC;EACA,UAAU,cAAc;GACtB,OAAO,eAAe,SAAS;GAC/B,QAAQ,UAAU,SAAS;EAC7B;CACF,CAAC;CACD,OAAO;AACT"}
|
package/dist/instructions.cjs
CHANGED
|
@@ -4,26 +4,29 @@
|
|
|
4
4
|
* the order the tools are used in. Clients that load tools on demand show the model this text and
|
|
5
5
|
* the tool names only, so the order of work has to be readable from here.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* Claude Code cuts server instructions at 4096 characters. This text stays under 3600, so a new
|
|
8
|
+
* tool can be named in the order of work without pushing it over. It keeps only the order of work
|
|
9
|
+
* and the rules that hold for every tool; what one tool does, refuses or waits for is said in that
|
|
10
|
+
* tool's description, and nothing here repeats it.
|
|
9
11
|
*/
|
|
10
12
|
const SERVER_INSTRUCTIONS = `Platforma Desktop: build and run data analysis projects. A project is an ordered list of blocks; each block is one analysis step with its own configuration, and reads the results of blocks above it.
|
|
11
13
|
|
|
12
14
|
Order of work:
|
|
13
15
|
1. Connection: get_connection_status. If not connected: list_connections, then connect_to_server.
|
|
14
16
|
2. Project: list_projects finds a project, create_project makes a new one. Every tool that works on a project takes its projectId.
|
|
15
|
-
3. Add blocks: list_available_blocks finds a block; add_block adds it, with params to configure it at creation. Add blocks in the order the data flows.
|
|
16
|
-
4. Configure a block:
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
3. Add blocks: list_available_blocks finds a block; add_block adds it, with params to configure it at creation (get_block_contract shows the params a kind accepts), or bare, in its default state. Add blocks in the order the data flows.
|
|
18
|
+
4. Configure a block: get_block_params reads its kind's params; write them whole with set_block_params. For what params do not cover (view state, plugin data, blocks with no params), or when set_block_params refuses: read the data with get_block_state and write it whole with set_block_data. Both writes wait for the outputs to settle and return the block's readiness. A block's choices for its inputs (datasets, columns of blocks above) are in its outputs: get_block_outputs; get_column_values lists a column's values.
|
|
19
|
+
From scratch: add the block bare, read its option outputs, copy the references you need into its params or data. A block offers a result of a block above only once it exists, some only after a run: if an option is missing, run the block above first (run_block, await_block_done). Params and data can name things differently: read the data before writing it.
|
|
20
|
+
Files: list_files finds them, get_file_handles makes import handles to put in the block's params or data. read_file reads a local file or a block's output blob.
|
|
21
|
+
5. Check and run: the readiness (get_block_state and both writes) says whether a block can run and, if not, why, in the block's own words. get_project_overview shows the status of every block. run_block starts a block together with the stale blocks above it; await_block_done waits for it.
|
|
22
|
+
6. Results: get_block_outputs, then list_columns and query_table for tables, get_block_logs for logs. select_block shows a block to the user, only when they ask.
|
|
23
|
+
|
|
24
|
+
Result pool: the columns blocks export for the blocks below them. list_pool_columns lists them with their specs, as one block sees them or for the whole project, and tests a column selector of a block's model against them; get_pool_column gives one whole spec. A block's choices are in its own option outputs; a pool column's \`ref\`, or its \`columnId\` when it has a \`ref\`, fits a block field of that form (get_block_contract).
|
|
25
|
+
To filter or join large results (columns of many blocks), create_table makes a temporary table of pool columns for query_table; drop_table frees it.
|
|
19
26
|
|
|
20
27
|
Rules:
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
- Changing a block's data can make its results, and the results of blocks that read them, stale until they run again.
|
|
24
|
-
- Only blocks on the current block API can be added.
|
|
25
|
-
- select_block shows a block to the user in the application; use it only when the user asks to be shown something.
|
|
26
|
-
- capture_screenshot, click, type_text, press_key, scroll and execute_js drive the application window. They are for testing the application; configuring and running blocks does not need them.`;
|
|
28
|
+
- Ids, references and handles come from tool results: copy them, do not compose them. A block param takes the form get_block_contract declares: a column's \`ref\` for a PlRef object, its \`columnId\` for an id string, \`valueIds\` for picked values. Tools that take a column (create_table, get_pool_column, get_column_values) take its \`columnId\`. The one exception: a reference to a result of a block above, {__isRef: true, blockId, name}, may be written by hand when get_block_contract declares that shape and you know the result's name, with the real id of a block above.
|
|
29
|
+
- Changing a block's params or data makes its results, and those of blocks that read them, stale until they run again.`;
|
|
27
30
|
exports.SERVER_INSTRUCTIONS = SERVER_INSTRUCTIONS;
|
|
28
31
|
|
|
29
32
|
//# sourceMappingURL=instructions.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructions.cjs","names":[],"sources":["../src/instructions.ts"],"sourcesContent":["/**\n * What a client is told about the server before it has seen any tool: what the server is for and\n * the order the tools are used in. Clients that load tools on demand show the model this text and\n * the tool names only, so the order of work has to be readable from here.\n *\n *
|
|
1
|
+
{"version":3,"file":"instructions.cjs","names":[],"sources":["../src/instructions.ts"],"sourcesContent":["/**\n * What a client is told about the server before it has seen any tool: what the server is for and\n * the order the tools are used in. Clients that load tools on demand show the model this text and\n * the tool names only, so the order of work has to be readable from here.\n *\n * Claude Code cuts server instructions at 4096 characters. This text stays under 3600, so a new\n * tool can be named in the order of work without pushing it over. It keeps only the order of work\n * and the rules that hold for every tool; what one tool does, refuses or waits for is said in that\n * tool's description, and nothing here repeats it.\n */\nexport const SERVER_INSTRUCTIONS = `Platforma Desktop: build and run data analysis projects. A project is an ordered list of blocks; each block is one analysis step with its own configuration, and reads the results of blocks above it.\n\nOrder of work:\n1. Connection: get_connection_status. If not connected: list_connections, then connect_to_server.\n2. Project: list_projects finds a project, create_project makes a new one. Every tool that works on a project takes its projectId.\n3. Add blocks: list_available_blocks finds a block; add_block adds it, with params to configure it at creation (get_block_contract shows the params a kind accepts), or bare, in its default state. Add blocks in the order the data flows.\n4. Configure a block: get_block_params reads its kind's params; write them whole with set_block_params. For what params do not cover (view state, plugin data, blocks with no params), or when set_block_params refuses: read the data with get_block_state and write it whole with set_block_data. Both writes wait for the outputs to settle and return the block's readiness. A block's choices for its inputs (datasets, columns of blocks above) are in its outputs: get_block_outputs; get_column_values lists a column's values.\n From scratch: add the block bare, read its option outputs, copy the references you need into its params or data. A block offers a result of a block above only once it exists, some only after a run: if an option is missing, run the block above first (run_block, await_block_done). Params and data can name things differently: read the data before writing it.\n Files: list_files finds them, get_file_handles makes import handles to put in the block's params or data. read_file reads a local file or a block's output blob.\n5. Check and run: the readiness (get_block_state and both writes) says whether a block can run and, if not, why, in the block's own words. get_project_overview shows the status of every block. run_block starts a block together with the stale blocks above it; await_block_done waits for it.\n6. Results: get_block_outputs, then list_columns and query_table for tables, get_block_logs for logs. select_block shows a block to the user, only when they ask.\n\nResult pool: the columns blocks export for the blocks below them. list_pool_columns lists them with their specs, as one block sees them or for the whole project, and tests a column selector of a block's model against them; get_pool_column gives one whole spec. A block's choices are in its own option outputs; a pool column's \\`ref\\`, or its \\`columnId\\` when it has a \\`ref\\`, fits a block field of that form (get_block_contract).\nTo filter or join large results (columns of many blocks), create_table makes a temporary table of pool columns for query_table; drop_table frees it.\n\nRules:\n- Ids, references and handles come from tool results: copy them, do not compose them. A block param takes the form get_block_contract declares: a column's \\`ref\\` for a PlRef object, its \\`columnId\\` for an id string, \\`valueIds\\` for picked values. Tools that take a column (create_table, get_pool_column, get_column_values) take its \\`columnId\\`. The one exception: a reference to a result of a block above, {__isRef: true, blockId, name}, may be written by hand when get_block_contract declares that shape and you know the result's name, with the real id of a block above.\n- Changing a block's params or data makes its results, and those of blocks that read them, stale until they run again.`;\n"],"mappings":";;;;;;;;;;;AAUA,MAAa,sBAAsB"}
|
package/dist/instructions.js
CHANGED
|
@@ -4,26 +4,29 @@
|
|
|
4
4
|
* the order the tools are used in. Clients that load tools on demand show the model this text and
|
|
5
5
|
* the tool names only, so the order of work has to be readable from here.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* Claude Code cuts server instructions at 4096 characters. This text stays under 3600, so a new
|
|
8
|
+
* tool can be named in the order of work without pushing it over. It keeps only the order of work
|
|
9
|
+
* and the rules that hold for every tool; what one tool does, refuses or waits for is said in that
|
|
10
|
+
* tool's description, and nothing here repeats it.
|
|
9
11
|
*/
|
|
10
12
|
const SERVER_INSTRUCTIONS = `Platforma Desktop: build and run data analysis projects. A project is an ordered list of blocks; each block is one analysis step with its own configuration, and reads the results of blocks above it.
|
|
11
13
|
|
|
12
14
|
Order of work:
|
|
13
15
|
1. Connection: get_connection_status. If not connected: list_connections, then connect_to_server.
|
|
14
16
|
2. Project: list_projects finds a project, create_project makes a new one. Every tool that works on a project takes its projectId.
|
|
15
|
-
3. Add blocks: list_available_blocks finds a block; add_block adds it, with params to configure it at creation. Add blocks in the order the data flows.
|
|
16
|
-
4. Configure a block:
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
3. Add blocks: list_available_blocks finds a block; add_block adds it, with params to configure it at creation (get_block_contract shows the params a kind accepts), or bare, in its default state. Add blocks in the order the data flows.
|
|
18
|
+
4. Configure a block: get_block_params reads its kind's params; write them whole with set_block_params. For what params do not cover (view state, plugin data, blocks with no params), or when set_block_params refuses: read the data with get_block_state and write it whole with set_block_data. Both writes wait for the outputs to settle and return the block's readiness. A block's choices for its inputs (datasets, columns of blocks above) are in its outputs: get_block_outputs; get_column_values lists a column's values.
|
|
19
|
+
From scratch: add the block bare, read its option outputs, copy the references you need into its params or data. A block offers a result of a block above only once it exists, some only after a run: if an option is missing, run the block above first (run_block, await_block_done). Params and data can name things differently: read the data before writing it.
|
|
20
|
+
Files: list_files finds them, get_file_handles makes import handles to put in the block's params or data. read_file reads a local file or a block's output blob.
|
|
21
|
+
5. Check and run: the readiness (get_block_state and both writes) says whether a block can run and, if not, why, in the block's own words. get_project_overview shows the status of every block. run_block starts a block together with the stale blocks above it; await_block_done waits for it.
|
|
22
|
+
6. Results: get_block_outputs, then list_columns and query_table for tables, get_block_logs for logs. select_block shows a block to the user, only when they ask.
|
|
23
|
+
|
|
24
|
+
Result pool: the columns blocks export for the blocks below them. list_pool_columns lists them with their specs, as one block sees them or for the whole project, and tests a column selector of a block's model against them; get_pool_column gives one whole spec. A block's choices are in its own option outputs; a pool column's \`ref\`, or its \`columnId\` when it has a \`ref\`, fits a block field of that form (get_block_contract).
|
|
25
|
+
To filter or join large results (columns of many blocks), create_table makes a temporary table of pool columns for query_table; drop_table frees it.
|
|
19
26
|
|
|
20
27
|
Rules:
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
- Changing a block's data can make its results, and the results of blocks that read them, stale until they run again.
|
|
24
|
-
- Only blocks on the current block API can be added.
|
|
25
|
-
- select_block shows a block to the user in the application; use it only when the user asks to be shown something.
|
|
26
|
-
- capture_screenshot, click, type_text, press_key, scroll and execute_js drive the application window. They are for testing the application; configuring and running blocks does not need them.`;
|
|
28
|
+
- Ids, references and handles come from tool results: copy them, do not compose them. A block param takes the form get_block_contract declares: a column's \`ref\` for a PlRef object, its \`columnId\` for an id string, \`valueIds\` for picked values. Tools that take a column (create_table, get_pool_column, get_column_values) take its \`columnId\`. The one exception: a reference to a result of a block above, {__isRef: true, blockId, name}, may be written by hand when get_block_contract declares that shape and you know the result's name, with the real id of a block above.
|
|
29
|
+
- Changing a block's params or data makes its results, and those of blocks that read them, stale until they run again.`;
|
|
27
30
|
export { SERVER_INSTRUCTIONS };
|
|
28
31
|
|
|
29
32
|
//# sourceMappingURL=instructions.js.map
|
package/dist/instructions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructions.js","names":[],"sources":["../src/instructions.ts"],"sourcesContent":["/**\n * What a client is told about the server before it has seen any tool: what the server is for and\n * the order the tools are used in. Clients that load tools on demand show the model this text and\n * the tool names only, so the order of work has to be readable from here.\n *\n *
|
|
1
|
+
{"version":3,"file":"instructions.js","names":[],"sources":["../src/instructions.ts"],"sourcesContent":["/**\n * What a client is told about the server before it has seen any tool: what the server is for and\n * the order the tools are used in. Clients that load tools on demand show the model this text and\n * the tool names only, so the order of work has to be readable from here.\n *\n * Claude Code cuts server instructions at 4096 characters. This text stays under 3600, so a new\n * tool can be named in the order of work without pushing it over. It keeps only the order of work\n * and the rules that hold for every tool; what one tool does, refuses or waits for is said in that\n * tool's description, and nothing here repeats it.\n */\nexport const SERVER_INSTRUCTIONS = `Platforma Desktop: build and run data analysis projects. A project is an ordered list of blocks; each block is one analysis step with its own configuration, and reads the results of blocks above it.\n\nOrder of work:\n1. Connection: get_connection_status. If not connected: list_connections, then connect_to_server.\n2. Project: list_projects finds a project, create_project makes a new one. Every tool that works on a project takes its projectId.\n3. Add blocks: list_available_blocks finds a block; add_block adds it, with params to configure it at creation (get_block_contract shows the params a kind accepts), or bare, in its default state. Add blocks in the order the data flows.\n4. Configure a block: get_block_params reads its kind's params; write them whole with set_block_params. For what params do not cover (view state, plugin data, blocks with no params), or when set_block_params refuses: read the data with get_block_state and write it whole with set_block_data. Both writes wait for the outputs to settle and return the block's readiness. A block's choices for its inputs (datasets, columns of blocks above) are in its outputs: get_block_outputs; get_column_values lists a column's values.\n From scratch: add the block bare, read its option outputs, copy the references you need into its params or data. A block offers a result of a block above only once it exists, some only after a run: if an option is missing, run the block above first (run_block, await_block_done). Params and data can name things differently: read the data before writing it.\n Files: list_files finds them, get_file_handles makes import handles to put in the block's params or data. read_file reads a local file or a block's output blob.\n5. Check and run: the readiness (get_block_state and both writes) says whether a block can run and, if not, why, in the block's own words. get_project_overview shows the status of every block. run_block starts a block together with the stale blocks above it; await_block_done waits for it.\n6. Results: get_block_outputs, then list_columns and query_table for tables, get_block_logs for logs. select_block shows a block to the user, only when they ask.\n\nResult pool: the columns blocks export for the blocks below them. list_pool_columns lists them with their specs, as one block sees them or for the whole project, and tests a column selector of a block's model against them; get_pool_column gives one whole spec. A block's choices are in its own option outputs; a pool column's \\`ref\\`, or its \\`columnId\\` when it has a \\`ref\\`, fits a block field of that form (get_block_contract).\nTo filter or join large results (columns of many blocks), create_table makes a temporary table of pool columns for query_table; drop_table frees it.\n\nRules:\n- Ids, references and handles come from tool results: copy them, do not compose them. A block param takes the form get_block_contract declares: a column's \\`ref\\` for a PlRef object, its \\`columnId\\` for an id string, \\`valueIds\\` for picked values. Tools that take a column (create_table, get_pool_column, get_column_values) take its \\`columnId\\`. The one exception: a reference to a result of a block above, {__isRef: true, blockId, name}, may be written by hand when get_block_contract declares that shape and you know the result's name, with the real id of a block above.\n- Changing a block's params or data makes its results, and those of blocks that read them, stale until they run again.`;\n"],"mappings":";;;;;;;;;;;AAUA,MAAa,sBAAsB"}
|
package/dist/package.cjs
CHANGED
package/dist/package.js
CHANGED