@collegium/sdk 0.0.1-beta.22 → 0.0.1-beta.24

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The authoring surface for [Collegium](https://collegium.sh) plugins.
4
4
 
5
- A plugin is a directory of TypeScript. The deployment mounts it, compiles it at boot, and grants it to the agents that need it. The layout declares the contents: `src/config.ts` declares settings and storage, each `src/tools/<name>.ts` declares one tool named by its filename, and each `src/skills/<name>.md` ships one skill.
5
+ A plugin is a directory of TypeScript. The deployment mounts it, compiles it at boot, and grants it to the agents that need it. The layout declares the contents: `src/config.ts` declares settings and storage, each `src/tools/<name>.ts` declares one tool named by its filename, and each `src/skills/<name>/` ships one skill as `SKILL.md` plus any `references/<name>.md` beside it.
6
6
 
7
7
  ```sh
8
8
  npm install @collegium/sdk zod
@@ -48,7 +48,7 @@ export default defineTool({
48
48
  });
49
49
  ```
50
50
 
51
- A tool with `approval` always stops for a human, who sees the full payload before it runs; one without never gates. The channel and the trace disclose both, line by line. `execute` returns the text the model reads, and raises the two failures a tool controls through `err`: `invalidArguments` continues the turn, `unresolved` ends it as an unconfirmed side effect.
51
+ Every tool states its gate: `approval` is required, and a tool whose `approval` is a function always stops for a human, who sees the full payload before it runs, while one declaring `approval: null` never gates. Omitting the key refuses the plugin at boot. `approval` may be `async`, and receives `settings` and each collection's reads (`findById`, `findFirst`, `findMany`) beside `args`. A tool that acts on a stored record can then show the approver the record itself. The channel and the trace disclose both, line by line. `execute` returns the text the model reads, and raises the two failures a tool controls through `err`: `invalidArguments` continues the turn, `unresolved` ends it as an unconfirmed side effect.
52
52
 
53
53
  **Storage.** Each declared collection is a set of records: the schema's output plus `id`, `createdAt`, and `updatedAt`, which the store stamps. The handle has `create`, `findMany`, `findFirst`, `findById`, `updateById`, and `deleteById`. `create` takes the schema's input with an optional `id`, minting a cuid2 when none is given. `findMany` with no argument lists everything; with a `where` over the schema's top-level scalar fields and `id` — a value for equality, `{ in: [...] }` for membership, `{ contains: text }` for a case-insensitive substring on a string — and an optional `limit`, it filters. `findFirst` takes the same `where` and returns the earliest match or `null`. Field names and value types come from the schema, so a bad query does not compile.
54
54
 
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { c as ToolTurnScope, d as defineConfig, i as defineTool, n as ToolContext, o as ToolApprovalPayload, s as ToolDisclosure, t as PluginTool, u as Register } from "./tool-CcZsVMw2.js";
2
- export { type PluginTool, type Register, type ToolApprovalPayload, type ToolContext, type ToolDisclosure, type ToolTurnScope, defineConfig, defineTool };
1
+ import { a as defineTool, c as ToolDisclosure, d as Register, f as defineConfig, l as ToolTurnScope, n as PluginTool, r as ToolContext, s as ToolApprovalPayload, t as ApprovalContext } from "./tool-0g77wWJM.js";
2
+ export { type ApprovalContext, type PluginTool, type Register, type ToolApprovalPayload, type ToolContext, type ToolDisclosure, type ToolTurnScope, defineConfig, defineTool };
package/dist/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as PluginToolFailureError, c as ToolTurnScope, l as PluginConfig, r as ToolContextFor } from "./tool-CcZsVMw2.js";
1
+ import { i as ToolContextFor, l as ToolTurnScope, o as PluginToolFailureError, u as PluginConfig } from "./tool-0g77wWJM.js";
2
2
  import { z } from "zod";
3
3
  //#region src/testing.d.ts
4
4
  /** `settings` as the declared schema accepts them, so defaults apply as they do at boot; `turn` overrides the four facts */
@@ -64,12 +64,14 @@ type ToolApprovalPayload = {
64
64
  };
65
65
  /**
66
66
  * A durable record's disclosure (§3.6), returned by the tool that created it; the turn writes the
67
- * event and the trace lines. `reference` names the record for later reads, e.g. a memory id.
67
+ * event the trace reads back. `reference` names the record for later reads, e.g. a memory id.
68
68
  */
69
69
  type ToolDisclosure = {
70
70
  readonly body: string;
71
71
  readonly description: string;
72
72
  readonly reference: string;
73
+ /** the reference of the record this one replaced in the same step, which no longer resolves (§3.6) */
74
+ readonly revisionOf?: string;
73
75
  readonly supersededDescriptions?: readonly string[];
74
76
  };
