@domesystems/templates 0.4.3 → 0.4.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/generate.mjs +18 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domesystems/templates",
3
- "version": "0.4.3",
3
+ "version": "0.4.5",
4
4
  "description": "Pull, publish, and run versioned Dome templates.",
5
5
  "repository": {
6
6
  "type": "git",
package/src/generate.mjs CHANGED
@@ -70,10 +70,23 @@ function managedModelReference(manifest, name) {
70
70
  throw new Error(`Managed agent default_model ${name} must name a pool or model.`);
71
71
  }
72
72
 
73
- function agentAttributes(agent, managed) {
73
+ function templateProvenance(manifest) {
74
+ const name = manifest.metadata?.name;
75
+ const version = manifest.metadata?.version;
76
+ if (typeof name !== "string" || !name.trim() || typeof version !== "string" || !version.trim()) {
77
+ throw new Error("template.yaml metadata.name and metadata.version are required to generate deployable Terraform.");
78
+ }
79
+ return {
80
+ "dome.template.name": name,
81
+ "dome.template.version": version,
82
+ };
83
+ }
84
+
85
+ function agentAttributes(agent, managed, provenance) {
74
86
  const lines = [];
75
87
  if (agent.parent) lines.push(attr("parent", `dome_agent.${label(agent.parent)}.name`));
76
- if (agent.metadata) lines.push(attr("metadata", `{ ${Object.entries(agent.metadata).map(([key, value]) => `${q(key)} = ${q(value)}`).join(", ")} }`));
88
+ const metadata = { ...(agent.metadata ?? {}), ...provenance };
89
+ if (Object.keys(metadata).length) lines.push(attr("metadata", `{ ${Object.entries(metadata).map(([key, value]) => `${q(key)} = ${q(value)}`).join(", ")} }`));
77
90
  for (const [key, resource] of [["allowed_pools", "dome_llm_pool"], ["allowed_models", "dome_llm_connection"], ...(!managed ? [["allowed_gateways", "dome_gateway"]] : [])]) {
78
91
  if (agent[key] !== undefined) lines.push(attr(key, `[${agent[key].map((name) => `${resource}.${label(name)}.name`).join(", ")}]`));
79
92
  }
@@ -90,6 +103,7 @@ function agentAttributes(agent, managed) {
90
103
 
91
104
  export function renderDomeTerraform(manifest) {
92
105
  if (!manifest.gateways.length) throw new Error("template.yaml must declare at least one gateway.");
106
+ const provenance = templateProvenance(manifest);
93
107
  const blocks = [];
94
108
  for (const gateway of manifest.gateways) {
95
109
  const gatewayLabel = label(gateway.name);
@@ -99,7 +113,7 @@ export function renderDomeTerraform(manifest) {
99
113
  }
100
114
  for (const connection of manifest.tool_connections) {
101
115
  const auth = connection.auth_method ?? "none";
102
- const lines = [attr("workspace_id", "var.workspace_id"), attr("name", q(connection.name)), attr("protocol", q(required(connection, "protocol", `Tool connection ${connection.name} needs protocol.`))), attr("url", q(required(connection, "url", `Tool connection ${connection.name} needs url.`))), attr("auth_method", q(auth)), attr("credential_type", q(connection.credential_type ?? (auth === "none" ? "none" : "shared")))];
116
+ const lines = [attr("workspace_id", "var.workspace_id"), attr("name", q(connection.name)), attr("protocol", q(required(connection, "protocol", `Tool connection ${connection.name} needs protocol.`))), attr("url", expression(required(connection, "url", `Tool connection ${connection.name} needs url.`))), attr("auth_method", q(auth)), attr("credential_type", q(connection.credential_type ?? (auth === "none" ? "none" : "shared")))];
103
117
  if (connection.managed_header_name) lines.push(attr("managed_header_name", q(connection.managed_header_name)));
104
118
  if (connection.secret_values) lines.push(attr("secret_values", `{ ${Object.entries(connection.secret_values).map(([key, value]) => `${q(key)} = ${expression(value)}`).join(", ")} }`));
105
119
  if (connection.oauth) lines.push(attr("oauth", `jsonencode(${JSON.stringify(connection.oauth)})`));
@@ -118,7 +132,7 @@ export function renderDomeTerraform(manifest) {
118
132
  }
119
133
  for (const agent of manifest.agents) {
120
134
  const agentLabel = label(agent.name); const managed = agent.type === "managed"; const resourceType = managed ? "dome_managed_agent" : "dome_agent";
121
- const lines = [attr("workspace_id", "var.workspace_id"), attr("name", q(agent.name)), ...agentAttributes(agent, managed)];
135
+ const lines = [attr("workspace_id", "var.workspace_id"), attr("name", q(agent.name)), ...agentAttributes(agent, managed, provenance)];
122
136
  if (managed) {
123
137
  if (!agent.system_prompt?.content || !agent.default_model) throw new Error(`Managed agent ${agent.name} needs system_prompt and default_model.`);
124
138
  if (typeof agent.gateway !== "string" || !agent.gateway) throw new Error(`Managed agent ${agent.name} needs gateway.`);