@matatbread/matbot-plugin-api 0.3.8 → 0.4.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/package.json +3 -2
- package/src/hooks.ts +6 -6
- package/src/host-machine.ts +191 -0
- package/src/host.ts +43 -0
- package/src/index.ts +27 -9
- package/src/invoke-tool.ts +25 -3
- package/src/notify.ts +3 -0
- package/src/plugin.ts +28 -195
- package/src/session.ts +30 -1
- package/src/types/events.ts +81 -0
- package/src/types/files.ts +46 -0
- package/src/types/frontend.ts +11 -0
- package/src/types/health.ts +6 -0
- package/src/types/hooks.ts +217 -0
- package/src/types/knowledge.ts +27 -0
- package/src/types/messages.ts +154 -0
- package/src/types/primitives.ts +5 -0
- package/src/types/principal.ts +10 -0
- package/src/types/provider.ts +157 -0
- package/src/types/registries.ts +84 -0
- package/src/types/session-runner.ts +69 -0
- package/src/types/steering.ts +33 -0
- package/src/types/storage.ts +16 -0
- package/src/types/system-context.ts +15 -0
- package/src/types/tools.ts +262 -0
- package/src/types/typescript.ts +50 -0
- package/src/types/vault.ts +37 -0
- package/src/types.ts +27 -1089
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// ── TypeScript ──────────────────────────────────────────────────────────────
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Erases TypeScript types from a source string, returning runnable JavaScript. Type-stripping is
|
|
5
|
+
* foundational — the harness ships raw `.ts` and any code compiled at runtime must have its types
|
|
6
|
+
* removed before it can execute — so every execution environment provides one, and it lives as a fixed
|
|
7
|
+
* runtime capability (on {@link MatbotRuntime}) the host supplies per platform, not a swappable service:
|
|
8
|
+
* node uses its built-in `stripTypeScriptTypes`, the browser bundle uses sucrase. A consumer that
|
|
9
|
+
* compiles source at runtime (e.g. `tool_function`) calls this instead of importing a platform stripper.
|
|
10
|
+
*
|
|
11
|
+
* `strip` may be async: a platform whose stripper loads lazily (the browser fetches sucrase on first use)
|
|
12
|
+
* returns a promise; a synchronous stripper (node) returns the string directly — callers `await` either.
|
|
13
|
+
* It is type-erasure, not full transpilation: node's stripper is erasable-only (enums/namespaces throw),
|
|
14
|
+
* sucrase is more permissive, so authors should keep to erasable TypeScript to stay portable.
|
|
15
|
+
*/
|
|
16
|
+
export interface TypeScriptStripper {
|
|
17
|
+
strip(source: string): string | Promise<string>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Optional, node-only developer-experience service: the live `.d.ts` of the types the loaded tools
|
|
22
|
+
* expose — what `toolResult(invokeTool(…, name, …))`, or a `function-tools` `await tool.name(…)`, resolves
|
|
23
|
+
* to — derived by compiling each loaded plugin's `declare module '@matatbread/matbot-plugin-api'`
|
|
24
|
+
* augmentations. The runtime registry can't supply this (result types are erased); only a TypeScript
|
|
25
|
+
* program reading the source can. Consumers that generate or compose tool-calling code use it so the model
|
|
26
|
+
* isn't guessing return shapes. Absent where no TypeScript program can run (the browser today) — a consumer
|
|
27
|
+
* must degrade (guess-and-run) when `services.ToolTypeIndex` is undefined.
|
|
28
|
+
*
|
|
29
|
+
* The result is rebuilt lazily and cached, invalidated when the tool set changes. Tools the source scan
|
|
30
|
+
* can't reach (a `function-tools` function) contribute their types by declaring a `toolContract` string on
|
|
31
|
+
* their registered {@link Tool} — identical in shape to a `ToolContracts` arm; the index splices it off the
|
|
32
|
+
* live registry, so no separate registration step is needed.
|
|
33
|
+
*/
|
|
34
|
+
export interface ToolTypeIndex {
|
|
35
|
+
/** Self-contained type declarations as a `.d.ts` string: the source-derived `ToolContracts` augmentations
|
|
36
|
+
* merged with the arms of every other live tool, plus `declare const tool: ToolProxy` — the overloaded
|
|
37
|
+
* proxy a generator writes `await tool.x(params)` against. */
|
|
38
|
+
dts(): Promise<string>;
|
|
39
|
+
/** Type-check a TypeScript `snippet` against exactly the {@link dts} above — the `tool` proxy ({@link
|
|
40
|
+
* ToolProxy}: each multi-action tool an overload set, so `await tool.x(params)` narrows its result by the
|
|
41
|
+
* params) is in scope. Returns human-readable diagnostics scoped to the snippet ([] means clean). A
|
|
42
|
+
* composer uses it to catch bad tool-call code before running/registering it. */
|
|
43
|
+
check(snippet: string): Promise<string[]>;
|
|
44
|
+
/** Per live tool (that has a contract): the `params`/`result` wire text, flattened from the one contract —
|
|
45
|
+
* a source tool's `ToolContracts` arms (via the source scan) or a source-less tool's `toolContract` string.
|
|
46
|
+
* The single contract is thus also the source of the wire description; the host folds this into the
|
|
47
|
+
* outgoing tool descriptions at the turn's dispatch edge. A tool with only a loose `inputSchema` (no
|
|
48
|
+
* contract) is absent. */
|
|
49
|
+
wireContracts(): Promise<Record<string, { params: string; result: string }>>;
|
|
50
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// ── Vault ─────────────────────────────────────────────────────────────────────
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The primitives a vault backend must implement. Resolution, redaction, and the three
|
|
5
|
+
* low-level store operations the smart `createSecret` policy composes. A backend implements
|
|
6
|
+
* `Vault` (which is `VaultSpec` plus that policy); plugins are handed a `Vault`.
|
|
7
|
+
*/
|
|
8
|
+
export interface VaultSpec {
|
|
9
|
+
/** Resolve ${NAME} placeholders by looking up the named value; throws MissingSecretError for any miss. */
|
|
10
|
+
resolve(ref: string): Promise<string>;
|
|
11
|
+
scrub(text: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Store `value` under exactly `name`, overwriting. The literal write; no reference/dedup logic.
|
|
14
|
+
* An empty `value` removes the key instead — there is no such thing as an empty secret, so the
|
|
15
|
+
* empty string is the removal signal (idempotent: removing an absent name is a no-op).
|
|
16
|
+
*/
|
|
17
|
+
writeSecret(name: string, value: string): Promise<void>;
|
|
18
|
+
/** Whether a secret is stored under this exact name. */
|
|
19
|
+
hasKey(name: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The name a value is already stored under, if any. Optional: backends that can't (or won't)
|
|
22
|
+
* reverse-index omit it, and `createSecret`'s dedup step is skipped.
|
|
23
|
+
*/
|
|
24
|
+
findByValue?(value: string): string | undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface Vault extends VaultSpec {
|
|
28
|
+
/**
|
|
29
|
+
* Store a secret coming (often) from a user via the LLM, where we cannot tell a real value
|
|
30
|
+
* from a key name they typed by mistake. Returns the key name callers MUST reference — not
|
|
31
|
+
* necessarily the `name` requested:
|
|
32
|
+
* - `value` is already a known key name → returns `value` (it was a reference, not a secret)
|
|
33
|
+
* - `value` already stored under another name → returns that name (dedup)
|
|
34
|
+
* - otherwise → writes under `name` and returns `name`
|
|
35
|
+
*/
|
|
36
|
+
createSecret(name: string, value: string): Promise<string>;
|
|
37
|
+
}
|