75
77
  declare namespace ToolFailure {
@@ -105,6 +107,18 @@ declare namespace ToolFailure {
105
107
  type Any = Exception | InvalidArguments | Timeout | UnknownTool | Unresolved;
106
108
  }
107
109
  type ToolFailure = ToolFailure.Any;
110
+ /** the methods of a storage collection that leave the store as they found it: all of storage an approval render reaches (§3.4) */
111
+ type ToolStorageReadMethod = 'findById' | 'findFirst' | 'findMany';
112
+ /**
113
+ * What an approval render receives, derived from what `execute` receives (§3.4): the settings where
114
+ * the context carries them, and of each storage handle only its read half — no service, no write,
115
+ * and no turn.
116
+ */
117
+ type ToolApprovalContext<TContext> = Pick<TContext, Extract<keyof TContext, 'settings'>> & (TContext extends {
118
+ readonly storage: infer TStorage;
119
+ } ? {
120
+ readonly storage: { readonly [K in keyof TStorage]: Pick<TStorage[K], Extract<keyof TStorage[K], ToolStorageReadMethod>>; };
121
+ } : unknown);
108
122
  //#endregion
109
123
  //#region ../core/src/plugins/plugins.errors.d.ts
110
124
  /** what `err.invalidArguments` and `err.unresolved` throw; the perimeter wrapper catches it and nothing else */
@@ -113,41 +127,6 @@ declare class PluginToolFailureError extends Error {
113
127
  constructor(failure: ToolFailure.InvalidArguments | ToolFailure.Unresolved);
114
128
  }
115
129
  //#endregion
116
- //#region ../core/src/plugins/plugins.types.d.ts
117
- /** what a plugin tool body may return: the text alone, or the text beside a durable record's disclosure and the line later turns replay (§3.4) */
118
- type PluginToolOutput = string | {
119
- readonly disclosure?: ToolDisclosure;
120
- readonly replay?: string;
121
- readonly text: string;
122
- };
123
- /**
124
- * The two failures a tool body may raise itself — the rest of the taxonomy (§7.1) is the
125
- * framework's to raise. Each throws; the perimeter wrapper maps the throw into the taxonomy.
126
- */
127
- type PluginToolErr = {
128
- /** the arguments were rejected — returned to the model as the tool result; the turn continues */
129
- invalidArguments(message: string): never;
130
- /** a committed side effect whose outcome cannot be established; the turn ends stating the ambiguity */
131
- unresolved(message: string): never;
132
- };
133
- /** one tool as a plugin declares it: the framework's tool minus `budgetExempt` and `isAvailableWith`, returning plain output */
134
- type PluginToolDeclaration<TContext, TParams extends z.ZodType> = {
135
- /** present ⇒ the tool always gates (§5); renders the payload the approver reads and cannot decline */
136
- approval?(args: z.infer<TParams>): ToolApprovalPayload;
137
- /** may run alongside the other concurrent calls of one completion: a read that touches nothing another call in the batch does */
138
- readonly concurrent?: boolean;
139
- readonly description: string;
140
- execute(args: z.infer<TParams>, context: TContext): Promisable<PluginToolOutput>;
141
- readonly parameters: TParams;
142
- /** §7.2 — whether a timed-out call may be reported to the model as a plain failure; false ends the turn as unconfirmable */
143
- readonly retryable?: boolean;
144
- /** a later result of any supersedable tool in the same turn replaces this one's text with its replay line, past the retained few (§3.8) */
145
- readonly supersedable?: boolean;
146
- readonly timeoutMs?: number;
147
- /** §8.1 — the one-line summary beside the name in the status post; absent shows the name alone */
148
- traceDetail?(args: z.infer<TParams>): string;
149
- };
150
- //#endregion
151
130
  //#region ../core/src/toolsets/storage/collection-query.types.d.ts
152
131
  /** the JSON scalars a query may compare; an object, array, or date field is not queryable */
153
132
  type Scalar = boolean | null | number | string;
@@ -226,6 +205,47 @@ type ToolsetContext<TServices extends ServicesDeclaration = EmptyDeclaration, TS
226
205
  readonly settings: z.infer<TSettings>;
227
206
  } : unknown);
228
207
  //#endregion
