@asterism-app/builtin-api 1.1.4 → 1.1.5

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.
@@ -4,7 +4,7 @@ A plugin can make its resource available through builtin's model-facing creation
4
4
 
5
5
  ## Reuse creation meaning
6
6
 
7
- Build on the original public creation contract rather than creating a parallel initialization path. A straightforward entry can expose that contract directly. A specialized entry is useful when a model can supply a smaller meaningful input, such as a short note from which the plugin derives a titled document.
7
+ Build on the original public creation contract rather than creating a parallel initialization path. Agent entries receive a parameter object even when there are no fields to supply. Reuse the creation schema directly when it describes an object, or use `inputSchema` and `toInput` to adapt that object to the underlying contract. This lets the domain contract keep inputs like `null` or a number without exposing them as the entire Agent input. An adapter can also expose a smaller meaningful input, such as a short note from which the plugin derives a titled document.
8
8
 
9
9
  Keep that adaptation explainable. It should translate intent into the same domain creation operation, not bypass validation or hide unrelated effects. Descriptions and schemas should make the resulting object's purpose understandable without a manual recipe.
10
10
 
@@ -15,8 +15,8 @@
15
15
  "react-intl": "^12.1.4"
16
16
  },
17
17
  "devDependencies": {
18
- "@asterism-app/sdk": "2.2.1",
19
- "@asterism-app/builtin-api": "1.1.4",
18
+ "@asterism-app/sdk": "2.3.0",
19
+ "@asterism-app/builtin-api": "1.1.5",
20
20
  "@asterism-app/plugin-build": "1.0.1",
21
21
  "typescript": "^7.0.2",
22
22
  "@types/node": "^26.6.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asterism-app/builtin-api",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "Public domain contracts and extensions for Asterism built-in features",
5
5
  "license": "MIT",
6
6
  "author": "Chien Zhang",
package/src/runtime.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { belongsTo, jsonSchema, type CreationContract, type Json, type SessionDirectory } from "@asterism-app/sdk/contracts";
2
+ import { belongsTo, jsonSchema, type CreationContract, type Json, type JsonObject, type SessionDirectory } from "@asterism-app/sdk/contracts";
3
3
  import { defineModule, PluginApiError, type PluginContext, type PluginModule, type ObjectReader, type TopLevelToolContext } from "@asterism-app/sdk/runtime";
4
4
 
5
5
  export { agentServices, registerAgentServices, type AgentServices } from "./agent-services.ts";
@@ -7,6 +7,9 @@ export { defineAgentPreparer, captureAgentPreparers, type AgentPreparation, type
7
7
  export { defineAgentContextTransform, captureAgentContextTransforms,
8
8
  type AgentContextUnit, type AgentContextItem, type AgentContextRequest } from "./context-transform.ts";
9
9
 
10
+ /** The Agent's argument envelope; each entry defines the object's fields. */
11
+ export const agentCreationInputSchema = z.object({}).catchall(jsonSchema);
12
+
10
13
  export interface AgentCreationDescription {
11
14
  readonly id: string;
12
15
  readonly resourceKind: string;
@@ -16,7 +19,7 @@ export interface AgentCreationDescription {
16
19
  }
17
20
  interface Entry {
18
21
  readonly description: AgentCreationDescription;
19
- create(input: Json, context: TopLevelToolContext): ReturnType<TopLevelToolContext["session"]["create"]>;
22
+ create(input: JsonObject, context: TopLevelToolContext): ReturnType<TopLevelToolContext["session"]["create"]>;
20
23
  }
21
24
  type CreationOptions = Parameters<TopLevelToolContext["session"]["create"]>[2];
22
25
  /** Catalogs are isolated by host runtime instance; shared public exports do not mix plugin registrations from different hosts. */
@@ -33,25 +36,40 @@ function entry(plugin: PluginContext, id: string): Entry {
33
36
  return value;
34
37
  }
35
38
 
39
+ /** Zod can project object variants as unions and named schemas as local definitions. */
40
+ function describesObject(root: z.core.JSONSchema.BaseSchema): boolean {
41
+ function check(schema: z.core.JSONSchema.BaseSchema, refs: readonly string[] = []): boolean {
42
+ if (schema.type === "object" || schema.allOf?.some(branch => check(branch, refs))) return true;
43
+ const variants = schema.anyOf ?? schema.oneOf;
44
+ if (variants?.length && variants.every(branch => check(branch, refs))) return true;
45
+ const ref = schema.$ref;
46
+ if (!ref?.startsWith("#/$defs/") || refs.includes(ref)) return false;
47
+ const name = ref.slice("#/$defs/".length).replaceAll("~1", "/").replaceAll("~0", "~");
48
+ const definition = root.$defs && Object.hasOwn(root.$defs, name) ? root.$defs[name] : undefined;
49
+ return definition !== undefined && check(definition, [...refs, ref]);
50
+ }
51
+ return check(root);
52
+ }
53
+
36
54
  /** The domain service shared by built-in creation tools and plugins; querying is not a prerequisite for creation. */
37
55
  export const agentCreations = {
38
56
  list(plugin: PluginContext) {
39
57
  return [...directory(plugin).values()].map(({ description: { id, resourceKind, description } }) => ({ id, resourceKind, description }));
40
58
  },
41
59
  inspect(plugin: PluginContext, id: string): AgentCreationDescription { return structuredClone(entry(plugin, id).description); },
42
- create(plugin: PluginContext, id: string, input: Json, context: TopLevelToolContext) {
60
+ create(plugin: PluginContext, id: string, input: JsonObject, context: TopLevelToolContext) {
43
61
  return entry(plugin, id).create(input, context);
44
62
  },
45
63
  };
46
64
 
47
- /** Agent creation entry points are independent domain contributions; they reuse creation input directly or explicitly adapt model input. */
65
+ /** Agent creation entries accept objects. Use an adapter if the underlying creation takes a different input shape. */
48
66
  export function defineAgentCreation<I, S extends Json, O extends Json, A extends Json = Json>(definition: {
49
67
  id: string;
50
68
  description: string;
51
69
  guidelines?: readonly string[];
70
+ } & ({ creation: CreationContract<I & JsonObject, S, O>; inputSchema?: never; toInput?: never; toOptions?: never } | {
52
71
  creation: CreationContract<I, S, O>;
53
- } & ({ inputSchema?: never; toInput?: never; toOptions?: never } | {
54
- inputSchema: z.ZodType<A>;
72
+ inputSchema: z.ZodType<A, JsonObject>;
55
73
  toInput(input: A, context: { object: ObjectReader }): I & Json;
56
74
  toOptions?(input: A, context: { object: ObjectReader }): CreationOptions;
57
75
  })): PluginModule {
@@ -60,7 +78,10 @@ export function defineAgentCreation<I, S extends Json, O extends Json, A extends
60
78
  if (!definition.description.trim()) throw new PluginApiError("invalid_argument", "An Agent creation entry needs a description.");
61
79
  const entries = directory(plugin);
62
80
  if (entries.has(definition.id)) throw new PluginApiError("conflict", `Duplicate Agent creation entry: ${definition.id}`);
63
- const input = jsonSchema.parse(z.toJSONSchema(definition.inputSchema ?? definition.creation.schema, { io: "input" }));
81
+ const projected = z.toJSONSchema(definition.inputSchema ?? definition.creation.schema, { io: "input" });
82
+ if (!describesObject(projected)) throw new PluginApiError("invalid_argument",
83
+ `Agent creation entry ${definition.id} needs an object input schema. Use inputSchema and toInput to adapt other creation inputs.`);
84
+ const input = jsonSchema.parse(projected);
64
85
  const value: Entry = {
65
86
  description: { id: definition.id, resourceKind: definition.creation.resource.kind,
66
87
  description: definition.description, guidelines: [...definition.guidelines ?? []], input },