@standardagents/builder 0.29.2 → 0.30.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/dist/plugin.d.ts CHANGED
@@ -5,6 +5,7 @@ interface AgentPluginOptions {
5
5
  toolsDir?: string;
6
6
  hooksDir?: string;
7
7
  apiDir?: string;
8
+ usersDir?: string;
8
9
  modelsDir?: string;
9
10
  providersDir?: string;
10
11
  promptsDir?: string;
package/dist/plugin.js CHANGED
@@ -1186,8 +1186,9 @@ function createHmrReloader() {
1186
1186
  const isPromptFile = file.startsWith(dirs.promptsDir) && file.endsWith(".ts");
1187
1187
  const isAgentFile = file.startsWith(dirs.agentsDir) && file.endsWith(".ts");
1188
1188
  const isEffectFile = file.startsWith(dirs.effectsDir) && file.endsWith(".ts");
1189
+ const isUserEndpointFile = file.startsWith(dirs.usersDir) && file.endsWith(".ts");
1189
1190
  const isConfigFile = isModelFile || isProviderFile || isPromptFile || isAgentFile || isEffectFile;
1190
- if (!isToolFile && !isThreadApiFile && !isHookFile && !isConfigFile) return;
1191
+ if (!isToolFile && !isThreadApiFile && !isHookFile && !isConfigFile && !isUserEndpointFile) return;
1191
1192
  reloader.invalidateSourceFileModule(server, file);
1192
1193
  if (isConfigFile || isToolFile) regenerateTypes();
1193
1194
  if (isToolFile) await reloader.reloadToolsModule(server);
@@ -3213,6 +3214,35 @@ function parseRequestBody(req) {
3213
3214
  req.on("error", reject);
3214
3215
  });
3215
3216
  }
3217
+ function scanUsersDirectory(dir) {
3218
+ const results = [];
3219
+ if (!fs8__default.existsSync(dir)) return results;
3220
+ const walk = (current, prefix) => {
3221
+ let entries;
3222
+ try {
3223
+ entries = fs8__default.readdirSync(current, { withFileTypes: true });
3224
+ } catch (error) {
3225
+ console.error(`Error scanning users directory ${current}:`, error);
3226
+ return;
3227
+ }
3228
+ for (const entry of entries) {
3229
+ const fullPath = path8__default.join(current, entry.name);
3230
+ if (entry.isDirectory()) {
3231
+ walk(fullPath, prefix ? `${prefix}/${entry.name}` : entry.name);
3232
+ continue;
3233
+ }
3234
+ if (!entry.name.endsWith(".ts") || entry.name.endsWith(".d.ts")) continue;
3235
+ const base = entry.name.slice(0, -3);
3236
+ const key = prefix ? `${prefix}/${base}` : base;
3237
+ results.push({
3238
+ key,
3239
+ importPath: "./" + path8__default.relative(process.cwd(), fullPath).replace(/\\/g, "/")
3240
+ });
3241
+ }
3242
+ };
3243
+ walk(dir, "");
3244
+ return results;
3245
+ }
3216
3246
 
3217
3247
  // src/plugin/agent-api-middleware.ts
3218
3248
  async function handleAgentApiRequest(context) {
@@ -6806,9 +6836,10 @@ function createDevMiddleware(server, context) {
6806
6836
  });
6807
6837
  }
