@asterism-app/builtin-api 1.1.4 → 1.2.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/README.md +2 -24
- package/docs/agents.md +3 -11
- package/docs/resource-creation.md +1 -1
- package/examples/package.json +2 -2
- package/package.json +1 -1
- package/src/records.ts +2 -2
- package/src/runtime.ts +28 -7
package/README.md
CHANGED
|
@@ -1,27 +1,5 @@
|
|
|
1
1
|
# Built-in public API
|
|
2
2
|
|
|
3
|
-
This package
|
|
3
|
+
This package lets plugins participate in the bundled Agent domain without importing its private implementation. The enabled provider supplies the original contracts and behavior at runtime; this package is not a second plugin.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Builtin owns its input admission, conversation history, and Agent execution. An extension owns its business state, external relationships, and presentation contributions. Use this boundary when extending that domain rather than treating the bundled paradigm as a mandatory model for all plugins.
|
|
8
|
-
|
|
9
|
-
Public declarations retain shared runtime identity across consumers. The package is not a second installed plugin and does not grant access to private objects. Generic hosting capabilities belong to the SDK; builtin-specific capabilities belong here when they are intentionally public.
|
|
10
|
-
|
|
11
|
-
## Depend on the implementation provider
|
|
12
|
-
|
|
13
|
-
Develop against compatible SDK and builtin API packages. Development dependencies supply declarations; peer dependencies express the shared provider relationship. Installing the API package does not install or update the builtin implementation that supplies behavior at runtime.
|
|
14
|
-
|
|
15
|
-
Import original contracts so extensions compose with the provider's operations rather than recreate them by convention. Validate the integration in an application with the intended provider enabled.
|
|
16
|
-
|
|
17
|
-
## Build an extension artifact
|
|
18
|
-
|
|
19
|
-
Declare `@asterism-app/builtin-api` as a peer dependency so the standalone builder keeps builtin public imports external throughout the graph. The enabled builtin provider supplies their native ESM modules; a private copy cannot replace its runtime identity.
|
|
20
|
-
|
|
21
|
-
Use `@asterism-app/plugin-build` and an explicit `asterism-plugin-build` build script. Build before adding the package directory to Asterism, then restart. The build writes loaded output into `dist`; source entries remain authoring inputs under `asterism.build`. Rebuild and restart after changes, and validate the delivered package against the intended application and provider rather than treating a successful build as integration acceptance.
|
|
22
|
-
|
|
23
|
-
## Explain integration choices
|
|
24
|
-
|
|
25
|
-
The package includes domain guides and source examples. Prose explains when to submit, prepare, observe, or present work and which participant owns each decision. Types and maintained examples express the concrete contracts and composition.
|
|
26
|
-
|
|
27
|
-
The manual supports users and plugin authors on demand. Tools remain understandable from their own descriptions, guidelines, and schemas without a separate documentation prerequisite.
|
|
5
|
+
Use the [Agent integration guide](docs/agents.md) to decide what belongs in an existing Agent. Read the bundled examples to see how an integration is assembled; use the target release's public source and types for the interface. Generic hosting capabilities live in the SDK.
|
package/docs/agents.md
CHANGED
|
@@ -6,15 +6,7 @@ The built-in public API lets plugins integrate with existing Agents without impo
|
|
|
6
6
|
|
|
7
7
|
Use the public Agent boundary when the work belongs in an existing Agent conversation. A plugin that needs its own execution model can instead compose host capabilities without adopting that conversation model.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## Build against the enabled provider
|
|
12
|
-
|
|
13
|
-
Declare `@asterism-app/builtin-api` as a peer dependency. The builder then keeps builtin API imports external in the completed artifact, including contracts, runtime helpers, and renderer exports reached through other modules of the plugin. A development dependency supplies the authoring declarations; neither declaration activates builtin.
|
|
14
|
-
|
|
15
|
-
Build explicitly with `asterism-plugin-build` before adding the package directory to Asterism, then restart. The build writes loaded output into `dist`; source entries belong in `asterism.build`. A source checkout and a distributed package use the same loading contract. Rebuilding does not replace a graph already running in the application.
|
|
16
|
-
|
|
17
|
-
Binding to the provider's native ESM exports preserves the original operation declarations and renderer services. A consumer-local copy is not a fallback when builtin is disabled or unavailable. Validate with the intended provider enabled; successful typechecking or artifact generation alone does not establish that integration.
|
|
9
|
+
Follow the target release's public domain exports into its declarations and the shipped integrations. Import those same contracts and verify with the provider enabled; a copied declaration is not a fallback for a missing provider.
|
|
18
10
|
|
|
19
11
|
## Make messages readable and attributable
|
|
20
12
|
|
|
@@ -22,7 +14,7 @@ Sender attribution explains where input came from independently of the Agent tha
|
|
|
22
14
|
|
|
23
15
|
Keep the body useful as ordinary readable text. For example, a pull-request notification can state the repository, change, author, and URL. The integration understands those facts and should explain them; the receiving Agent's instructions supply its responsibilities. A domain event does not need a private machine payload disguised as a message.
|
|
24
16
|
|
|
25
|
-
|
|
17
|
+
Separate machine-useful event metadata from the explanation shown to people. Put useful tool identifiers where the receiving Agent can use them; keep the visible message readable without them. If the received content already explains the event, avoid repeating it.
|
|
26
18
|
|
|
27
19
|
Use retained attachments when the message must preserve submitted bytes. Use file references when the message should carry an address for later consumption. Forwarding an address does not mean its content has been read or captured.
|
|
28
20
|
|
|
@@ -80,7 +72,7 @@ Keep preparation deterministic within the captured request environment. Changes
|
|
|
80
72
|
|
|
81
73
|
## Transform model context without rewriting history
|
|
82
74
|
|
|
83
|
-
|
|
75
|
+
Use context transforms to shape what a particular request needs, not to change the recorded facts. Keep tool calls and results paired. Treat earlier transforms as part of the input, and make the result deterministic within the captured request so unchanged context can stay reusable.
|
|
84
76
|
|
|
85
77
|
Provenance accompanies the model items but is not sent to the model. Preserve a part's original identity only when forwarding that part. Synthetic or replaced parts do not claim its provenance. Treat a recall ticket as an address, not authority: resolve it on the calling Agent's request path and return the original content as a new tool result. Projection changes neither the saved timeline nor user-facing history.
|
|
86
78
|
|
|
@@ -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.
|
|
7
|
+
Build on the original public creation contract rather than creating a parallel initialization path. Give the Agent the choices that express the user's intent; adapt them when the domain needs a different representation or can derive remaining values. For example, a short note can be enough input to create 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
|
|
package/examples/package.json
CHANGED
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"react-intl": "^12.1.4"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@asterism-app/sdk": "2.
|
|
19
|
-
"@asterism-app/builtin-api": "1.
|
|
18
|
+
"@asterism-app/sdk": "2.4.0",
|
|
19
|
+
"@asterism-app/builtin-api": "1.2.0",
|
|
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
package/src/records.ts
CHANGED
|
@@ -14,8 +14,8 @@ export const Execution = defineRecord(builtin.name("agent.execution"), {
|
|
|
14
14
|
});
|
|
15
15
|
/** Tool inputs keep their model-order position; execution fills the outcome once. */
|
|
16
16
|
export const ToolExecution = defineOperationRecord(builtin.name("agent.tool-execution"), {
|
|
17
|
-
input: modelToolCallBlockSchema.refine(block => !block.complete && block.outcome === null && block.
|
|
18
|
-
"Tool operation input must have complete
|
|
17
|
+
input: modelToolCallBlockSchema.refine(block => !block.complete && block.outcome === null && block.input !== null && block.draft === null,
|
|
18
|
+
"Tool operation input must have complete input and a pending outcome."),
|
|
19
19
|
output: toolOutcomeSchema,
|
|
20
20
|
});
|
|
21
21
|
export const executionRecordIds = [Execution.id, ToolExecution.id];
|
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:
|
|
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:
|
|
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
|
|
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
|
-
|
|
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
|
|
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 },
|