@deepseek-ai/dsh-cordis-host-runner 0.0.1-rc.3

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.
@@ -0,0 +1,71 @@
1
+ /**
2
+ * The registration boundary between a sandboxed host half and the real runtime: ParameterSchemaSpec
3
+ * normalization + validation with teaching errors, the marker-guarded `harness.defineTool` /
4
+ * `harness.registerTool` pair, the `harness.handle` invoke-handler normalizer, the SANDBOX CONTEXT
5
+ * FAÇADE a running plugin's `apply` receives in place of the real `ctx`, and the plugin-shape
6
+ * helpers the run lifecycle narrows sandbox return values with. The façade is a whitelist of
7
+ * lifecycle-safe verbs and declared services; framework internals and context-valued service
8
+ * returns are denied.
9
+ *
10
+ * VM-realm schemas and canonical values are rebuilt as host objects, while rendered content and
11
+ * presentation metadata are shape-checked before entering the registry. Common JSON-Schema spellings are normalized when they
12
+ * have one meaning; invalid vocabulary fails during registration with a teaching error.
13
+ * @module @deepseek-ai/dsh-cordis-host-runner/guard
14
+ */
15
+ import { Context } from '@deepseek-ai/cordis';
16
+ import type { Plugin } from '@deepseek-ai/cordis';
17
+ import type { ToolDefinition } from '@deepseek-ai/dsh-tools';
18
+ /**
19
+ * The `harness.defineTool` handed into the sandbox: the real DSL, with `parameters` normalized
20
+ * into a fresh host-realm ParameterSchemaSpec (raw object wrappers unwrapped,
21
+ * required arrays mapped, and explicit DSL object openness enforced) and the tool's `execute` return normalized into the host realm
22
+ * via a JSON round-trip. Non-JSON or wrong-shape output fails that call instead of poisoning
23
+ * the session log.
24
+ * @param options - the standard `defineTool` options; `parameters` may be the ParameterSchemaSpec DSL or a JSON-Schema-style wrapper.
25
+ * @returns the marker-tagged definition `harness.registerTool` (and the guarded `ctx.tools.register`) accepts.
26
+ */
27
+ export declare function sandboxDefineTool(options: unknown): ToolDefinition;
28
+ /**
29
+ * Normalize one `harness.handle` registration at the sandbox boundary: the
30
+ * method name must be a non-empty string and the handler a function whose
31
+ * result is host-materialized through the same cross-realm JSON clone as tool
32
+ * `execute` returns (a VM-realm object would otherwise escape the wire's
33
+ * plain-object contract).
34
+ * @param method - handler name the package's browser half calls through `host.call`.
35
+ * @param fn - sandbox handler receiving the wire-decoded JSON arguments.
36
+ * @returns the validated name and the clone-wrapped handler.
37
+ */
38
+ export declare function normalizeHandler(method: unknown, fn: unknown): {
39
+ method: string;
40
+ handler: (args: unknown) => Promise<unknown>;
41
+ };
42
+ /**
43
+ * The `harness.registerTool` handed into the sandbox: registers a
44
+ * marker-verified dynamic tool on the given context's registry.
45
+ * @param ctx - the (guarded) context whose `tools` service receives the tool.
46
+ * @param tool - a definition produced by {@link sandboxDefineTool}; anything else is rejected.
47
+ * @returns the registry disposer for the registration.
48
+ */
49
+ export declare function sandboxRegisterTool(ctx: Context, tool: unknown): () => void;
50
+ /**
51
+ * Narrow an arbitrary sandbox return value to a runnable cordis plugin: a
52
+ * function, or an object with an `apply` function. (A bare function passes the
53
+ * first arm, so the object arm never sees `Function.prototype.apply`.)
54
+ * @param value - whatever the host half returned.
55
+ * @returns whether the value can be started via `ctx.plugin`.
56
+ */
57
+ export declare function isPlugin(value: unknown): value is Plugin;
58
+ /**
59
+ * Wrap a plugin so `apply` receives the sandbox context while preserving injection metadata.
60
+ * @param plugin - the plugin the host half returned.
61
+ * @param reportFailure - reports a guard rejection to the owning Agent.
62
+ * @returns an equivalent plugin whose `apply` sees the sandbox context façade.
63
+ */
64
+ export declare function guardedPlugin(plugin: Plugin, reportFailure: (error: Error) => void): Plugin;
65
+ /**
66
+ * Display name for a running plugin: its `name` property, else anonymous.
67
+ * @param plugin - the plugin the host half returned.
68
+ * @returns the human-readable name used in run results and inspect output.
69
+ */
70
+ export declare function pluginName(plugin: Plugin): string;
71
+ //# sourceMappingURL=guard.d.ts.map