@standardagents/builder 0.39.1 → 0.40.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.
Files changed (43) hide show
  1. package/dist/built-in-routes.js +609 -94
  2. package/dist/built-in-routes.js.map +1 -1
  3. package/dist/client/{ApiKeysView-AH5i-H6j.js → ApiKeysView-DoYvZZ7e.js} +1 -1
  4. package/dist/client/{CenteredContentView-DaBp0K-A.js → CenteredContentView-53PY0cqY.js} +1 -1
  5. package/dist/client/{CompositionView-yY1Q4M23.js → CompositionView-fp-0YnPt.js} +1 -1
  6. package/dist/client/{ConfirmDialog.vue_vue_type_script_setup_true_lang-Bwo5CJzF.js → ConfirmDialog.vue_vue_type_script_setup_true_lang-Cvcagja2.js} +1 -1
  7. package/dist/client/{CopyButton.vue_vue_type_script_setup_true_lang-D0WYwWyA.js → CopyButton.vue_vue_type_script_setup_true_lang-jYvO2v1K.js} +1 -1
  8. package/dist/client/{DataTable.vue_vue_type_script_setup_true_lang-1wwPn2aY.js → DataTable.vue_vue_type_script_setup_true_lang-DQ3Ufa7y.js} +1 -1
  9. package/dist/client/{JsonViewer-Bi8Zdmir.js → JsonViewer-6aaGzutE.js} +1 -1
  10. package/dist/client/{LoginView-BIKahEU6.js → LoginView-DwpCmNw9.js} +1 -1
  11. package/dist/client/{MarketplaceView-DPDPVH68.js → MarketplaceView-Da02L0J5.js} +1 -1
  12. package/dist/client/{Modal.vue_vue_type_script_setup_true_lang-D1_rfOsy.js → Modal.vue_vue_type_script_setup_true_lang-Bi8OjiBf.js} +1 -1
  13. package/dist/client/{ModelModal.vue_vue_type_script_setup_true_lang-DSLeOdxr.js → ModelModal.vue_vue_type_script_setup_true_lang-cYZLOYY7.js} +1 -1
  14. package/dist/client/{ModelsView-Q2WXu1Gw.js → ModelsView-BLlHO9Ud.js} +1 -1
  15. package/dist/client/{PromptEditView-BzA-3n1w.js → PromptEditView-EeNwTDtT.js} +1 -1
  16. package/dist/client/{PromptModal-CJWh_cru.js → PromptModal-BkwrKJ2d.js} +1 -1
  17. package/dist/client/{PromptsView-BezNl-Et.js → PromptsView-D1r7tsLu.js} +1 -1
  18. package/dist/client/{ProvidersView-BuzSKxuT.js → ProvidersView-CmUDl5nM.js} +1 -1
  19. package/dist/client/{ThreadInspectorPane.vue_vue_type_script_setup_true_lang-DOxNp_3C.js → ThreadInspectorPane.vue_vue_type_script_setup_true_lang-cRs3tApQ.js} +1 -1
  20. package/dist/client/{ThreadsView-DPCpZA4J.js → ThreadsView-Bl5fSIO1.js} +1 -1
  21. package/dist/client/{ToolsView-DMjFMAhH.js → ToolsView-DlVEF8-7.js} +1 -1
  22. package/dist/client/{UsersView-B7jXLNQs.js → UsersView-CGlA7a7R.js} +1 -1
  23. package/dist/client/{VariablesView-CF7x0G8g.js → VariablesView-BpYmJL4V.js} +1 -1
  24. package/dist/client/index-CKtIkI0N.js +6 -0
  25. package/dist/client/index.html +1 -1
  26. package/dist/{discovery-DiMJWisl.d.ts → discovery-DZ7fv-b4.d.ts} +3 -2
  27. package/dist/{index-yIcqf7DC.d.ts → index-0NI3m5DR.d.ts} +8 -2
  28. package/dist/index.d.ts +4 -4
  29. package/dist/index.js +1299 -758
  30. package/dist/index.js.map +1 -1
  31. package/dist/packing.d.ts +5 -3
  32. package/dist/packing.js +180 -5
  33. package/dist/packing.js.map +1 -1
  34. package/dist/plugin.d.ts +12 -1
  35. package/dist/plugin.js +299 -19
  36. package/dist/plugin.js.map +1 -1
  37. package/dist/runtime.d.ts +12 -5
  38. package/dist/runtime.js +1009 -750
  39. package/dist/runtime.js.map +1 -1
  40. package/dist/test.d.ts +2 -2
  41. package/dist/{types-Bpe7IANZ.d.ts → types-BMnBYNwn.d.ts} +3 -1
  42. package/package.json +5 -5
  43. package/dist/client/index-eGECJFYe.js +0 -6
