@matatbread/matbot-core 0.2.9 → 0.3.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 CHANGED
@@ -4,7 +4,7 @@
4
4
  "node",
5
5
  "browser"
6
6
  ],
7
- "version": "0.2.9",
7
+ "version": "0.3.0",
8
8
  "engines": {
9
9
  "node": ">=24.0.0"
10
10
  },
@@ -35,7 +35,7 @@
35
35
  "access": "public"
36
36
  },
37
37
  "dependencies": {
38
- "@matatbread/matbot-plugin-api": "^0.2.9"
38
+ "@matatbread/matbot-plugin-api": "^0.3.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "typescript": "^6.0.3"
package/src/about.ts CHANGED
@@ -1,8 +1,8 @@
1
- import type { Tool, ToolExecutor, ToolResultOf, ToolContext } from '@matatbread/matbot-plugin-api';
1
+ import type { Tool, ToolExecutor, ToolContract, ToolResultOf, ToolContext } from '@matatbread/matbot-plugin-api';
2
2
 
3
3
  declare module '@matatbread/matbot-plugin-api' {
4
- interface ToolResults {
5
- about_matbot: { version: string; about: string };
4
+ interface ToolContracts {
5
+ about_matbot: ToolContract<{ version: string; about: string }, Record<string, never>>;
6
6
  }
7
7
  }
8
8
 
@@ -27,11 +27,7 @@ export function createAboutMatbotTool(version: string): Tool<ToolResultOf<'about
27
27
  description:
28
28
  'Report what you are running: the matbot harness version and a one-line description. Use it when ' +
29
29
  'asked what version of matbot this is, or for an "about" of the harness itself (distinct from the ' +
30
- 'plugin tool, which lists loaded plugins).\n\n' +
31
- 'Parameters (TypeScript):\n' +
32
- '```ts\n' +
33
- '{} // -> { version, about }\n' +
34
- '```',
30
+ 'plugin tool, which lists loaded plugins).',
35
31
  inputSchema: { type: 'object', properties: {} },
36
32
  executor,
37
33
  };
@@ -5,6 +5,7 @@ import type {
5
5
  } from './types.js';
6
6
  import type { MatbotPlugin } from './plugin.js';
7
7
  import type { HookRegistry } from './hooks.js';
8
+ import type { ToolTypeIndex } from '@matatbread/matbot-plugin-api';
8
9
  import { appendMessage, createMessage } from './session.js';
9
10
  import { contextSwitch, withUsageScope } from '@matatbread/matbot-plugin-api';
10
11
  import { runSession } from './runner.js';
@@ -13,6 +14,11 @@ export interface SessionRunnerDeps {
13
14
  store: Store<Session>;
14
15
  resolveProvider: (name: string) => Promise<{ adapter: ProviderAdapter; config: ProviderConfig } | null>;
15
16
  tools?: ToolRegistry;
17
+ // Resolved live (the service registers after boot): supplies the per-tool wire contract derived from each
18
+ // tool's single contract source (the `ToolContracts` arms, or a source-less tool's `toolContract`), folded
19
+ // into the turn-start tool snapshot's description so the wire carries params/result text. Absent (e.g.
20
+ // browser) ⇒ tools keep their plain description.
21
+ toolTypeIndex?: () => ToolTypeIndex | undefined;
16
22
  hooks?: HookRegistry;
17
23
  systemContext?: SystemContextRegistry;
18
24
  vault?: Vault;
@@ -207,8 +213,19 @@ export function createSessionRunner(deps: SessionRunnerDeps): SessionRunner {
207
213
 
208
214
  const ac = new AbortController();
209
215
  s.ac = ac;
216
+ // Fold each tool's wire contract — the `params`/`result` text flattened from its single contract
217
+ // (a source tool's ToolContracts arms, or a source-less tool's `toolContract`) — into its description
218
+ // for this turn, so the model reasons about the real TS shapes, not just the loose inputSchema.
219
+ // Derived here because `services`/ToolTypeIndex are live at dispatch. Tools with only a loose
220
+ // inputSchema (no contract) are left as-is; absent ToolTypeIndex (browser) ⇒ plain descriptions.
221
+ const wire = await deps.toolTypeIndex?.()?.wireContracts();
210
222
  const toolMap = deps.tools !== undefined
211
- ? new Map<string, Tool>(deps.tools.list().map(t => [t.name, t]))
223
+ ? new Map<string, Tool>(deps.tools.list().map(t => {
224
+ const wc = wire?.[t.name];
225
+ return [t.name, wc !== undefined
226
+ ? { ...t, description: `${t.description}\n\nTypeScript:\n params: ${wc.params}\n result: ${wc.result}` }
227
+ : t];
228
+ }))
212
229
  : undefined;
213
230
 
214
231
  try {
@@ -1,8 +1,8 @@
1
- import type { Tool, ToolExecutor, ToolResultOf, ToolContext, MatbotMachine } from '@matatbread/matbot-plugin-api';
1
+ import type { Tool, ToolExecutor, ToolContract, ToolResultOf, ToolContext, MatbotMachine } from '@matatbread/matbot-plugin-api';
2
2
 
3
3
  declare module '@matatbread/matbot-plugin-api' {
4
- interface ToolResults {
5
- single_turn: { text: string }; // the consulted provider's reply text
4
+ interface ToolContracts {
5
+ single_turn: ToolContract<{ text: string }, { provider?: string; prompt: string; system?: string }>; // the consulted provider's reply text
6
6
  }
7
7
  }
8
8
 
@@ -53,11 +53,7 @@ export function createSingleTurnTool(services: MatbotMachine): Tool<ToolResultOf
53
53
  'back its text. Use it to consult a different model — e.g. a second, ' +
54
54
  'different-lineage model critiquing your draft, or any generation that should run on a specific ' +
55
55
  'provider. `provider` is OPTIONAL: omit it to run on the current conversation\'s model, or name ' +
56
- 'a configured provider to switch models (list or add providers with the provider tool).\n\n' +
57
- 'Parameters (TypeScript):\n' +
58
- '```ts\n' +
59
- '{ provider?: string; prompt: string; system?: string } // -> { text }\n' +
60
- '```',
56
+ 'a configured provider to switch models (list or add providers with the provider tool).',
61
57
  inputSchema: {
62
58
  type: 'object',
63
59
  required: ['prompt'],