@faapi/faapi 6.4.1 → 6.5.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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { A as AppRegistries, R as RouteManifest, F as FaapiContext, C as CorsOptions, T as TaskClient, H as HelmetOptions, L as LoggerOptions, a as FaapiMiddleware, I as InjectorMap, b as TaskFailedHandler, c as TaskQueueDeps, d as TaskQueue, e as TaskDriver, f as TaskRegistry, g as TaskManifest, h as ToolMetadata, i as AgentCore, j as AgentMetadata, W as WsRouteManifest } from './routeTypes-_17rXzal.js';
2
- export { k as AgentHandleFactory, l as AgentHandleStore, m as AgentPathMeta, n as AgentRegistry, o as AgentToolDescriptor, p as FaapiContextConfig, q as FaapiTaskMeta, r as FailOptions, s as Injector, t as RouteInfo, u as RouteInputSchema, v as RouteOutputSchema, w as RouteParamSchema, S as SkillRegistry, x as SseEvent, y as SseWriter, z as TaskContext, B as TaskDriverJob, D as TaskDriverProcess, E as TaskDriverRecord, G as TaskFailedInfo, J as TaskJob, K as TaskJobStatus, M as TaskMetadata, N as TaskModule, O as ToolCore, P as ToolPathMeta, Q as ToolRegistry, U as cors, V as createAppRegistries, X as createTaskRegistry, Y as helmet, Z as logger } from './routeTypes-_17rXzal.js';
1
+ import { A as AppRegistries, R as RouteManifest, F as FaapiContext, C as CorsOptions, T as TaskClient, H as HelmetOptions, L as LoggerOptions, a as FaapiMiddleware, I as InjectorMap, b as TaskFailedHandler, c as TaskQueueDeps, d as TaskQueue, e as TaskDriver, f as TaskRegistry, g as TaskManifest, h as ToolMetadata, i as AgentCore, j as AgentMetadata, W as WsRouteManifest } from './routeTypes-q9OXB--o.js';
2
+ export { k as AgentHandleFactory, l as AgentHandleStore, m as AgentPathMeta, n as AgentRegistry, o as AgentToolDescriptor, p as FaapiContextConfig, q as FaapiTaskMeta, r as FailOptions, s as Injector, t as RouteInfo, u as RouteInputSchema, v as RouteOutputSchema, w as RouteParamSchema, S as SkillRegistry, x as SseEvent, y as SseWriter, z as TaskContext, B as TaskDriverJob, D as TaskDriverProcess, E as TaskDriverRecord, G as TaskFailedInfo, J as TaskJob, K as TaskJobStatus, M as TaskMetadata, N as TaskModule, O as TaskRegistriesSnapshot, P as TaskRegistriesView, Q as ToolCore, U as ToolPathMeta, V as ToolRegistry, X as cors, Y as createAppRegistries, Z as createTaskRegistriesView, _ as createTaskRegistry, $ as helmet, a0 as logger } from './routeTypes-q9OXB--o.js';
3
3
  import * as node_http from 'node:http';
4
4
  import { Server, IncomingMessage, ServerResponse } from 'node:http';
5
5
  import { Socket } from 'node:net';
package/dist/index.js CHANGED
@@ -1869,6 +1869,40 @@ function createTaskHandleStore() {
1869
1869
  }
1870
1870
  };
1871
1871
  }