208
+ //#region ../core/src/plugins/plugins.types.d.ts
209
+ /** what a plugin tool body may return: the text alone, or the text beside a durable record's disclosure and the line later turns replay (§3.4) */
210
+ type PluginToolOutput = string | {
211
+ readonly disclosure?: ToolDisclosure;
212
+ readonly replay?: string;
213
+ readonly text: string;
214
+ };
215
+ /**
216
+ * The two failures a tool body may raise itself — the rest of the taxonomy (§7.1) is the
217
+ * framework's to raise. Each throws; the perimeter wrapper maps the throw into the taxonomy.
218
+ */
219
+ type PluginToolErr = {
220
+ /** the arguments were rejected — returned to the model as the tool result; the turn continues */
221
+ invalidArguments(message: string): never;
222
+ /** a committed side effect whose outcome cannot be established; the turn ends stating the ambiguity */
223
+ unresolved(message: string): never;
224
+ };
225
+ /** one tool as a plugin declares it: the framework's tool minus `budgetExempt` and `isAvailableWith`, returning plain output */
226
+ type PluginToolDeclaration<TContext, TParams extends z.ZodType> = {
227
+ /**
228
+ * The payload the approver reads, or `null` for a tool that does not gate. Required, unlike the
229
+ * framework's own optional field: a framework toolset is read as source by whoever maintains it,
230
+ * while a plugin's source may not be in this repository at all, so an omitted field cannot be
231
+ * told from a forgotten one (§3.14). A function ⇒ the tool always gates (§3.7) and cannot decline;
232
+ * it may read the settings and the stored records the call acts on (§3.4).
233
+ */
234
+ approval: ((args: z.infer<TParams>, context: ToolApprovalContext<TContext>) => Promisable<ToolApprovalPayload>) | null;
235
+ /** may run alongside the other concurrent calls of one completion: a read that touches nothing another call in the batch does */
236
+ readonly concurrent?: boolean;
237
+ readonly description: string;
238
+ execute(args: z.infer<TParams>, context: TContext): Promisable<PluginToolOutput>;
239
+ readonly parameters: TParams;
240
+ /** §7.2 — whether a timed-out call may be reported to the model as a plain failure; false ends the turn as unconfirmable */
241
+ readonly retryable?: boolean;
242
+ /** a later result of any supersedable tool in the same turn replaces this one's text with its replay line, past the retained few (§3.8) */
243
+ readonly supersedable?: boolean;
244
+ readonly timeoutMs?: number;
245
+ /** §8.1 — the one-line summary beside the name in the status post; absent shows the name alone */
246
+ traceDetail?(args: z.infer<TParams>): string;
247
+ };
248
+ //#endregion
229
249
  //#region src/tool.d.ts
230
250
  /** what `execute` receives under a config: its settings and storage, the failure raisers, and the four facts of the turn */
231
251
  type ToolContextFor<TConfig extends PluginConfig> = ToolsetContext<EmptyDeclaration, TConfig['settings'], TConfig['storage']> & {
@@ -233,8 +253,12 @@ type ToolContextFor<TConfig extends PluginConfig> = ToolsetContext<EmptyDeclarat
233
253
  };
234
254
  /** the context under the registered config: what every tool file's `execute` receives */
235
255
  type ToolContext = ToolContextFor<RegisteredConfig>;
256
+ /** what `approval` receives under a config: the settings, and of each collection only the methods that read (§3.4) */
257
+ type ApprovalContextFor<TConfig extends PluginConfig> = ToolApprovalContext<ToolContextFor<TConfig>>;
258
+ /** the approval context under the registered config: what every tool file's `approval` receives */
259
+ type ApprovalContext = ApprovalContextFor<RegisteredConfig>;
236
260
  type PluginTool<TParams extends z.ZodType> = PluginToolDeclaration<ToolContext, TParams>;
237
261
  /** identity at runtime; what it is for is typing `args` from `parameters` across the whole declaration */
238
262
  declare function defineTool<TParams extends z.ZodType>(tool: PluginTool<TParams>): PluginTool<TParams>;
239
263
  //#endregion
240
- export { PluginToolFailureError as a, ToolTurnScope as c, defineConfig as d, defineTool as i, PluginConfig as l, ToolContext as n, ToolApprovalPayload as o, ToolContextFor as r, ToolDisclosure as s, PluginTool as t, Register as u };
264
+ export { defineTool as a, ToolDisclosure as c, Register as d, defineConfig as f, ToolContextFor as i, ToolTurnScope as l, PluginTool as n, PluginToolFailureError as o, ToolContext as r, ToolApprovalPayload as s, ApprovalContext as t, PluginConfig as u };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@collegium/sdk",
3
3
  "type": "module",
4
- "version": "0.0.1-beta.22",
4
+ "version": "0.0.1-beta.24",
5
5
  "description": "Write a Collegium plugin: declare a toolset with its tools, settings, storage, and skills.",
6
6
  "license": "AGPL-3.0-only",
7
7
  "homepage": "https://collegium.sh",