package/dist/packing.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { P as PackingAnalysis, a as PackingOptions, b as PackingResult, U as UnpackAnalysis, c as UnpackOptions, d as UnpackResult } from './types-Bpe7IANZ.js';
2
- export { D as DiscoveredPackage } from './types-Bpe7IANZ.js';
3
- export { P as PackageDiscoveryService, d as discoverPackages } from './discovery-DiMJWisl.js';
1
+ import { P as PackingAnalysis, a as PackingOptions, b as PackingResult, U as UnpackAnalysis, c as UnpackOptions, d as UnpackResult } from './types-BMnBYNwn.js';
2
+ export { D as DiscoveredPackage } from './types-BMnBYNwn.js';
3
+ export { P as PackageDiscoveryService, d as discoverPackages } from './discovery-DZ7fv-b4.js';
4
4
  import '@standardagents/spec';
5
5
 
6
6
  /**
@@ -100,6 +100,8 @@ declare class PackingService {
100
100
  * Analyze a nested agent (used as a handoff target).
101
101
  */
102
102
  private analyzeNestedAgent;
103
+ /** Add a hook referenced by an agent or prompt to the packed graph. */
104
+ private analyzeHook;
103
105
  /**
104
106
  * Analyze a model and its fallbacks.
105
107
  */
package/dist/packing.js CHANGED
@@ -238,11 +238,19 @@ async function extractPromptTools(sourceCode) {
238
238
  result.tools.push(element.text);
239
239
  } else if (ts.isObjectLiteralExpression(element)) {
240
240
  result.hasSubpromptConfigs = true;
241
+ let configuredName;
242
+ let implementingAgent;
241
243
  for (const objProp of element.properties) {
242
- if (ts.isPropertyAssignment(objProp) && ts.isIdentifier(objProp.name) && objProp.name.text === "name" && ts.isStringLiteral(objProp.initializer)) {
243
- result.tools.push(objProp.initializer.text);
244
+ if (ts.isPropertyAssignment(objProp) && ts.isIdentifier(objProp.name) && ts.isStringLiteral(objProp.initializer)) {
245
+ if (objProp.name.text === "name") {
246
+ configuredName = objProp.initializer.text;
247
+ } else if (objProp.name.text === "agent") {
248
+ implementingAgent = objProp.initializer.text;
249
+ }
244
250
  }
245
251
  }
252
+ const dependencyName = implementingAgent ?? configuredName;
253
+ if (dependencyName) result.tools.push(dependencyName);
246
254
  }
247
255
  }
248
256
  }
@@ -365,6 +373,106 @@ async function extractAgentPrompts(sourceCode) {
365
373
  visit(sourceFile);
366
374
  return result;
367
375
  }
