@collegium/sdk 0.0.1-beta.11 → 0.0.1-beta.13

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
@@ -50,7 +50,7 @@ export default defineTool({
50
50
 
51
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.
52
52
 
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`, `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. Field names and value types come from the schema, so a bad query does not compile.
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
 
55
55
  **Testing.** `@collegium/sdk/testing` builds the context `execute` receives, over in-memory storage that validates and parses as the deployment's store does. Pass your config; settings go through your schema, so defaults apply.
56
56
 
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-Vqe6D48m.js";
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-CZZZNBSg.js";
2
2
  export { 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-Vqe6D48m.js";
1
+ import { a as PluginToolFailureError, c as ToolTurnScope, l as PluginConfig, r as ToolContextFor } from "./tool-CZZZNBSg.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 */
package/dist/testing.js CHANGED
@@ -137,6 +137,12 @@ function createCollection(schema) {
137
137
  },
138
138
  deleteById: (id) => Promise.try(() => rows.delete(id)),
139
139
  findById: (id) => Promise.try(() => rows.has(id) ? toRecord(rows.get(id)) : null),
140
+ findFirst: (query = {}) => {
141
+ return Promise.try(() => applyCollectionQuery([...rows.values()].map(toRecord), {
142
+ ...query,
143
+ limit: 1
144
+ })[0] ?? null);
145
+ },
140
146
  findMany: (query = {}) => Promise.try(() => applyCollectionQuery([...rows.values()].map(toRecord), query)),
141
147
  updateById: (id, patch) => {
142
148
  return Promise.try(() => {
@@ -129,7 +129,7 @@ type PluginToolErr = {
129
129
  /** a committed side effect whose outcome cannot be established; the turn ends stating the ambiguity */
130
130
  unresolved(message: string): never;
131
131
  };
132
- /** one tool as a plugin declares it: the framework's tool minus `budgetExempt`, returning plain output */
132
+ /** one tool as a plugin declares it: the framework's tool minus `budgetExempt` and `isAvailableWith`, returning plain output */
133
133
  type PluginToolDeclaration<TContext, TParams extends z.ZodType> = {
134
134
  /** present ⇒ the tool always gates (§5); renders the payload the approver reads and cannot decline */
135
135
  approval?(args: z.infer<TParams>): ToolApprovalPayload;
@@ -160,10 +160,12 @@ type CollectionFieldCondition<TField> = ([Extract<TField, string>] extends [neve
160
160
  };
161
161
  /** an AND over field conditions, keyed by the record's own scalar fields */
162
162
  type CollectionWhere<TRecord> = { readonly [K in keyof QueryableFields<TRecord>]?: CollectionFieldCondition<QueryableFields<TRecord>[K]>; };
163
- type CollectionQuery<TRecord> = {
164
- readonly limit?: number;
163
+ type CollectionFilter<TRecord> = {
165
164
  readonly where?: CollectionWhere<TRecord>;
166
165
  };
166
+ type CollectionQuery<TRecord> = CollectionFilter<TRecord> & {
167
+ readonly limit?: number;
168
+ };
167
169
  //#endregion
168
170
  //#region ../core/src/toolsets/storage/collection.types.d.ts
169
171
  /** what the store stamps on every record beside the declared fields; a schema may not declare any of these */
@@ -185,6 +187,8 @@ type ToolsetCollection<TSchema extends z.ZodObject> = {
185
187
  }): Promise<CollectionRecord<z.output<TSchema>>>;
186
188
  deleteById(id: string): Promise<boolean>;
187
189
  findById(id: string): Promise<CollectionRecord<z.output<TSchema>> | null>;
190
+ /** the earliest-inserted record the query matches, or null; without a query, the earliest record */
191
+ findFirst(query?: CollectionFilter<CollectionRecord<z.output<TSchema>>>): Promise<CollectionRecord<z.output<TSchema>> | null>;
188
192
  /** without a query, every record in insertion order */
189
193
  findMany(query?: CollectionQuery<CollectionRecord<z.output<TSchema>>>): Promise<CollectionRecord<z.output<TSchema>>[]>;
190
194
  /** the patch merged over the stored fields and the whole parsed again, so a patch cannot leave an invalid record */
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.11",
4
+ "version": "0.0.1-beta.13",
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",