MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / createExecutor

Function createExecutor

packages/core/sdk/src/executor.ts:1895–7324  ·  view source on GitHub ↗
(
  config: ExecutorConfig<TPlugins>,
)

Source from the content-addressed store, hash-verified

1893};
1894
1895export const createExecutor = <const TPlugins extends readonly AnyPlugin[] = readonly []>(
1896 config: ExecutorConfig<TPlugins>,
1897): Effect.Effect<Executor<TPlugins>, StorageFailure> =>
1898 Effect.gen(function* () {
1899 const defaultPlugins = (): TPlugins => {
1900 const empty: readonly AnyPlugin[] = [];
1901 return empty as TPlugins;
1902 };
1903 const { plugins: userPlugins = defaultPlugins() } = config;
1904
1905 const tenant = String(config.tenant);
1906 const subject = config.subject != null ? String(config.subject) : null;
1907
1908 const ownerBinding: OwnerBinding = {
1909 tenant: config.tenant,
1910 subject: config.subject ?? null,
1911 };
1912
1913 const ownedKeys = (owner: Owner): OwnedKeys => {
1914 if (owner === "org") return { tenant, owner, subject: ORG_SUBJECT };
1915 if (subject == null) {
1916 // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: programmer error caught and surfaced as StorageError below by callers
1917 throw new StorageError({
1918 message: `Cannot target owner "user": executor has no subject.`,
1919 cause: undefined,
1920 });
1921 }
1922 return { tenant, owner, subject };
1923 };
1924
1925 const requireUserSubject = (owner: Owner): Effect.Effect<void, StorageFailure> =>
1926 owner === "user" && subject == null
1927 ? Effect.fail(
1928 new StorageError({
1929 message: `Cannot target owner "user": executor has no subject.`,
1930 cause: undefined,
1931 }),
1932 )
1933 : Effect.void;
1934
1935 // Workspace-settings gate (`ExecutorConfig.orgWrites`). Called at the top
1936 // of every user-intent workspace-level mutation: with an explicit owner it
1937 // refuses only `"org"` targets; with no owner it guards a tenant-shared
1938 // surface outright. Deliberately NOT wired into the storage owner policy —
1939 // operational org-row writes (token refresh, tool-catalog re-sync) must
1940 // keep working for a denied member.
1941 const guardOrgWrite = (owner?: Owner): Effect.Effect<void, OrgWriteDeniedError> =>
1942 Effect.gen(function* () {
1943 const access =
1944 config.orgWrites === "request" ? yield* currentOrgWriteAccess : config.orgWrites;
1945 if (access === "denied" && (owner === undefined || owner === "org")) {
1946 return yield* new OrgWriteDeniedError();
1947 }
1948 });
1949
1950 // Built-in core-tools plugin: agent-facing static tools over the v2 surface.
1951 const plugins: readonly AnyPlugin[] = config.coreTools
1952 ? ([

Callers 15

setupFunction · 0.90
executorWithConnectionFunction · 0.90
makePlatformExecutorFunction · 0.90
failInvokingFunction · 0.90
recordToolRowLaunchFunction · 0.90
recordCredentialLaunchFunction · 0.90
executor.test.tsFile · 0.90
makeTestWorkspaceHarnessFunction · 0.90
makeHealthHarnessFunction · 0.90

Calls 15

withQueryContextFunction · 0.90
makeFumaClientFunction · 0.90
makeFumaBlobStoreFunction · 0.90
makeShapeMemoryFunction · 0.90
makeOAuthServiceFunction · 0.90
makePendingApprovalStoreFunction · 0.90
pluginBlobStoreFunction · 0.90
afterCommitFunction · 0.90
defaultPluginsFunction · 0.85
collectTablesFunction · 0.85

Tested by 15

setupFunction · 0.72
executorWithConnectionFunction · 0.72
makePlatformExecutorFunction · 0.72
failInvokingFunction · 0.72
recordToolRowLaunchFunction · 0.72
recordCredentialLaunchFunction · 0.72
makeHealthHarnessFunction · 0.72
setupFunction · 0.72
platformExecutorForFunction · 0.72
productExecutorForFunction · 0.72
makeExecutorFunction · 0.72
makeExecutorWithFunction · 0.72