1872
+ function createTaskRegistriesView(registries) {
1873
+ return {
1874
+ agent: {
1875
+ getAgent: (name) => registries.agent.getAgent(name),
1876
+ getAgentEntry: (name) => registries.agent.getAgentEntry(name),
1877
+ listAgents: () => registries.agent.listAgents(),
1878
+ asTool: (name) => registries.agent.asTool(name),
1879
+ resolveAgentTools: (name) => registries.agent.resolveAgentTools(name),
1880
+ resolveSubAgents: (name) => registries.agent.resolveSubAgents(name)
1881
+ },
1882
+ tool: {
1883
+ get: (name) => registries.tool.get(name),
1884
+ list: () => registries.tool.list()
1885
+ },
1886
+ skill: {
1887
+ get: (name) => registries.skill.get(name),
1888
+ list: () => registries.skill.list()
1889
+ }
1890
+ };
1891
+ }
1892
+ function createEmptyTaskRegistriesView() {
1893
+ return {
1894
+ agent: {
1895
+ getAgent: () => void 0,
1896
+ getAgentEntry: () => void 0,
1897
+ listAgents: () => [],
1898
+ asTool: () => void 0,
1899
+ resolveAgentTools: () => [],
1900
+ resolveSubAgents: () => []
1901
+ },
1902
+ tool: { get: () => void 0, list: () => [] },
1903
+ skill: { get: () => void 0, list: () => [] }
1904
+ };
1905
+ }
1872
1906
  function createAppRegistries() {
1873
1907
  const tool = createToolRegistry();
1874
1908
  const agent = createAgentRegistry(tool);
@@ -1964,11 +1998,68 @@ function safeConfig(config) {
1964
1998
  return void 0;
1965
1999
  }
1966
2000
  }