6808
6838
  async function loadBuilderVirtualModule(context) {
6809
- const { toolsDir, hooksDir, modelsDir, promptsDir, agentsDir, effectsDir, hmr } = context;
6839
+ const { toolsDir, hooksDir, modelsDir, promptsDir, agentsDir, effectsDir, usersDir, hmr } = context;
6810
6840
  const tools = await scanToolsDirectory(toolsDir);
6811
6841
  const hooks = await scanHooksDirectory(hooksDir);
6842
+ const userEndpoints = scanUsersDirectory(usersDir);
6812
6843
  const models = await scanModelsDirectory(modelsDir);
6813
6844
  const prompts = await scanPromptsDirectory(promptsDir);
6814
6845
  const agents = await scanAgentsDirectory(agentsDir);
@@ -6910,6 +6941,17 @@ async function loadBuilderVirtualModule(context) {
6910
6941
  },`;
6911
6942
  }
6912
6943
  }).join("\n");
6944
+ const userEndpointsCode = userEndpoints.map(({ key, importPath }) => {
6945
+ const absPath = toAbsolutePath(importPath);
6946
+ return ` "${key}": async () => {
6947
+ try {
6948
+ return (await import("${absPath}")).default;
6949
+ } catch (error) {
6950
+ console.error('Failed to import user endpoint ${key}:', error);
6951
+ throw error;
6952
+ }
6953
+ },`;
6954
+ }).join("\n");
6913
6955
  return `// Consolidated virtual module: virtual:@standardagents/builder /* v${hmr.versions.builder} */
6914
6956
  // Provides DurableThread, DurableAgentBuilder, ThreadWatchdog, and router
6915
6957
  import { DurableThread as _BaseDurableThread } from '@standardagents/builder/runtime';
@@ -6955,6 +6997,10 @@ const _effects = {
6955
6997
  ${effectsCode}
6956
6998
  };
6957
6999
 
7000
+ const _userEndpoints = {
7001
+ ${userEndpointsCode}
7002
+ };
7003
+
6958
7004
  /**
6959
7005
  * DurableThread with all virtual module methods already implemented.
6960
7006
  * Exported by the generated AgentBuilder Worker entry; user projects do not
@@ -7044,10 +7090,21 @@ export class CodeExecutionBridge extends _BaseCodeExecutionBridge {}
7044
7090
  export class ThreadWatchdog extends _BaseThreadWatchdog {}
7045
7091
 
7046
7092
  /**
7047
- * Per-user hub companion. Coordination only (persistent daemon socket, wake
7048
- * signal, sharded account KV); needs no virtual-module registries.
7093
+ * Per-user hub companion: persistent daemon socket, wake signal, sharded
7094
+ * account KV \u2014 and the USER SCOPE (spec: Users): packaged user endpoints from
7095
+ * the users/ directory executed under per-user serialization, the user event
7096
+ * stream, and user lifecycle hooks (filtered from the shared hooks registry
7097
+ * by hook type at dispatch).
7049
7098
  */
7050
- export class DurableUserHub extends _BaseDurableUserHub {}
7099
+ export class DurableUserHub extends _BaseDurableUserHub {
7100
+ userEndpoints() {
7101
+ return _userEndpoints;
7102
+ }
7103
+
7104
+ userHooks() {
7105
+ return _hooks;
7106
+ }
7107
+ }
7051
7108
  `;
7052
7109
  }
7053
7110
  async function loadRegistryVirtualModule(context) {
@@ -8103,6 +8160,7 @@ function agentbuilder(options = {}) {
8103
8160
  const promptsDir = options.promptsDir ? path8__default.resolve(process.cwd(), options.promptsDir) : path8__default.resolve(process.cwd(), "agents/prompts");
8104
8161
  const agentsDir = options.agentsDir ? path8__default.resolve(process.cwd(), options.agentsDir) : path8__default.resolve(process.cwd(), "agents/agents");
8105
8162
  const effectsDir = options.effectsDir ? path8__default.resolve(process.cwd(), options.effectsDir) : path8__default.resolve(process.cwd(), "agents/effects");
8163
+ const usersDir = options.usersDir ? path8__default.resolve(process.cwd(), options.usersDir) : path8__default.resolve(process.cwd(), "agents/users");
8106
8164
  const outputDir = path8__default.resolve(process.cwd(), ".agents");
8107
8165
  const generatedWorkerEntry = path8__default.join(outputDir, "worker.ts");
8108
8166
  const isProviderPackageInstalled = (packageName) => {
@@ -8165,6 +8223,7 @@ export { CodeExecutionBridge, DurableAgentBuilder, DurableThread, ThreadWatchdog
8165
8223
  toolsDir,
8166
8224
  hooksDir,
8167
8225
  threadApiDir,
8226
+ usersDir,
8168
8227
  modelsDir,
8169
8228
  providersDir,
8170
8229
  promptsDir,
@@ -8175,6 +8234,7 @@ export { CodeExecutionBridge, DurableAgentBuilder, DurableThread, ThreadWatchdog
8175
8234
  toolsDir,
8176
8235
  hooksDir,
8177
8236
  threadApiDir,
8237
+ usersDir,
8178
8238
  modelsDir,
8179
8239
  providersDir,
8180
8240
  promptsDir,
@@ -8262,6 +8322,7 @@ export { CodeExecutionBridge, DurableAgentBuilder, DurableThread, ThreadWatchdog
8262
8322
  this.addWatchFile(promptsDir);
8263
8323
  this.addWatchFile(agentsDir);
8264
8324
  this.addWatchFile(effectsDir);
8325
+ this.addWatchFile(usersDir);
8265
8326
  },
8266
8327
  configureServer(server) {
8267
8328
  createDevMiddleware(server, devMiddlewareContext);