376
+ async function extractAgentHooks(sourceCode) {
377
+ const ts = await loadTypeScript();
378
+ const sourceFile = ts.createSourceFile(
379
+ "agent.ts",
380
+ sourceCode,
381
+ ts.ScriptTarget.ESNext,
382
+ true
383
+ );
384
+ const arrays = /* @__PURE__ */ new Map();
385
+ const result = {
386
+ hooks: [],
387
+ parentHooks: [],
388
+ parentHookRequirements: []
389
+ };
390
+ const unwrapArray = (expression) => {
391
+ let current = expression;
392
+ while (ts.isParenthesizedExpression(current) || ts.isAsExpression(current) || ts.isSatisfiesExpression(current)) {
393
+ current = current.expression;
394
+ }
395
+ if (ts.isArrayLiteralExpression(current)) return current;
396
+ if (ts.isIdentifier(current)) return arrays.get(current.text) ?? null;
397
+ return null;
398
+ };
399
+ for (const statement of sourceFile.statements) {
400
+ if (!ts.isVariableStatement(statement)) continue;
401
+ for (const declaration of statement.declarationList.declarations) {
402
+ if (ts.isIdentifier(declaration.name) && declaration.initializer) {
403
+ const array = unwrapArray(declaration.initializer);
404
+ if (array) arrays.set(declaration.name.text, array);
405
+ }
406
+ }
407
+ }
408
+ const pushUnique = (target, value) => {
409
+ if (!target.includes(value)) target.push(value);
410
+ };
411
+ function visit(node) {
412
+ if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "defineAgent" && node.arguments.length > 0 && ts.isObjectLiteralExpression(node.arguments[0])) {
413
+ for (const property of node.arguments[0].properties) {
414
+ if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) continue;
415
+ const array = unwrapArray(property.initializer);
416
+ if (!array) continue;
417
+ if (property.name.text === "hooks") {
418
+ for (const element of array.elements) {
419
+ if (ts.isStringLiteral(element)) pushUnique(result.hooks, element.text);
420
+ }
421
+ }
422
+ if (property.name.text === "parentHooks") {
423
+ for (const element of array.elements) {
424
+ if (!ts.isObjectLiteralExpression(element)) continue;
425
+ let hook;
426
+ let reason;
427
+ let stage;
428
+ for (const requirement of element.properties) {
429
+ if (ts.isPropertyAssignment(requirement) && ts.isIdentifier(requirement.name) && ts.isStringLiteral(requirement.initializer)) {
430
+ if (requirement.name.text === "hook") hook = requirement.initializer.text;
431
+ if (requirement.name.text === "reason") reason = requirement.initializer.text;
432
+ if (requirement.name.text === "stage" && (requirement.initializer.text === "before_parent" || requirement.initializer.text === "after_parent")) {
433
+ stage = requirement.initializer.text;
434
+ }
435
+ }
436
+ }
437
+ if (hook) {
438
+ pushUnique(result.parentHooks, hook);
439
+ if (reason) result.parentHookRequirements.push({ hook, reason, stage });
440
+ }
441
+ }
442
+ }
443
+ }
444
+ }
445
+ ts.forEachChild(node, visit);
446
+ }
447
+ visit(sourceFile);
448
+ return result;
449
+ }
450
+ async function extractPromptHooks(sourceCode) {
451
+ const ts = await loadTypeScript();
452
+ const sourceFile = ts.createSourceFile(
453
+ "prompt.ts",
454
+ sourceCode,
455
+ ts.ScriptTarget.ESNext,
456
+ true
457
+ );
458
+ const hooks = [];
459
+ function visit(node) {
460
+ if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "definePrompt" && node.arguments.length > 0 && ts.isObjectLiteralExpression(node.arguments[0])) {
461
+ for (const property of node.arguments[0].properties) {
462
+ if (ts.isPropertyAssignment(property) && ts.isIdentifier(property.name) && property.name.text === "hooks" && ts.isArrayLiteralExpression(property.initializer)) {
463
+ for (const element of property.initializer.elements) {
464
+ if (ts.isStringLiteral(element) && !hooks.includes(element.text)) {
465
+ hooks.push(element.text);
466
+ }
467
+ }
468
+ }
469
+ }
470
+ }
471
+ ts.forEachChild(node, visit);
472
+ }
473
+ visit(sourceFile);
474
+ return hooks;
475
+ }
368
476
  async function extractAgentDescription(sourceCode) {
369
477
  const ts = await loadTypeScript();
370
478
  const sourceFile = ts.createSourceFile(
@@ -604,6 +712,13 @@ var PackingService = class {
604
712
  });
605
713
  const agentSource = fs3.readFileSync(agentFilePath, "utf-8");
606
714
  const agentPrompts = await extractAgentPrompts(agentSource);
715
+ const agentHooks = await extractAgentHooks(agentSource);
716
+ for (const hookId of agentHooks.hooks) {
717
+ await this.analyzeHook(hookId, agentsDir, analysis, false, `agent:${agentName}`);
718
+ }
719
+ for (const hookId of agentHooks.parentHooks) {
720
+ await this.analyzeHook(hookId, agentsDir, analysis, true, `agent:${agentName}`);
721
+ }
607
722
  if (agentPrompts.sideA) {
608
723
  analysis.primaryPrompt = agentPrompts.sideA;
609
724
  await this.analyzePrompt(agentPrompts.sideA, agentsDir, analysis, /* @__PURE__ */ new Set(), `agent:${agentName}`);
@@ -806,6 +921,9 @@ var PackingService = class {
806
921
  }
807
922
  visited.add(`prompt:${promptName}`);
808
923
  const promptSource = fs3.readFileSync(promptFilePath, "utf-8");
924
+ for (const hookId of await extractPromptHooks(promptSource)) {
925
+ await this.analyzeHook(hookId, agentsDir, analysis, false, thisKey);
926
+ }
809
927
  const modelName = await extractPromptModel(promptSource);
810
928
  if (modelName) {
811
929
  await this.analyzeModel(modelName, agentsDir, analysis, visited, thisKey);
@@ -890,6 +1008,13 @@ var PackingService = class {
890
1008
  visited.add(`agent:${agentName}`);
891
1009
  const agentSource = fs3.readFileSync(agentFilePath, "utf-8");
892
1010
  const agentPrompts = await extractAgentPrompts(agentSource);
1011
+ const agentHooks = await extractAgentHooks(agentSource);
1012
+ for (const hookId of agentHooks.hooks) {
1013
+ await this.analyzeHook(hookId, agentsDir, analysis, false, thisKey);
1014
+ }
1015
+ for (const hookId of agentHooks.parentHooks) {
1016
+ await this.analyzeHook(hookId, agentsDir, analysis, true, thisKey);
1017
+ }
893
1018
  if (agentPrompts.sideA) {
894
1019
  await this.analyzePrompt(agentPrompts.sideA, agentsDir, analysis, visited, thisKey);
895
1020
  }
@@ -897,6 +1022,27 @@ var PackingService = class {
897
1022
  await this.analyzePrompt(agentPrompts.sideB, agentsDir, analysis, visited, thisKey);
898
1023
  }
899
1024
  }
1025
+ /** Add a hook referenced by an agent or prompt to the packed graph. */
1026
+ async analyzeHook(hookId, agentsDir, analysis, required, parentKey) {
1027
+ const hookFilePath = await this.findFile(path3.join(agentsDir, "hooks"), hookId);
1028
+ if (!hookFilePath) {
1029
+ const message = `Hook file not found for ID: ${hookId}`;
1030
+ if (required) analysis.errors.push(message);
1031
+ else analysis.warnings.push(message);
1032
+ return;
1033
+ }
1034
+ if (!analysis.constituents.hooks.some(
1035
+ (hook) => hook.name === hookId && hook.parentKey === parentKey
1036
+ )) {
1037
+ analysis.constituents.hooks.push({
1038
+ name: hookId,
1039
+ filePath: hookFilePath,
1040
+ discoveredVia: "static",
1041
+ sharedWith: [],
1042
+ parentKey
1043
+ });
1044
+ }
1045
+ }
900
1046
  /**
901
1047
  * Analyze a model and its fallbacks.
902
1048
  */
@@ -1031,11 +1177,17 @@ var PackingService = class {
1031
1177
  } = options;
1032
1178
  const finalPackageName = packageName || packageId;
1033
1179
  const packedAt = Date.now();
1180
+ const entryAgentFile = await this.findFile(
1181
+ path3.join(rootDir, "agents", "agents"),
1182
+ agentName
1183
+ );
1184
+ const entryParentHooks = entryAgentFile ? (await extractAgentHooks(fs3.readFileSync(entryAgentFile, "utf-8"))).parentHookRequirements : [];
1034
1185
  const meta = {
1035
1186
  packageId,
1036
1187
  version,
1037
1188
  entryAgents: [agentName],
1038
- packedAt
1189
+ packedAt,
1190
+ ...entryParentHooks.length > 0 ? { parentHooks: { [agentName]: entryParentHooks } } : {}
1039
1191
  };
1040
1192
  const result = {
1041
1193
  success: false,
@@ -1144,6 +1296,7 @@ var PackingService = class {
1144
1296
  agentName,
1145
1297
  this.deduplicateConstituents(analysis).effects.map((effect) => effect.name),
1146
1298
  this.deduplicateConstituents(analysis).threadEndpoints.map((endpoint) => endpoint.name),
1299
+ meta.parentHooks,
1147
1300
  externalDeps,
1148
1301
  rootDir,
1149
1302
  license,
@@ -1535,7 +1688,7 @@ var PackingService = class {
1535
1688
  /**
1536
1689
  * Generate the package.json file with dependencies.
1537
1690
  */
1538
- generatePackageJson(packageName, version, agentName, effects, threadEndpoints, externalDeps, rootDir, license, licenseOwner) {
1691
+ generatePackageJson(packageName, version, agentName, effects, threadEndpoints, parentHooks, externalDeps, rootDir, license, licenseOwner) {
1539
1692
  const dependencies = {
1540
1693
  "@standardagents/spec": this.resolvePackageVersion("@standardagents/spec", rootDir)
1541
1694
  };
@@ -1557,6 +1710,7 @@ var PackingService = class {
1557
1710
  keywords: ["standardagent"],
1558
1711
  standardagent: {
1559
1712
  entryAgents: [agentName],
1713
+ ...parentHooks ? { parentHooks } : {},
1560
1714
  ...effects.length > 0 ? { effects } : {},
1561
1715
  ...threadEndpoints.length > 0 ? { threadEndpoints } : {}
1562
1716
  },
@@ -1850,6 +2004,22 @@ ${license || "See LICENSE file"}
1850
2004
  return agents;
1851
2005
  }
1852
2006
  };
2007
+ function validParentHooks(value) {
2008
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
2009
+ return Object.values(value).every((requirements) => {
2010
+ if (!Array.isArray(requirements)) return false;
2011
+ const seen = /* @__PURE__ */ new Set();
2012
+ return requirements.every((requirement) => {
2013
+ if (typeof requirement !== "object" || requirement === null) return false;
2014
+ const item = requirement;
2015
+ if (typeof item.hook !== "string" || !item.hook.trim() || typeof item.reason !== "string" || !item.reason.trim() || item.stage !== void 0 && item.stage !== "before_parent" && item.stage !== "after_parent" || seen.has(item.hook)) {
2016
+ return false;
2017
+ }
2018
+ seen.add(item.hook);
2019
+ return true;
2020
+ });
2021
+ });
2022
+ }
1853
2023
  var PackageDiscoveryService = class {
1854
2024
  config;
1855
2025
  constructor(config) {
@@ -1945,6 +2115,7 @@ var PackageDiscoveryService = class {
1945
2115
  }
1946
2116
  const effects = Array.isArray(pkgJson.standardagent.effects) && pkgJson.standardagent.effects.every((effectName) => typeof effectName === "string") ? pkgJson.standardagent.effects : void 0;
1947
2117
  const threadEndpoints = Array.isArray(pkgJson.standardagent.threadEndpoints) && pkgJson.standardagent.threadEndpoints.every((endpoint) => typeof endpoint === "string") ? pkgJson.standardagent.threadEndpoints : void 0;
2118
+ const parentHooks = validParentHooks(pkgJson.standardagent.parentHooks) ? pkgJson.standardagent.parentHooks : void 0;
1948
2119
  return {
1949
2120
  packageId: pkgJson.name || pkgName,
1950
2121
  version: pkgJson.version || "0.0.0",
@@ -1953,6 +2124,7 @@ var PackageDiscoveryService = class {
1953
2124
  entryAgents: pkgJson.standardagent.entryAgents,
1954
2125
  ...effects ? { effects } : {},
1955
2126
  ...threadEndpoints ? { threadEndpoints } : {},
2127
+ ...parentHooks ? { parentHooks } : {},
1956
2128
  description: pkgJson.description
1957
2129
  };
1958
2130
  } catch (error) {
@@ -2014,6 +2186,7 @@ var PackageDiscoveryService = class {
2014
2186
  }
2015
2187
  const effects = Array.isArray(pkgJson.standardagent.effects) && pkgJson.standardagent.effects.every((effectName) => typeof effectName === "string") ? pkgJson.standardagent.effects : void 0;
2016
2188
  const threadEndpoints = Array.isArray(pkgJson.standardagent.threadEndpoints) && pkgJson.standardagent.threadEndpoints.every((endpoint) => typeof endpoint === "string") ? pkgJson.standardagent.threadEndpoints : void 0;
2189
+ const parentHooks = validParentHooks(pkgJson.standardagent.parentHooks) ? pkgJson.standardagent.parentHooks : void 0;
2017
2190
  return {
2018
2191
  packageId: pkgJson.name || dirName,
2019
2192
  version: pkgJson.version || "0.0.0",
@@ -2022,6 +2195,7 @@ var PackageDiscoveryService = class {
2022
2195
  entryAgents: pkgJson.standardagent.entryAgents,
2023
2196
  ...effects ? { effects } : {},
2024
2197
  ...threadEndpoints ? { threadEndpoints } : {},
2198
+ ...parentHooks ? { parentHooks } : {},
2025
2199
  description: pkgJson.description
2026
2200
  };
2027
2201
  } catch (error) {
@@ -2050,7 +2224,8 @@ var PackageDiscoveryService = class {
2050
2224
  const hasValidEntryAgents = Array.isArray(f.entryAgents) && f.entryAgents.length > 0 && f.entryAgents.every((e) => typeof e === "string");
2051
2225
  const hasValidEffects = f.effects === void 0 || Array.isArray(f.effects) && f.effects.every((effectName) => typeof effectName === "string");
2052
2226
  const hasValidThreadEndpoints = f.threadEndpoints === void 0 || Array.isArray(f.threadEndpoints) && f.threadEndpoints.every((endpoint) => typeof endpoint === "string");
2053
- return hasValidEntryAgents && hasValidEffects && hasValidThreadEndpoints;
2227
+ const hasValidParentHooks = f.parentHooks === void 0 || validParentHooks(f.parentHooks);
2228
+ return hasValidEntryAgents && hasValidEffects && hasValidThreadEndpoints && hasValidParentHooks;
2054
2229
  }
2055
2230
  /**
2056
2231
  * Get a package by ID.