2001
+ var BUILD_VIEW_SOURCE = `
2002
+ function buildRegistriesView(snapshot) {
2003
+ var agents = new Map(((snapshot && snapshot.agents) || []).map(function (a) { return [a.name, a]; }));
2004
+ var tools = new Map(((snapshot && snapshot.tools) || []).map(function (t) { return [t.name, t]; }));
2005
+ var skills = new Map(((snapshot && snapshot.skills) || []).map(function (s) { return [s.name, s]; }));
2006
+ return {
2007
+ agent: {
2008
+ getAgent: function (name) { return agents.get(name); },
2009
+ getAgentEntry: function (name) { return agents.get(name); },
2010
+ listAgents: function () { return Array.from(agents.values()); },
2011
+ asTool: function (name) {
2012
+ var agent = agents.get(name);
2013
+ if (!agent) return undefined;
2014
+ return {
2015
+ kind: 'agent',
2016
+ name: 'agent.' + agent.name,
2017
+ agentName: agent.name,
2018
+ description: agent.description,
2019
+ metadata: agent,
2020
+ };
2021
+ },
2022
+ resolveAgentTools: function (name) {
2023
+ var agent = agents.get(name);
2024
+ var result = new Map();
2025
+ if (agent && agent.tools) {
2026
+ agent.tools.forEach(function (toolName) {
2027
+ var resolved = tools.get(toolName);
2028
+ if (resolved) result.set(resolved.name, resolved);
2029
+ });
2030
+ }
2031
+ return Array.from(result.values());
2032
+ },
2033
+ resolveSubAgents: function (name) {
2034
+ var agent = agents.get(name);
2035
+ var result = [];
2036
+ if (agent && agent.agents) {
2037
+ agent.agents.forEach(function (subName) {
2038
+ var sub = agents.get(subName);
2039
+ if (sub) result.push(sub);
2040
+ });
2041
+ }
2042
+ return result;
2043
+ },
2044
+ },
2045
+ tool: {
2046
+ get: function (name) { return tools.get(name); },
2047
+ list: function () { return Array.from(tools.values()); },
2048
+ },
2049
+ skill: {
2050
+ get: function (name) { return skills.get(name); },
2051
+ list: function () { return Array.from(skills.values()); },
2052
+ },
2053
+ };
2054
+ }
2055
+ `;
1967
2056
  function buildWrapperSource(moduleUrl) {
1968
2057
  return `
1969
2058
  import { parentPort } from 'node:worker_threads';
1970
2059
  import * as mod from '${moduleUrl}';
1971
2060
 
2061
+ ${BUILD_VIEW_SOURCE}
2062
+
1972
2063
  const run = mod.run;
1973
2064
  if (typeof run !== 'function') {
1974
2065
  parentPort.postMessage({ type: 'error', message: 'Task module has no run export' });
@@ -1983,7 +2074,8 @@ if (typeof run !== 'function') {
1983
2074
  controller = new AbortController();
1984
2075
  const { payload, taskCtx } = msg;
1985
2076
  try {
1986
- const result = await run(payload, { ...taskCtx, signal: controller.signal });
2077
+ const registries = buildRegistriesView(msg.registries);
2078
+ const result = await run(payload, { ...taskCtx, signal: controller.signal, registries });
1987
2079
  parentPort.postMessage({ type: 'done', result });
1988
2080
  } catch (err) {
1989
2081
  parentPort.postMessage({
@@ -2081,7 +2173,8 @@ async function runTaskInWorker(options) {
2081
2173
  worker.postMessage({
2082
2174
  type: "run",
2083
2175
  payload,
2084
- taskCtx: { config: safeConfig(taskCtx.config), job: taskCtx.job }
2176
+ taskCtx: { config: safeConfig(taskCtx.config), job: taskCtx.job },
2177
+ registries: options.registries
2085
2178
  });
2086
2179
  } catch (err) {
2087
2180
  finish(
@@ -2096,6 +2189,7 @@ async function runTaskInWorker(options) {
2096
2189
  // src/task/taskQueue.ts
2097
2190
  function createTaskQueue(deps) {
2098
2191
  const { registry, rootDir, driver } = deps;
2192
+ const registriesView = deps.registries ?? createEmptyTaskRegistriesView();
2099
2193
  const records = /* @__PURE__ */ new Map();
2100
2194
  const moduleCache2 = /* @__PURE__ */ new Map();
2101
2195
  const schemaCache = /* @__PURE__ */ new Map();
@@ -2119,6 +2213,13 @@ function createTaskQueue(deps) {
2119
2213
  throw new Error(`[faapi] Unknown task "${name}". Registered tasks: ${known}`);
2120
2214
  }
2121
2215
  }
2216
+ function snapshotRegistries() {
2217
+ return {
2218
+ agents: registriesView.agent.listAgents().map((core) => registriesView.agent.getAgentEntry(core.name)).filter((entry) => entry !== void 0),
2219
+ tools: registriesView.tool.list(),
2220
+ skills: registriesView.skill.list()
2221
+ };
2222
+ }
2122
2223
  async function validatePayload(name, payload) {
2123
2224
  if (!schemaCache.has(name)) {
2124
2225
  const meta = registry.get(name);
@@ -2165,6 +2266,7 @@ function createTaskQueue(deps) {
2165
2266
  config: deps.config,
2166
2267
  job: { id: job.id, name: job.name, attempt: job.attempt }
2167
2268
  },
2269
+ registries: snapshotRegistries(),
2168
2270
  timeoutMs: meta.timeoutMs,
2169
2271
  externalSignal: job.signal
2170
2272
  });
@@ -2180,7 +2282,8 @@ function createTaskQueue(deps) {
2180
2282
  const taskCtx = {
2181
2283
  signal: job.signal,
2182
2284
  config: deps.config,
2183
- job: { id: job.id, name: job.name, attempt: job.attempt }
2285
+ job: { id: job.id, name: job.name, attempt: job.attempt },
2286
+ registries: registriesView
2184
2287
  };
2185
2288
  result = await mod.run(job.payload, taskCtx);
2186
2289
  }
@@ -6495,6 +6598,7 @@ async function createAppBase(options) {
6495
6598
  registry: registries.task,
6496
6599
  rootDir,
6497
6600
  config,
6601
+ registries: createTaskRegistriesView(registries),
6498
6602
  driver: taskDriver,
6499
6603
  onFailed: config?.task?.onFailed
6500
6604
  });
@@ -7179,6 +7283,7 @@ export {
7179
7283
  createProgram,
7180
7284
  createPrograms,
7181
7285
  createTaskQueue,
7286
+ createTaskRegistriesView,
7182
7287
  createTaskRegistry,
7183
7288
  extractTypeInfo,
7184
7289
  getAgent,