@intentface/latch-agent-builder 0.9.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Intentface
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # @intentface/latch-agent-builder
2
+
3
+ Agents defined as **data**, plus the meta-agent that writes that data. Ship a product where users create and edit their own agents in a chat, without deploying code.
4
+
5
+ ## What it does
6
+
7
+ - **`AgentRecordSchema`** (`@intentface/latch-agent-builder/record`) — one zod schema for what an agent *is*: name, scope, instructions, model, connections, and capability flags under `exec` (sandbox, memory, authored tools, reasoning effort). The model that writes a record, the editor a user types into, and the validator that guards the save all speak this one shape. The subpath is zod-only and browser-safe, so a form can import it.
8
+ - **`normalizeAgentRecord` / `parseAgentRecord`** — the canonical form: name normalization, trimming, deduped memory targets, dropped blanks. Cross-field rules live in the schema, so an org-scoped memory config on a user-scoped agent is rejected once, not in three places.
9
+ - **`createAgentBuilder`** — the meta-agent. It reads the host's models, connections and chat history to make grounded proposals, then creates and updates agents through a host-supplied store. Mutations are gated with `user-approval`, so a user sees the exact spec before it persists.
10
+ - **`AgentBuilderStore`** — the storage seam. `@intentface/latch-drizzle` ships an implementation; a host with its own tables can satisfy it directly.
11
+ - **`AgentBuilderExtension`** — the feature seam. Evals, tool authoring, memory schemas and connection management plug in as extensions, so a host without the feature gets a builder that never mentions it.
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { createAgentBuilder } from "@intentface/latch-agent-builder";
17
+
18
+ const builder = createAgentBuilder<Principal>({
19
+ model,
20
+ // Lazy and per-principal, so the composition root has no import cycle.
21
+ deps: async (principal) => ({ runtime, store, models, connections }),
22
+ extensions: [evalsExtension, toolAuthoringExtension],
23
+ });
24
+ ```
25
+
26
+ Register it like any other agent, and the records it writes resolve into live agents through the store.
27
+
28
+ ## Where it fits
29
+
30
+ Sits on `@intentface/latch-core` — the records it produces become agent factories the runtime can run. Pair it with `@intentface/latch-drizzle` for the store.
@@ -0,0 +1,105 @@
1
+ import type { AgentFactory, AgentMeta, Runtime } from "@intentface/latch-core";
2
+ import type { LanguageModel } from "ai";
3
+ import type { AgentBuilderExtension } from "./extension";
4
+ import type { AgentBuilderStore } from "./store";
5
+ /** A model the builder may assign to an agent (from the host's catalog). */
6
+ export interface ModelChoice {
7
+ id: string;
8
+ label?: string;
9
+ provider?: string;
10
+ reasoning?: boolean;
11
+ }
12
+ /** A connection the builder may wire to an agent. */
13
+ export interface ConnectionChoice {
14
+ name: string;
15
+ kind?: string;
16
+ authorized?: boolean;
17
+ }
18
+ /** The live host services the builder's tools run against, per principal. */
19
+ export interface AgentBuilderDeps<P> {
20
+ runtime: Pick<Runtime<P>, "listAgents" | "listChats" | "loadHistory" | "runAgent" | "schedule" | "listSchedules" | "unschedule">;
21
+ store: AgentBuilderStore<P>;
22
+ /** The host's model catalog (assignable model ids). */
23
+ models: ModelChoice[];
24
+ /** Connections the caller can wire to an agent. */
25
+ listConnections: (principal: P) => Promise<ConnectionChoice[]>;
26
+ /** Enumerate the tools a set of connections exposes, for this caller. */
27
+ connectionTools: (principal: P, names: string[]) => Promise<{
28
+ name: string;
29
+ description: string;
30
+ }[]>;
31
+ }
32
+ /**
33
+ * What THIS host actually wires for each optional agent capability — so the
34
+ * builder's prompt only offers what exists, and save_agent rejects the rest
35
+ * instead of persisting silent no-op flags. Every capability defaults to
36
+ * supported (backwards compatible for hosts that wire everything).
37
+ * `defaultTools` may carry a host-specific description of what the flag
38
+ * grants (rendered in the prompt verbatim).
39
+ */
40
+ export interface CapabilitySupport {
41
+ sandbox?: boolean;
42
+ providerWebTools?: boolean;
43
+ renderTools?: boolean;
44
+ defaultTools?: boolean | {
45
+ description: string;
46
+ };
47
+ /**
48
+ * Whether the host honors the save-time write-approval waiver
49
+ * (`preApprovedWrites`). Only meaningful on hosts that gate writes; a host
50
+ * with ungated writes should declare it unsupported so the flag can't be
51
+ * saved as a no-op.
52
+ */
53
+ preApprovedWrites?: boolean | {
54
+ description: string;
55
+ };
56
+ /**
57
+ * Whether this host composes a memory provider (`exec.memory`). Opt-IN like
58
+ * `preApprovedWrites`: a host without memory must not let the builder save a
59
+ * memory config nothing will ever read.
60
+ */
61
+ memory?: boolean | {
62
+ description: string;
63
+ };
64
+ }
65
+ export interface AgentBuilderConfig<P, RuntimeContext = unknown> {
66
+ /** The builder's own model — a value, or a per-request factory (e.g. per-tenant catalogs). */
67
+ model: LanguageModel | ((ctx: {
68
+ context: RuntimeContext;
69
+ principal: P;
70
+ }) => LanguageModel | Promise<LanguageModel>);
71
+ /**
72
+ * Lazy host services, resolved per turn. Lazy so the host's composition
73
+ * root can import this package without a static import cycle.
74
+ */
75
+ deps: (principal: P) => Promise<AgentBuilderDeps<P>>;
76
+ /** Code-declared agent names save_agent must refuse to overwrite (host statics). */
77
+ reservedNames?: string[];
78
+ /** Which optional agent capabilities this host wires (default: all). */
79
+ capabilities?: CapabilitySupport;
80
+ /**
81
+ * Offer schedule tools (schedule_agent / list_schedules / unschedule_agent)
82
+ * so the builder can put agents on a cron cadence. Default true — the
83
+ * runtime always has the schedule API; disable if the host runs no cron
84
+ * driver (nothing would ever fire) or supplies richer schedule tools of its
85
+ * own via an extension. delete_agent's schedule cascade runs either way.
86
+ */
87
+ scheduling?: boolean;
88
+ /** Optional feature sets: evals, tool authoring, … */
89
+ extensions?: AgentBuilderExtension<P>[];
90
+ /**
91
+ * Interval (ms) for test_agent's progress heartbeat data part
92
+ * (`data-test-agent-progress`) while the nested test run executes. The
93
+ * heartbeat keeps idle-timeout proxies from killing the chat stream during
94
+ * a minutes-long test and doubles as live progress. Default 10s.
95
+ */
96
+ testHeartbeatMs?: number;
97
+ /** Picker metadata override. */
98
+ meta?: AgentMeta;
99
+ }
100
+ /**
101
+ * Create the Agent Builder as a standard agent factory for the host's
102
+ * registry: `agents: { "agent-builder": createAgentBuilder({...}) }`.
103
+ */
104
+ export declare function createAgentBuilder<P, RuntimeContext = unknown>(config: AgentBuilderConfig<P, RuntimeContext>): AgentFactory<P, RuntimeContext>;
105
+ //# sourceMappingURL=agent-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-builder.d.ts","sourceRoot":"","sources":["../src/agent-builder.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAc,MAAM,wBAAwB,CAAC;AAC3F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACxC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AA4BjD,4EAA4E;AAC5E,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAA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