@xpert-ai/plugin-sdk 3.23.0 → 3.25.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/_object_without_properties_loose.cjs.js +16 -0
- package/_object_without_properties_loose.esm.js +14 -0
- package/analytics-result.cjs.js +212 -0
- package/analytics-result.esm.js +201 -0
- package/analytics.cjs.default.js +1 -0
- package/analytics.cjs.js +17 -0
- package/analytics.cjs.mjs +2 -0
- package/analytics.d.ts +1 -0
- package/analytics.esm.js +2 -0
- package/artifact-document.cjs.default.js +1 -0
- package/artifact-document.cjs.js +581 -0
- package/artifact-document.cjs.mjs +2 -0
- package/artifact-document.d.ts +1 -0
- package/artifact-document.esm.js +563 -0
- package/data-workbench.cjs.js +23 -6
- package/data-workbench.esm.js +23 -6
- package/docs/README.md +8 -0
- package/docs/analytics.md +108 -0
- package/docs/artifact-documents.md +74 -0
- package/docs/artifact-drafts.md +24 -0
- package/docs/artifact-presentations.md +43 -0
- package/docs/json-encoded-schema.md +19 -0
- package/docs/mcp-client.md +63 -0
- package/docs/provider-credential-validation.md +34 -0
- package/docs/rest-client.md +24 -0
- package/docs/workspace-dataset-pipelines.md +120 -0
- package/docs/workspace-file-tools.md +66 -0
- package/index.cjs.js +555 -108
- package/index.esm.js +573 -172
- package/model-provider-toolset.cjs.js +1 -1
- package/model-provider-toolset.esm.js +1 -1
- package/model-provider.cjs.js +47 -1
- package/model-provider.esm.js +41 -2
- package/package.json +14 -2
- package/src/analytics.d.ts +3 -0
- package/src/artifact-document.d.ts +5 -0
- package/src/index.d.ts +2 -0
- package/src/lib/agent/handoff/agent-runtime-message.contract.d.ts +80 -80
- package/src/lib/agent/middleware/capabilities/assistant-task.d.ts +36 -1
- package/src/lib/agent/runtime/dispatch.d.ts +284 -284
- package/src/lib/agent/runtime/index.d.ts +1 -0
- package/src/lib/agent/runtime/pipeline-scope.d.ts +110 -0
- package/src/lib/agent/runtime/types.d.ts +4 -2
- package/src/lib/ai-model/ai-model-provider.interface.d.ts +3 -1
- package/src/lib/ai-model/utils/limits.d.ts +4 -2
- package/src/lib/artifact-document/dependencies.d.ts +101 -0
- package/src/lib/artifact-document/host.d.ts +30 -0
- package/src/lib/artifact-document/protocol.d.ts +60 -0
- package/src/lib/artifact-document/runtime.d.ts +4 -0
- package/src/lib/artifact-document/sha256.d.ts +2 -0
- package/src/lib/artifact-presentation/index.d.ts +35 -0
- package/src/lib/core/index.d.ts +1 -0
- package/src/lib/core/json-encoded-schema.d.ts +15 -0
- package/src/lib/data/analytics/analytics-payload.d.ts +3 -0
- package/src/lib/data/analytics/analytics-provider.d.ts +74 -0
- package/src/lib/data/analytics/analytics-result.d.ts +4 -0
- package/src/lib/data/analytics/analytics.registry.d.ts +10 -0
- package/src/lib/data/analytics/analytics.schema.d.ts +206 -0
- package/src/lib/data/analytics/index.d.ts +5 -0
- package/src/lib/data/datasource/index.d.ts +1 -0
- package/src/lib/data/datasource/types.d.ts +1 -1
- package/src/lib/data/datasource/workbench-adapter.d.ts +11 -1
- package/src/lib/data/datasource/workbench-sql.d.ts +12 -0
- package/src/lib/project-pipeline/adapters.d.ts +87 -0
- package/src/lib/project-pipeline/capability.d.ts +100 -0
- package/src/lib/project-pipeline/index.d.ts +5 -0
- package/src/lib/project-pipeline/projection.d.ts +71 -0
- package/src/lib/project-pipeline/registry.d.ts +509 -0
- package/src/lib/project-pipeline/runtime-registry.d.ts +45 -0
- package/src/lib/project-pipeline/scoped-registry.d.ts +10 -0
- package/src/lib/project-task/index.d.ts +6 -0
- package/src/lib/project-type/index.d.ts +17 -1
- package/src/lib/rag/types.d.ts +1 -1
- package/src/lib/runtime/capabilities/artifact-drafts.d.ts +29 -0
- package/src/lib/runtime/capabilities/artifacts.d.ts +12 -0
- package/src/lib/runtime/capabilities/index.d.ts +3 -0
- package/src/lib/runtime/capabilities/mcp-client-runtime.d.ts +41 -0
- package/src/lib/runtime/capabilities/rest-client-runtime.d.ts +34 -0
- package/src/lib/runtime/capabilities/sandbox-jobs.d.ts +36 -2
- package/src/lib/runtime/index.d.ts +2 -0
- package/src/lib/runtime/mutation-evidence.d.ts +7 -0
- package/src/lib/runtime/workspace-file-tools.d.ts +11 -0
- package/src/lib/sandbox/file-edits.d.ts +4 -0
- package/src/lib/sandbox/protocol.d.ts +7 -1
- package/src/lib/sandbox/runtime-provider.d.ts +4 -0
- package/src/lib/sandbox/sandbox.d.ts +2 -8
- package/src/lib/tool-provider/adapters.d.ts +1 -1
- package/src/lib/tool-provider/types.d.ts +2 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Workspace live script queries and dashboard Datasets
|
|
2
|
+
|
|
3
|
+
Status: implemented in the current source tree. The platform provides generic execution capabilities, and `@xpert-ai/plugin-analytics-workspace-script` provides the Python/JavaScript adapter. Before deployment, independently verify compatible SDK/contracts packages, the compute image and the Runtime Binding. Successful local integration does not establish production release readiness.
|
|
4
|
+
|
|
5
|
+
This document uses the script provider to illustrate how platform capabilities compose. `workspace_script.*`, script definitions, language entrypoints and the plugin limits below belong to this plugin; they are not a protocol that every Analytics provider must adopt. See [Analytics](analytics.md) for the generic data and presentation boundaries, and the [HTML document host](artifact-documents.md) for the browser isolation protocol.
|
|
6
|
+
|
|
7
|
+
Each dashboard open, filter change or manual refresh reruns the script against current inputs and returns a normalized Dataset. Routine refreshes require no LLM calls. Automatic push updates and scheduled polling are outside this version's scope.
|
|
8
|
+
|
|
9
|
+
## Query flow
|
|
10
|
+
|
|
11
|
+
```text
|
|
12
|
+
Dashboard Artifact + controls
|
|
13
|
+
→ Analytics Runtime (current actor, parameters, executionId, deadline, signal)
|
|
14
|
+
→ workspace_script.query provider
|
|
15
|
+
→ Definition Artifact/version + current file authorization + execution code snapshot
|
|
16
|
+
→ Sandbox Jobs / compute Runtime
|
|
17
|
+
query(ctx)
|
|
18
|
+
├─ sources.query(alias, controls) → invocation → Analytics → source plugin
|
|
19
|
+
└─ files.read(alias) → invocation → Workspace Files
|
|
20
|
+
→ Plugin validates columns/rows and trusted execution evidence
|
|
21
|
+
→ Platform normalizeAnalyticsResult
|
|
22
|
+
→ Live Dashboard: Data Analytics renderer or isolated HTML page
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Multiple charts can reuse the same Dataset. Each actual query receives a new executionId and Job idempotency key, so it runs again even when parameters are unchanged. This does not automatically deduplicate separate page calls. Temporary outputs belong to the current execution and cannot serve as a cache for the next query.
|
|
26
|
+
|
|
27
|
+
## Modules and responsibility boundaries
|
|
28
|
+
|
|
29
|
+
| Module | Implemented responsibilities |
|
|
30
|
+
| --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
31
|
+
| `plugin-sdk` Analytics capability | Generic Dataset/Binding/discovery interfaces; provider context includes executionId, deadlineAt and ancestry; trusted internal query execution propagates signal/deadline |
|
|
32
|
+
| `server/data-source/analytics` | Assign execution IDs before dispatch; enforce parent/child deadlines, cancellation, source reauthorization, nesting depth and recursion limits |
|
|
33
|
+
| `plugin-sdk` jsonEncodedSchema | Decode JSON text once at explicitly enabled input boundaries, then apply the original strict schema; shared by script registration and dashboard saves without automatically relaxing HTTP or persistence protocols |
|
|
34
|
+
| `plugin-sdk` Sandbox Jobs capability | `run(input, options?)`, with signal and a named invocation handler in options; callbacks are not serialized, and actor parameters are not accepted from HTTP |
|
|
35
|
+
| `server-ai/sandbox/sandbox-job` | Job lifecycle, bounded stdout invocation sessions, actor context preservation, cancellation and cleanup; no SQL/ontology/CSV logic |
|
|
36
|
+
| `server-ai/shared/volume` and Workspace Files | Existing published Assistant/Project ACLs, portable references, path and symlink restrictions; a dedicated cleanup entrypoint for Job roots |
|
|
37
|
+
| Sandbox Runtime Suite | Generic compute profile and Node/Python image; non-root execution, no network, read-only inputs and resource limits |
|
|
38
|
+
| Pro Docker Runtime Provider | Read-only task mounts, separate output tmpfs, live output streaming, bounded output reads and cancellation cleanup; replaceable by a provider with equivalent capabilities |
|
|
39
|
+
| `analytics-workspace-script` plugin | Definition schema, language entrypoints, CSV helpers, alias authorization, result constraints and lineage |
|
|
40
|
+
| PostgreSQL / data-xpert plugins | Native queries, credentials, resource policies and data semantics; scripts invoke only Binding aliases |
|
|
41
|
+
| Live Dashboard plugin | Saves, filters, refreshes, stale-response protection, preview receipts, standard charts/tables and custom HTML presentation |
|
|
42
|
+
|
|
43
|
+
No script-specific business table is introduced. Definitions and execution evidence use existing Artifact/ArtifactVersion records; tasks use SandboxJob. The platform does not interpret script business semantics, and charts do not interpret SQL, ontology Actions or script languages.
|
|
44
|
+
|
|
45
|
+
## Protocol and persistence
|
|
46
|
+
|
|
47
|
+
The generic Binding uses `providerId: workspace_script.query`, `operation: query` and `contractVersion: 1`, with source type `workspace-script`. Its payload contains only the definition's `artifactId/versionId`; parameters bind controls, and output declares the datasetId, stable field IDs, types, units and grain.
|
|
48
|
+
|
|
49
|
+
The plugin definition uses `xpert.analytics-script/v1`:
|
|
50
|
+
|
|
51
|
+
- `runtime` pins the Action name and version, currently `workspace_script.execute@1.0.0`.
|
|
52
|
+
- `language`, `mode`, the `script` portable reference and `scriptSha256` identify the code.
|
|
53
|
+
- `authorization` retains the original Assistant file reference; pinned snapshots still require rechecking the original permissions.
|
|
54
|
+
- `files` maps aliases to authorized portable references; `sources` maps aliases to complete source Bindings.
|
|
55
|
+
- `parameters/output` must exactly match the outer Binding; saving cannot silently substitute a different contract.
|
|
56
|
+
|
|
57
|
+
`pinned` fixes the code snapshot while reading current inputs. `current` rereads the code on each execution and creates an immutable snapshot for that execution. Definitions are currently owned by their creator; sharing a dashboard does not automatically expand script or file permissions.
|
|
58
|
+
|
|
59
|
+
Execution Artifacts store the executionId, Job ID, definition version, code SHA, parameter digest, input file SHAs/read times, child queries and source execution IDs, and output SHA. The source timestamp uses the earliest input read time in the execution; execution time is not presented as business dataAsOf. No automatic audit-retention TTL is introduced.
|
|
60
|
+
|
|
61
|
+
## Script entrypoints
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
async def query(ctx):
|
|
65
|
+
dataset = await ctx.sources.query("sales", {"region": ctx.parameters.get("region")})
|
|
66
|
+
return ctx.dataset([
|
|
67
|
+
{"region": row["region"], "amount": row["amount"]}
|
|
68
|
+
for row in dataset["rows"]
|
|
69
|
+
])
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
export async function query(ctx) {
|
|
74
|
+
const file = await ctx.files.read('orders')
|
|
75
|
+
const records = ctx.csv.parse(file.text)
|
|
76
|
+
return ctx.dataset(records.map((row) => ({ region: row.region, amount: row.amount })))
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Source Dataset rows use `field.id`; script output uses the definition's `sourceField`. decimal/int64 values must remain exact strings. Python can use Decimal, and JavaScript can use integer minor units/BigInt, converting results back to exact strings. Results may contain only columns/rows; scripts cannot issue freshness, provenance or completeness claims.
|
|
81
|
+
|
|
82
|
+
The second argument to a source query supplies controls for the predeclared Binding, mapped by controlId. Scripts cannot replace the source, native payload, actor or credentials. CSV helpers remain in the plugin. Only the Python/Node standard libraries are available by default; arbitrary packages are not installed.
|
|
83
|
+
|
|
84
|
+
## Invocation during generic execution
|
|
85
|
+
|
|
86
|
+
`SandboxJobRunOptions.invocation` registers operations, maxCalls, maxBytes and a trusted handler. Dedicated JSONL frames on container stdout carry id/operation/payload. After validation, the platform calls the handler and writes the response through the Runtime file API into the current Job's response directory, which is read-only inside the container. Docker has no network access; scripts receive neither tokens nor HTTP addresses.
|
|
87
|
+
|
|
88
|
+
The platform uses AsyncResource to preserve the trusted caller context and checks duplicate IDs, allowed operations and quotas. Sessions close when the Job completes, fails or is cancelled. Any Runtime Provider can implement this protocol through live output and file uploads. Requests currently execute in the owning API process; reconnect recovery and resumption across API processes are not implemented.
|
|
89
|
+
|
|
90
|
+
The plugin forwards `source.query` to Analytics Runtime and `file.read` to Workspace Files. Each call revalidates the definition, original Assistant and input permissions. Source actor tokens and database passwords remain in the platform/source plugins. Child queries inherit the parent deadline and cancellation signal, and recursive source calls are prohibited.
|
|
91
|
+
|
|
92
|
+
## Isolation and limits
|
|
93
|
+
|
|
94
|
+
The compute profile requires hardened, ephemeral execution, resource limits, no network, a non-root user, a read-only root filesystem and a read-only Workspace. Development mode cannot bypass the readOnlyWorkspace capability requirement. The Pro provider uses read-only task mounts and a separate 64 MB output tmpfs, with a trusted reader that rejects output symlinks and oversized files.
|
|
95
|
+
|
|
96
|
+
The total query deadline is 30 seconds. Compute execution defaults to 25 seconds with a hard limit of 30 seconds, 1 CPU and 256 MB of memory. Scripts are limited to 64 KB; up to 8 file aliases, each with a 1 MB UTF-8 file; up to 4 source aliases; 16 invocations/8 MB of invocation data; at most 4,000 source rows in total; and at most 1,000 result rows/2 MB. Longer tasks require a future unified asynchronous query protocol.
|
|
97
|
+
|
|
98
|
+
Files remain consistent within an execution after their first read. Reading multiple sources does not create a cross-system transactional snapshot. Upstream truncation/pagination propagates to the final result; aggregates over partial inputs cannot claim to be complete totals. The platform validates output fields, types and grain before returning the result, then removes temporary outputs.
|
|
99
|
+
|
|
100
|
+
The frontend uses request sequence numbers to discard late responses. The server uses deadlines and cancellation signals to reclaim executions. The current UI has no user-facing Job cancellation button, and changing filters does not guarantee immediate interruption of all previous queries.
|
|
101
|
+
|
|
102
|
+
## Two presentation modes
|
|
103
|
+
|
|
104
|
+
Standard mode uses `bindings + controls + charts/tables`. The plugin maps the normalized Dataset to the existing Data Analytics renderer; a Binding itself does not describe chart types or layout.
|
|
105
|
+
|
|
106
|
+
HTML mode uses `bindings + controls + presentation.html`, with empty `charts/tables`. The page calls `window.xpertLiveArtifact.query(bindingId, controls)` to obtain a Dataset, then uses its own JavaScript and stable field IDs to render DOM/SVG/Canvas. `subscribe` receives filter and refresh results. Host refreshes reuse the latest control values without reloading the HTML. The page does not need to know whether data comes from SQL, an ontology or a script.
|
|
107
|
+
|
|
108
|
+
Both modes save query definitions, not result snapshots. HTML and Bindings belong to the same Artifact version; the backend loads the Binding from that version and reauthorizes the current user. Frontend chart scripts in HTML and the backend Workspace data-processing scripts described here run in separate environments: the former render the page, while the latter access inputs through governed aliases in a Sandbox Job.
|
|
109
|
+
|
|
110
|
+
## One-sentence Agent generation
|
|
111
|
+
|
|
112
|
+
The Agent first discovers actual data and metric definitions, writes a script through Workspace tools, and registers it with structured parameters. Before registration, source Bindings are checked with default parameters, so invalid native query configurations fail before the script starts. Registration returns the complete bindingJson. `dashboard_preview_binding` previews it unchanged and issues a receipt for the current generation run; `dashboard_create` or `dashboard_create_html` can save only with successful receipts. HTML mode also reads the page from an authorized Workspace and runs an isolated browser preflight with real default Dataset results before saving. This flow reuses normal dashboard validation for business semantics, grain and default filters; it does not save model-invented result snapshots. A dedicated Assistant can configure allowedFinalProviders in LiveDashboard middleware to restrict the final saved provider while permitting upstream previews from other providers. The script acceptance Assistant uses workspace_script.query; ordinary Assistants have no such restriction by default.
|
|
113
|
+
|
|
114
|
+
Earlier live acceptance runs used the same nine-order fixture through Python CSV, JavaScript PostgreSQL, data-xpert semantic sources and data-xpert SSO pages. Historical results and repeatable isolated tests are documented in `xpert-plugins/community/tools/analytics-workspace-script/docs/acceptance.md`. Historical model and SSO acceptance for standard/HTML dashboards is in `xpert-plugins/community/apps/live-dashboard/docs/`. This documentation review does not mean those scenarios were rerun.
|
|
115
|
+
|
|
116
|
+
## Release boundaries
|
|
117
|
+
|
|
118
|
+
Local compute images and integration against a source checkout do not constitute a production release. Release requires updated SDK/contracts packages, a built and published compute image, a generated digest catalog/Binding, and validation of the target Runtime Provider's capabilities. Existing local execution receipts do not replace these steps.
|
|
119
|
+
|
|
120
|
+
New exports such as `jsonEncodedSchema` must exist in the SDK actually used. An old peer semver range or stale local dist does not establish compatibility. Before migrating an existing plugin to a shared helper, verify the SDK release version and dependency constraints, then remove the original implementation. Temporary SDK builds and test doubles do not prove that an older published package supports a new API.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Workspace file tools
|
|
2
|
+
|
|
3
|
+
Use the platform `SandboxFile` middleware to read, write, append and edit HTML,
|
|
4
|
+
Python, JavaScript and other text files. Domain plugins should consume the files
|
|
5
|
+
through `WorkspaceFilesRuntimeCapability` instead of adding duplicate writers.
|
|
6
|
+
The Assistant must enable the sandbox feature and include the file middleware;
|
|
7
|
+
these helpers do not enable tools or grant file access.
|
|
8
|
+
|
|
9
|
+
## Agent arguments
|
|
10
|
+
|
|
11
|
+
File paths are relative to the Assistant's file workspace, for example
|
|
12
|
+
`dashboards/sales.html` or `scripts/sales.py`. The SDK exports
|
|
13
|
+
`workspaceRelativeFilePathSchema` for the same portable input contract:
|
|
14
|
+
|
|
15
|
+
- At most 1024 characters, with non-empty `/`-separated segments.
|
|
16
|
+
- No absolute paths, Windows drive prefixes, backslashes, control characters,
|
|
17
|
+
`.`/`..` segments or whitespace at either edge of a segment.
|
|
18
|
+
- Unicode names and spaces inside a segment are supported.
|
|
19
|
+
|
|
20
|
+
Write and append accept `{ file_path, content }`, with `content` as one string
|
|
21
|
+
(including an empty string). Arrays, `html` aliases and extra fields are rejected.
|
|
22
|
+
Edit uses `old_string`, `new_string` and optional `replace_all`; multi-edit takes
|
|
23
|
+
`edits` containing `oldString`, `newString` and optional `replaceAll`. Unknown keys
|
|
24
|
+
are rejected inside each edit as well as at the top level.
|
|
25
|
+
|
|
26
|
+
This is a file-path contract. Directory listing and search retain their own
|
|
27
|
+
schemas, including support for the workspace root. Input validation does not
|
|
28
|
+
replace host authorization, filesystem containment or symlink protection.
|
|
29
|
+
|
|
30
|
+
## Observing file mutation intent
|
|
31
|
+
|
|
32
|
+
The four mutating platform tools declare host-owned metadata:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
metadata: workspaceFileMutationMetadata
|
|
36
|
+
// { workspaceFileOperation: { type: 'mutation', pathArgument: 'file_path' } }
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
A plugin can call `workspaceFileMutationPath(tool.metadata, toolCall.args)` to
|
|
40
|
+
obtain the validated relative path. Other tool implementations may declare their
|
|
41
|
+
own `pathArgument`. Missing or malformed metadata, non-mutation operations and
|
|
42
|
+
invalid paths return `undefined`; consumers must not infer mutation behavior
|
|
43
|
+
from tool names, labels or file extensions.
|
|
44
|
+
|
|
45
|
+
Metadata describes an attempted operation, not its success. A plugin may mark an
|
|
46
|
+
already registered document as potentially changed before execution, but must
|
|
47
|
+
inspect the tool result and actual file content before accepting a save. Writing
|
|
48
|
+
a file does not save an Artifact draft or publish a version. Artifact saves need
|
|
49
|
+
their own successful, revision-bearing receipt. Business rules for selecting
|
|
50
|
+
files, validating dashboards, saving drafts and publishing remain in plugins.
|
|
51
|
+
|
|
52
|
+
## Runtime path mapping
|
|
53
|
+
|
|
54
|
+
Plugins exchange relative paths, never container or server absolute paths. After
|
|
55
|
+
sandbox acquisition, the invocation handler uses the acquired provider's workspace
|
|
56
|
+
mapper when it differs from the requested provider, including when the host
|
|
57
|
+
chooses a default provider. Graph compilation and runtime workspace paths use this
|
|
58
|
+
mapped work area; server-side file access retains the Volume path and scope.
|
|
59
|
+
This does not add default-provider selection to hosts that require an explicit
|
|
60
|
+
provider, or change workspace authorization and sandbox lifecycle ownership.
|
|
61
|
+
|
|
62
|
+
## Recovering failed file edits
|
|
63
|
+
|
|
64
|
+
`sandbox_write_file` creates a new file; it does not overwrite an existing editing copy. Read an existing file and use exact-text edit tools. Structured mutation results containing an error provide a portable `recovery.read` tool call and recovery guidance without converting the error into success.
|
|
65
|
+
|
|
66
|
+
`BaseSandbox.multiEdit` persists operations sequentially, stops at the first error, and does not roll back earlier successful edits. Its optional `MultiEditResult.progress` reports `mode: "sequential"`, `appliedEdits`, and a one-based `failedEdit` on failure. Other backends may omit progress; consumers must not infer rollback or applied counts when it is absent. Transport exceptions propagate. Always reread current contents after a failed batch and apply only remaining changes.
|